List of usage examples for org.apache.solr.common SolrInputDocument isEmpty
@Override
public boolean isEmpty()
From source file:cz.zcu.kiv.eegdatabase.logic.indexing.Indexer.java
License:Apache License
/** * Performs indexing of a POJO object.//from w ww .j a v a 2 s.c o m * @param instance The POJO to be indexed. * @throws IllegalAccessException * @throws IOException * @throws SolrServerException */ public void index(T instance) throws IllegalAccessException, IOException, SolrServerException { SolrInputDocument document = prepareForIndexing(instance); log.debug(document); if (document == null || document.isEmpty()) { return; } solrServer.add(document); // if the document already exists, it is replaced by the new one UpdateResponse response = solrServer.commit(); log.debug("Document " + document.get("uuid").getValue().toString() + " added to the solr index."); logCommitResponse(response); }
From source file:cz.zcu.kiv.eegdatabase.logic.indexing.Indexer.java
License:Apache License
/** * Performs indexing of a list of objects. * @param instanceList The list of all objects to be indexed. * @throws IllegalAccessException/*from w w w . j a v a 2 s. c o m*/ * @throws SolrServerException * @throws IOException */ public void indexAll(List<T> instanceList) throws IllegalAccessException, SolrServerException, IOException { int documentsToBeAdded = 0; for (T instance : instanceList) { SolrInputDocument document = prepareForIndexing(instance); // skip empty or null documents if (document == null || document.isEmpty()) { continue; } solrServer.add(document); documentsToBeAdded++; // commit in a batch if (documentsToBeAdded % BATCH_COMMIT_SIZE == 0) { UpdateResponse response = solrServer.commit(); logCommitResponse(response); } } // commit the rest if there are any uncommited documents if (documentsToBeAdded % BATCH_COMMIT_SIZE != 0) { UpdateResponse response = solrServer.commit(); logCommitResponse(response); } }
From source file:edu.ucsb.nceas.mdqengine.solr.SolrIndex.java
License:Open Source License
private synchronized void insertToIndex(SolrDoc doc) throws SolrServerException, IOException { if (doc != null) { SolrInputDocument solrDoc = new SolrInputDocument(); List<SolrElementField> list = doc.getFieldList(); if (list != null) { Iterator<SolrElementField> iterator = list.iterator(); while (iterator.hasNext()) { SolrElementField field = iterator.next(); if (field != null) { String value = field.getValue(); String name = field.getName(); solrDoc.addField(name, value); }/*from w ww . j av a 2 s . c om*/ } } if (!solrDoc.isEmpty()) { try { UpdateResponse response = solrClient.add(solrDoc); solrClient.commit(); } catch (SolrServerException e) { throw e; } catch (IOException e) { throw e; } } } }
From source file:org.si4t.solr.SolrIndexDispatcher.java
License:Apache License
public String addDocuments(DispatcherPackage dispatcherPackage) throws ParserConfigurationException, IOException, SAXException, SolrServerException { SolrServer server = this.getSolrServer(dispatcherPackage.getRequest()); if (server == null) { throw new SolrServerException("Solr server not instantiated."); }//from ww w. ja v a 2 s. co m ArrayList<SolrInputDocument> documents = dispatcherPackage.getDocuments(); if (documents == null) { throw new NullPointerException("Document list is null"); } for (SolrInputDocument d : documents) { if (d == null || d.isEmpty()) { log.error("Document is null Or empty"); } else { log.info(Utils.RemoveLineBreaks(d.toString())); server.add(d); } } UpdateResponse serverrsp = server.commit(true, true); return ("Processing " + documents.size() + " documents had the following response: " + serverrsp.getResponse()); }
From source file:org.springframework.data.solr.core.convert.MappingSolrConverterTests.java
License:Apache License
@Test public void testWriteNonMapPropertyWithWildcardWhenNotIndexed() { BeanWithCatchAllField bean = new BeanWithCatchAllField(); bean.allStringProperties = new String[] { "value_1", "value_2" }; SolrInputDocument solrDocument = new SolrInputDocument(); converter.write(bean, solrDocument); Assert.assertTrue(solrDocument.isEmpty()); }