public void commit() throws IOException, SolrServerException { solr.commit(); }
/** * Delete data from the index, as described by a query. * * @param query description of the records to be deleted. * @throws IOException * @throws SolrServerException */ public static void removeIndex(String query) throws IOException, SolrServerException { solr.deleteByQuery(query); solr.commit(); }
public static void markRobotByUserAgent(String agent){ try { /* Result Process to alter record to be identified as a bot */ ResultProcessor processor = new ResultProcessor(){ public void process(SolrDocument doc) throws IOException, SolrServerException { doc.removeFields("isBot"); doc.addField("isBot", true); SolrInputDocument newInput = ClientUtils.toSolrInputDocument(doc); solr.add(newInput); } }; /* query for ip, exclude results previously set as bots. */ processor.execute("userAgent:"+agent+ " AND -isBot:true"); solr.commit(); } catch (Exception e) { log.error(e.getMessage(),e); } }
public static void markRobotsByIP() { for(String ip : SpiderDetector.getSpiderIpAddresses()){ try { /* Result Process to alter record to be identified as a bot */ ResultProcessor processor = new ResultProcessor(){ public void process(SolrDocument doc) throws IOException, SolrServerException { doc.removeFields("isBot"); doc.addField("isBot", true); SolrInputDocument newInput = ClientUtils.toSolrInputDocument(doc); solr.add(newInput); log.info("Marked " + doc.getFieldValue("ip") + " as bot"); } }; /* query for ip, exclude results previously set as bots. */ processor.execute("ip:"+ip+ "* AND -isBot:true"); solr.commit(); } catch (Exception e) { log.error(e.getMessage(),e); } } }
log.info("Running forced commit!"); try { core.commit(); } catch (Exception e) { log.warn("Solr forced commit failed. Document will" +
/** * Unindex a Document in the Lucene Index. * @param context the dspace context * @param handle the handle of the object to be deleted * @throws SQLException * @throws IOException */ public void unIndexContent(Context context, String handle, boolean commit) throws SQLException, IOException { try { getSolr().deleteById(handle); if(commit) { getSolr().commit(); } } catch (SolrServerException e) { log.error(e.getMessage(), e); } }
solr.add(newInput); solr.commit();
solr.commit(true, true);
getSolr().commit();
@Test public void testSolr() throws IOException, SolrServerException { Set<Cluster.Instance> instances = cluster.getInstancesMatching(role(SOLR_ROLE)); for (Cluster.Instance instance : instances) { String publicIp = instance.getPublicIp(); LOG.info("Adding a document to instance " + instance.getId() + " @ " + publicIp); CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(String.format("http://%s:%s/solr/core0", instance.getPublicHostName(), SOLR_PORT)); SolrInputDocument doc = new SolrInputDocument(); doc.addField("name", "Apache Whirr"); doc.addField("inceptionYear", "2010"); solrServer.add(doc); solrServer.commit(); LOG.info("Committed document to instance " + instance.getId() + " @ " + publicIp); LOG.info("Performing a search on instance " + instance.getId() + " @ " + publicIp); SolrQuery query = new SolrQuery("name:whirr"); QueryResponse response = solrServer.query(query); SolrDocumentList results = response.getResults(); assertEquals("Search on instance " + instance.getId() + " did NOT return a document!" , 1, results.size()); SolrDocument resultDoc = results.get(0); assertEquals("name field on document of instance " + instance.getId() + " is incorrect", "Apache Whirr", resultDoc.get("name")); } }