List of usage examples for org.apache.lucene.index IndexWriter updateNumericDocValue
public long updateNumericDocValue(Term term, String field, long value) throws IOException
field
to the given value
. From source file:com.vmware.xenon.services.common.LuceneDocumentIndexBackupService.java
License:Open Source License
private void updateCurrentAttributeForSelfLink(IndexSearcher searcher, long timeSnapshotBoundaryMicros, String selfLink, IndexWriter newWriter) throws IOException { Query selfLinkClause = new TermQuery(new Term(ServiceDocument.FIELD_NAME_SELF_LINK, selfLink)); Query updateTimeClause = LongPoint.newRangeQuery(ServiceDocument.FIELD_NAME_UPDATE_TIME_MICROS, 0, timeSnapshotBoundaryMicros); Query booleanQuery = new BooleanQuery.Builder().add(selfLinkClause, Occur.MUST) .add(updateTimeClause, Occur.MUST).build(); Sort versionSort = new Sort( new SortedNumericSortField(ServiceDocument.FIELD_NAME_VERSION, SortField.Type.LONG, true)); TopDocs results = searcher.search(booleanQuery, 1, versionSort, false, false); if (results == null || results.scoreDocs == null || results.scoreDocs.length == 0) { return;//from w w w .jav a2 s. c om } DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(); visitor.reset(LuceneIndexDocumentHelper.FIELD_NAME_INDEXING_ID); searcher.doc(results.scoreDocs[0].doc, visitor); if (visitor.documentIndexingId == null) { return; } Term indexingIdTerm = new Term(LuceneIndexDocumentHelper.FIELD_NAME_INDEXING_ID, visitor.documentIndexingId); newWriter.updateNumericDocValue(indexingIdTerm, LuceneIndexDocumentHelper.FIELD_NAME_INDEXING_METADATA_VALUE_TOMBSTONE_TIME, LuceneIndexDocumentHelper.ACTIVE_DOCUMENT_TOMBSTONE_TIME); }
From source file:jp.sf.fess.solr.plugin.update.DocValueUpdateHandlerFilter.java
License:Apache License
private void updateNumericValue(final IndexWriter writer, final Iterable<? extends IndexableField> doc, final String termName) throws IOException { String termValue = null;//from www . jav a 2s . co m final List<IndexableField> numericFieldList = new ArrayList<IndexableField>(); for (final IndexableField field : doc) { if (termName.equals(field.name()) && field.stringValue() != null) { termValue = field.stringValue(); } else if (field instanceof NumericDocValuesField) { numericFieldList.add(field); } } if (termValue == null) { throw new IllegalArgumentException("A value of term is not found in the doc."); } for (final IndexableField field : numericFieldList) { writer.updateNumericDocValue(new Term(termName, termValue), field.name(), field.numericValue().longValue()); } }