private static boolean insertBatch(HttpSolrClient client, List<SolrInputDocument> collect) { try { if (!config.getDryRun()) { logger.info("adding " + collect.size() + " documents (" + incrementCounter(collect.size()) + ")"); if(counter >= skipCount){ client.add(collect); if(commitAfter != null && counter - lastCommit > commitAfter){ commit(client); lastCommit = counter; } } else { logger.info("Skipping as current number of counter :" + counter +" is smaller than skipCount: " + skipCount); } } } catch (SolrServerException | IOException e) { logger.error("Problem while saving", e); return false; } return true; }
public boolean indexQuestion(int qid, String title, String content) throws IOException, SolrServerException { SolrInputDocument doc = new SolrInputDocument(); doc.setField("id", qid); doc.setField(QUESTION_TITLE_FIELD, title); doc.setField("QUESTION_CONTENT_FIELD", content); UpdateResponse response = client.add(doc, 1000); return response != null && response.getStatus() == 0; } }
HttpSolrClient solr = new HttpSolrClient.Builder(solrServer).build(); solr.deleteByQuery("*:*"); solr.add(solrDocumentList); solr.commit(); SolrQuery query = new SolrQuery("*:*");