List of usage examples for org.apache.solr.update AddUpdateCommand getLuceneDocument
public Document getLuceneDocument()
From source file:jp.sf.fess.solr.plugin.update.DocValueUpdateHandlerFilter.java
License:Apache License
@Override public int addDoc(final AddUpdateCommand cmd, final UpdateHandlerFilterChain chain) throws IOException { final String exCmd = cmd.getReq().getParams().get(EXTENDED_CMD); if (UPDATE_CMD.equals(exCmd)) { final String termName = cmd.getReq().getParams().get(TERM_PARAM); if (termName == null) { throw new IllegalArgumentException("term is not specified."); }/*from w w w.j a va 2s . c om*/ int rc = -1; final RefCounted<IndexWriter> iw = updateHandler.getSolrCoreState() .getIndexWriter(updateHandler.getSolrCore()); try { final IndexWriter writer = iw.get(); if (cmd.isBlock()) { for (final Iterable<? extends IndexableField> doc : cmd) { updateNumericValue(writer, doc, termName); } } else { final Iterable<IndexableField> doc = cmd.getLuceneDocument(); updateNumericValue(writer, doc, termName); } rc = 1; } finally { iw.decref(); } return rc; } else { return chain.addDoc(cmd); } }
From source file:lux.solr.LuxUpdateProcessor.java
License:Mozilla Public License
@Override public void processAdd(final AddUpdateCommand cmd) throws IOException { SolrInputDocument solrInputDocument = cmd.getSolrInputDocument(); String xmlFieldName = indexConfig.getFieldName(FieldRole.XML_STORE); String idFieldName = indexConfig.getFieldName(FieldRole.ID); // remove and stash the xml field value SolrInputField xmlField = solrInputDocument.removeField(xmlFieldName); SolrInputField luxIdField = solrInputDocument.removeField(idFieldName); String uri = (String) solrInputDocument.getFieldValue(indexConfig.getFieldName(FieldRole.URI)); Document luceneDocument = cmd.getLuceneDocument(); UpdateDocCommand luxCommand = null;/*from ww w.j a v a 2s .co m*/ if (uri != null && xmlField != null) { // restore the xml field value solrInputDocument.put(xmlFieldName, xmlField); XmlIndexer xmlIndexer = solrIndexConfig.checkoutXmlIndexer(); Object xml = xmlField.getFirstValue(); try { try { if (xml instanceof String) { xmlIndexer.index(new StringReader((String) xml), uri); } else if (xml instanceof byte[]) { TinyBinary xmlbin = new TinyBinary((byte[]) xml, Charset.forName("utf-8")); xmlIndexer.index(xmlbin.getTinyDocument(saxonConfig), uri); } else if (xml instanceof NodeInfo) { xmlIndexer.index((NodeInfo) xml, uri); } // why is this here? we're getting double values now since we also call // addDocumentFIelds below? //luceneDocument = xmlIndexer.createLuceneDocument(); } catch (XMLStreamException e) { logger.error("Failed to parse " + FieldRole.XML_STORE, e); } addDocumentFields(xmlIndexer, solrIndexConfig.getSchema(), luceneDocument); if (luxIdField != null) { Object id = luxIdField.getValue(); if (!(id instanceof Long)) { // solr cloud distributes these as Strings id = Long.valueOf(id.toString()); } luceneDocument.add(new LongField(idFieldName, (Long) id, Store.YES)); } luxCommand = new UpdateDocCommand(req, solrInputDocument, luceneDocument, uri); } catch (Exception e) { logger.error("An error occurred while indexing " + uri, e); throw new IOException(e); } finally { solrIndexConfig.returnXmlIndexer(xmlIndexer); } // logger.debug ("Indexed XML document " + uri); } if (next != null) { next.processAdd(luxCommand == null ? cmd : luxCommand); } }