List of usage examples for org.apache.solr.client.solrj.request UpdateRequest UpdateRequest
public UpdateRequest()
From source file:at.newmedialab.lmf.search.services.indexing.SolrCoreRuntime.java
License:Apache License
/** * Queue the input document in the document queue of this SolrCoreRuntime and check whether it is * necessary to commit./* www .ja v a 2 s .c om*/ * * @param doc the document to be added to the Solr Core */ public void queueInputDocument(SolrInputDocument doc) { if (doc != null) { serverLock.lock(); try { final Object fv = doc.getFieldValue("id"); if (fv != null) { UpdateRequest update = new UpdateRequest(); update.setCommitWithin(10000); update.add(doc); //update.setAction(ACTION.COMMIT, false, false); server.request(update); } else { log.warn("({}) rejected document without 'id' for update", config.getName()); } } catch (IOException e) { log.warn("I/O exception while adding SOLR document to index", e); } catch (SolrServerException e) { log.warn("server exception while adding SOLR document to index", e); } finally { serverLock.unlock(); } } }
From source file:at.newmedialab.lmf.search.services.indexing.SolrCoreRuntime.java
License:Apache License
/** * Queue the deletion of a document in the Solr Core and check whether it is necessary to * commit.//from w w w .ja va2 s. c o m * * @param docId */ public void queueDeletion(String docId) { serverLock.lock(); try { UpdateRequest update = new UpdateRequest(); update.setCommitWithin(10000); update.deleteById(docId); //update.setAction(ACTION.COMMIT, false, false); server.request(update); } catch (IOException e) { log.warn("I/O exception while removing SOLR document from index", e); } catch (SolrServerException e) { log.warn("server exception while removing SOLR document from index", e); } finally { serverLock.unlock(); } }
From source file:at.newmedialab.lmf.search.services.indexing.SolrCoreRuntime.java
License:Apache License
/** * Clear the index managed by this SolrCoreRuntime. *//*www .jav a2 s . c om*/ public void clear() { serverLock.lock(); try { UpdateRequest request = new UpdateRequest(); request.deleteByQuery("id:[* TO *]"); request.setAction(ACTION.COMMIT, true, true); server.request(request); } catch (IOException e) { log.error("(" + config.getName() + ") could not clear search index: an I/O Exception occurred", e); } catch (SolrServerException e) { log.error( "(" + config.getName() + ") could not clear search index: a SOLR Exception occurred (server not available?)", e); } catch (Exception e) { log.error("(" + config.getName() + ") index could not be cleared: a runtime Exception occurred (server sending invalid response?)", e); } finally { serverLock.unlock(); } }
From source file:com.digitalpebble.behemoth.solr.SOLRWriter.java
License:Apache License
public void write(BehemothDocument doc) throws IOException { final SolrInputDocument inputDoc = convertToSOLR(doc); try {// www. j a v a2 s .c om progress.progress(); if (params == null) { solr.add(inputDoc); } else { UpdateRequest req = new UpdateRequest(); req.setParams(params); req.add(inputDoc); solr.request(req); } } catch (SolrServerException e) { throw makeIOException(e); } }
From source file:com.digitalpebble.storm.crawler.solr.SolrConnection.java
License:Apache License
public static UpdateRequest getRequest(Map stormConf, String boltType) { int commitWithin = ConfUtils.getInt(stormConf, "solr." + boltType + ".commit.within", -1); UpdateRequest request = new UpdateRequest(); if (commitWithin != -1) { request.setCommitWithin(commitWithin); }//from w w w . j a v a 2 s . com return request; }
From source file:com.doculibre.constellio.stats.StatsCompiler.java
License:Open Source License
public synchronized void saveStats(SimpleSearch simpleSearch, SolrServer indexJournal, SolrServer indexCompile, QueryResponse res) throws SolrServerException, IOException { String collectionName = simpleSearch.getCollectionName(); String luceneQuery = simpleSearch.getLuceneQuery(); GregorianCalendar calendar = new GregorianCalendar(); Date time = new Date(); calendar.setTime(time);// w w w . j a v a 2 s . co m String query = luceneQuery; String escapedQuery = escape(query); long nbRes = res.getResults().getNumFound(); long qTime = res.getQTime(); String desplayDate = time.toString(); String searchDate = format(time); String queryWithParams = simpleSearch.toSimpleParams().toString(); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", desplayDate + query); doc.addField("query", query); doc.addField("queryWithParams", queryWithParams); doc.addField("nbres", "" + nbRes); doc.addField("qtime", "" + qTime); doc.addField("dateaffiche", desplayDate); doc.addField("date", searchDate); doc.addField("recherche", "recherche"); doc.addField("collection", collectionName); UpdateRequest up = new UpdateRequest(); up.setAction(ACTION.COMMIT, true, true); up.add(doc); up.process(indexJournal); String compileId = "collection_" + collectionName + " id_" + escapedQuery; SolrQuery solrQuery = new SolrQuery(); // Requte Lucene solrQuery.setQuery("id:\"" + compileId + "\""); // nb rsultats par page solrQuery.setRows(15); // page de dbut solrQuery.setStart(0); QueryResponse qr = indexCompile.query(solrQuery); if (qr.getResults().getNumFound() > 0) { SolrDocument sd = qr.getResults().get(0); long freq = (Long) sd.getFieldValue("freq"); long click = (Long) sd.getFieldValue("click"); // indexCompile.deleteById(query); SolrInputDocument docCompile = new SolrInputDocument(); docCompile.addField("id", compileId); docCompile.addField("query", query); if (!((String) sd.getFieldValue("nbres")).equals("0")) { ConstellioSpringUtils.getAutocompleteServices().onQueryAdd(docCompile, query); } docCompile.addField("freq", freq + 1); docCompile.addField("nbres", "" + nbRes); docCompile.addField("recherche", "recherche"); docCompile.addField("collection", collectionName); if (nbRes == 0) { docCompile.addField("zero", "true"); } else { docCompile.addField("zero", "false"); } docCompile.addField("click", click); if (click == 0) { docCompile.addField("clickstr", "zero"); } else { docCompile.addField("clickstr", "notzero"); } up.clear(); up.setAction(ACTION.COMMIT, true, true); up.add(docCompile); up.process(indexCompile); } else { SolrInputDocument docCompile = new SolrInputDocument(); docCompile.addField("id", compileId); docCompile.addField("query", query); if (nbRes != 0) { ConstellioSpringUtils.getAutocompleteServices().onQueryAdd(docCompile, query); } docCompile.addField("freq", 1); docCompile.addField("recherche", "recherche"); docCompile.addField("collection", collectionName); docCompile.addField("nbres", "" + nbRes); if (nbRes == 0) { docCompile.addField("zero", "true"); } else { docCompile.addField("zero", "false"); } docCompile.addField("click", 0); docCompile.addField("clickstr", "zero"); up.clear(); up.setAction(ACTION.COMMIT, true, true); up.add(docCompile); up.process(indexCompile); } }
From source file:com.doculibre.constellio.stats.StatsCompiler.java
License:Open Source License
public synchronized void computeClick(String collectionName, SolrServer indexCompile, SimpleSearch simpleSearch) throws SolrServerException, IOException { String query = simpleSearch.getLuceneQuery(); String escapedQuery = escape(query); String compileId = "collection_" + collectionName + " id_" + escapedQuery; SolrQuery solrQuery = new SolrQuery(); // Requte Lucene solrQuery.setQuery("id:\"" + compileId + "\""); // nb rsultats par page solrQuery.setRows(15);/*from www .j a v a 2s .c om*/ // page de dbut solrQuery.setStart(0); QueryResponse qr = indexCompile.query(solrQuery); if (qr.getResults().getNumFound() > 0) { SolrDocument sd = qr.getResults().get(0); long click = (Long) sd.getFieldValue("click"); indexCompile.deleteById(escapedQuery); SolrInputDocument docCompile = new SolrInputDocument(); docCompile.addField("id", compileId); docCompile.addField("query", query); if (!((String) sd.getFieldValue("nbres")).equals("0")) { ConstellioSpringUtils.getAutocompleteServices().onQueryAdd(docCompile, query); } docCompile.addField("freq", (Long) sd.getFieldValue("freq")); docCompile.addField("recherche", "recherche"); docCompile.addField("zero", (String) sd.getFieldValue("zero")); docCompile.addField("nbres", (String) sd.getFieldValue("nbres")); docCompile.addField("click", (click + 1)); docCompile.addField("clickstr", "notzero"); docCompile.addField("collection", collectionName); UpdateRequest up = new UpdateRequest(); up.setAction(ACTION.COMMIT, true, true); up.add(docCompile); up.process(indexCompile); } }
From source file:com.doculibre.constellio.stats.StatsCompiler.java
License:Open Source License
public synchronized void computeClickUrl(String collectionName, String url, String recordURL, SolrServer indexurl, SimpleSearch simpleSearch) throws SolrServerException, IOException { String query = simpleSearch.getLuceneQuery(); String escapedQuery = escape(query); String compileId = "url_" + url + " collection_" + collectionName + " id_" + escapedQuery; SolrQuery solrQuery = new SolrQuery(); // Requte Lucene solrQuery.setQuery("id:\"" + compileId + "\""); // nb rsultats par page solrQuery.setRows(15);/* w w w . j ava 2 s . c o m*/ // page de dbut solrQuery.setStart(0); QueryResponse qr = indexurl.query(solrQuery); if (qr.getResults().getNumFound() > 0) { SolrDocument sd = qr.getResults().get(0); long nbClick = (Long) sd.getFieldValue("nbclick"); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", compileId); doc.addField("query", escapedQuery); doc.addField("url", url); doc.addField("nbclick", nbClick + 1); doc.addField("recordURL", recordURL); doc.addField("collectionName", collectionName); UpdateRequest up = new UpdateRequest(); up.setAction(ACTION.COMMIT, true, true); up.add(doc); up.process(indexurl); } else { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", compileId); doc.addField("query", escapedQuery); doc.addField("url", url); doc.addField("nbclick", 0); doc.addField("recordURL", recordURL); doc.addField("collectionName", collectionName); UpdateRequest up = new UpdateRequest(); up.setAction(ACTION.COMMIT, true, true); up.add(doc); up.process(indexurl); } }
From source file:com.ifactory.press.db.solr.processor.UpdateDocValuesTest.java
License:Apache License
@Test /** The update service throws an error when key field is provided with no value fields */ public void testMissingValue() throws Exception { insertTestDocuments(1);//from w w w .ja v a 2s .co m UpdateRequest req = new UpdateRequest(); SolrInputDocument doc = new SolrInputDocument(); req.add(doc); req.setPath(UPDATE_DOCVALUES); req.setParam(UpdateDocValuesProcessor.UPDATEDV_KEY_FIELD, "id"); req.setParam(UpdateDocValuesProcessor.UPDATEDV_VALUE_FIELD, "x"); // doc with no value for key try { solr.request(req); assertFalse("expected exception not thrown", true); } catch (SolrException e) { assertTrue(e.getMessage(), e.getMessage().contains("no value for updatedv.key.field")); } doc.addField("id", "id0"); req.setParam(UpdateDocValuesProcessor.UPDATEDV_VALUE_FIELD, null); // no UpdateDocValuesProcessor.UPDATEDV_VALUE_FIELD try { solr.request(req); assertFalse("expected exception not thrown", true); } catch (SolrException e) { assertTrue(e.getMessage().contains("missing parameter updatedv.value.field")); } }
From source file:com.ifactory.press.db.solr.processor.UpdateDocValuesTest.java
License:Apache License
private void insertTestDocuments(int n, int nkids, boolean preserveDV) throws Exception { UpdateRequest req = new UpdateRequest(); req.setPath(UPDATE_DOCVALUES);/*from w w w . j av a 2 s . co m*/ if (preserveDV) { req.setParam(UpdateDocValuesProcessor.UPDATEDV_VALUE_FIELD, WEIGHT_DV); } for (int i = 1; i <= n; i++) { SolrInputDocument doc = new SolrInputDocument(); doc.addField(URI, uri(i)); doc.addField(TEXT_FIELD, "This is document " + i); // NOTE: must provide a value for at least one document in order to create the field: // it's not enough to just put it in the solr schema if (!preserveDV) { doc.addField(WEIGHT_DV, 0); } for (int j = 1; j <= nkids; j++) { SolrInputDocument kid = new SolrInputDocument(); kid.addField(URI, uriChild(i, j)); kid.addField(TEXT_FIELD, "This is child document " + i + "/" + j); doc.addChildDocument(kid); } req.add(doc); } solr.request(req); solr.commit(false, true, true); }