/** * Index one document (in XML format), see {@link #convertSolrDocInXML(SolrInputDocument)}. * * @param docXML a textual representation of the document in XML format. * @throws Exception */ public void indexDocument(String docXML) throws Exception { String xml = "<add>" + docXML + "</add>"; DirectXmlRequest xmlreq = new DirectXmlRequest("/update", xml); mServer.request(xmlreq); }
/**Indexing API for document in xml format**/ public void indexDocument(String docXML) throws Exception { String xml = "<add>" + docXML + "</add>"; DirectXmlRequest xmlreq = new DirectXmlRequest("/update", xml); server.request(xmlreq); }
/** * Submits a batch of update instructions in XML format. * * @param docXML input XML that represents one or more update instruction. * @throws Exception */ public void submitXML(String docXML) throws Exception { DirectXmlRequest xmlreq = new DirectXmlRequest("/update", docXML); mServer.request(xmlreq); }
@Override public UpdateResponse process(SolrServer server) throws SolrServerException, IOException { long startTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS); UpdateResponse res = new UpdateResponse(); res.setResponse(server.request(this)); long endTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS); res.setElapsedTime(endTime - startTime); return res; }
/** * {@inheritDoc} */ @Override public DocumentAnalysisResponse process(SolrServer server) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); DocumentAnalysisResponse res = new DocumentAnalysisResponse(); res.setResponse(server.request(this)); res.setElapsedTime(System.currentTimeMillis() - startTime); return res; }
@Override public void run() { if (oldLastCommit == lastCommit) { lastCommit = System.currentTimeMillis(); UpdateRequest req = new UpdateRequest(); req.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false); try { solrServer.request(req); } catch (Exception e) { logger.error("Failed to commit", e); } } } }, current + 100);
public static NamedList<Object> getAllFacetFields(SolrServer solrServer) throws SolrServerException, IOException { LukeRequest qr = new LukeRequest(); NamedList<Object> qresp = solrServer.request(qr); Object fields = qresp.get("fields"); if (fields instanceof NamedList<?>) { @SuppressWarnings("unchecked") NamedList<Object> fieldsList = (NamedList<Object>) fields; return fieldsList; } else { throw new IllegalStateException( "Fields container is not a NamedList, so there is no facet information available"); } }
@Deprecated public static NamedList<Object> getAllFacetFields(SolrServer solrServer) throws SolrServerException, IOException { LukeRequest qr = new LukeRequest(); NamedList<Object> qresp = solrServer.request(qr); Object fields = qresp.get("fields"); if (fields instanceof NamedList<?>) { @SuppressWarnings("unchecked") NamedList<Object> fieldsList = (NamedList<Object>) fields; return fieldsList; } else { throw new IllegalStateException( "Fields container is not a NamedList, so there is no facet information available"); } }
@Override public UpdateResponse process( SolrServer server ) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); UpdateResponse res = new UpdateResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; }
@Override public LukeResponse process( SolrServer server ) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); LukeResponse res = new LukeResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; } }
@Override public CoreAdminResponse process(SolrServer server) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); CoreAdminResponse res = new CoreAdminResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; }
@Override public SolrPingResponse process( SolrServer server ) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); SolrPingResponse res = new SolrPingResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; } }
@Override public UpdateResponse process( SolrServer server ) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); UpdateResponse res = new UpdateResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; } }
/** * {@inheritDoc} */ @Override public FieldAnalysisResponse process(SolrServer server) throws SolrServerException, IOException { if (fieldTypes == null || fieldNames == null) { throw new IllegalStateException("A list one field type or field name need to be specified"); } if (fieldValue == null) { throw new IllegalStateException("The field value must be set"); } long startTime = System.currentTimeMillis(); FieldAnalysisResponse res = new FieldAnalysisResponse(); res.setResponse(server.request(this)); res.setElapsedTime(System.currentTimeMillis() - startTime); return res; }
@Override public SolrResponse process(SolrServer server) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); SolrPingResponse res = new SolrPingResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; }
@Override public QueryResponse process( SolrServer server ) throws SolrServerException { try { long startTime = System.currentTimeMillis(); QueryResponse res = new QueryResponse( server.request( this ), server ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; } catch (SolrServerException e){ throw e; } catch (Exception e) { throw new SolrServerException("Error executing query", e); } } }
@Override public SolrResponse dataImport(final String command) { return solrTemplate.execute(new SolrCallback<SolrResponse>() { @Override public SolrResponse doInSolr(SolrServer solrServer) throws SolrServerException, IOException { return new SolrRequest(METHOD.GET, "/dataimport?command=" + command) { //..skipped some methods to shorten @Override public SolrResponse process(SolrServer server) throws SolrServerException, IOException { SolrResponseBase response = new SolrResponseBase(); response.setResponse(server.request(this)); return response; } }.process(solrServer); } }); }
SolrServer server = new CommonsHttpSolrServer("http://localhost:8983/solr"); ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract"); req.addFile(new File("myxml.xml")); req.setParam(ExtractingParams.EXTRACT_ONLY, "true"); NamedList<Object> result = server.request(req); System.out.println("Result: " + result);
/**Indexing API for document do be indexed in HashMap format**/ public void indexDocument(HashMap<String,Object>indexMap) throws Exception { SolrInputDocument solrDoc=this.buildSolrDocument(indexMap); String docXML=this.convertSolrDocInXML(solrDoc); String xml = "<add>" + docXML + "</add>"; DirectXmlRequest xmlreq = new DirectXmlRequest("/update", xml); server.request(xmlreq); }
/** * Index one document using a key-value map representation. * * @param keyValueMap key-value map (field name, field text). * @throws Exception */ public void indexDocument(HashMap<String,Object> keyValueMap) throws Exception { SolrInputDocument solrDoc = SolrUtils.buildSolrDocument(keyValueMap); String docXML=this.convertSolrDocInXML(solrDoc); String xml = "<add>" + docXML + "</add>"; DirectXmlRequest xmlreq = new DirectXmlRequest("/update", xml); mServer.request(xmlreq); }