List of usage examples for org.apache.solr.client.solrj.impl NoOpResponseParser NoOpResponseParser
public NoOpResponseParser(String writerType)
From source file:com.github.fengtan.sophie.tables.DocumentsTable.java
License:Open Source License
/** * Export documents into CSV file./*from ww w .j a v a2 s. c om*/ * * @throws SophieException * If the documents could not be exported into a CSV file. */ public void export() throws SophieException { // Open dialog to let the user select where the file will be dumped. FileDialog dialog = new FileDialog(table.getShell(), SWT.SAVE); dialog.setFilterNames(new String[] { "CSV Files (*.csv)", "All Files (*.*)" }); dialog.setFilterExtensions(new String[] { "*.csv", "*.*" }); String date = new SimpleDateFormat("yyyy-MM-dd-HH:mm").format(new Date()); dialog.setFileName("documents_" + date + ".csv"); String path = dialog.open(); // User did not selected any location. if (path == null) { return; } // Send Solr query and write result into file. SolrQuery query = getBaseQuery(0, table.getItemCount()); QueryRequest request = new QueryRequest(query); request.setResponseParser(new NoOpResponseParser("csv")); NamedList<Object> response; try { response = Sophie.client.request(request); } catch (SolrServerException | IOException | SolrException e) { throw new SophieException("Unable to get CSV documents from Solr", e); } String csv = (String) response.get("response"); try { Writer writer = new PrintWriter(path, "UTF-8"); writer.write(csv); writer.close(); } catch (IOException e) { throw new SophieException("Unable to write into file " + path, e); } }