List of usage examples for org.apache.lucene.index LeafReader getNumericDocValues
public abstract NumericDocValues getNumericDocValues(String field) throws IOException;
From source file:org.elasticsearch.common.lucene.uid.PerThreadIDAndVersionLookup.java
License:Apache License
/** * Initialize lookup for the provided segment *//*from ww w . j a va2 s . c om*/ public PerThreadIDAndVersionLookup(LeafReader reader) throws IOException { TermsEnum termsEnum = null; NumericDocValues versions = null; boolean hasPayloads = false; Fields fields = reader.fields(); if (fields != null) { Terms terms = fields.terms(UidFieldMapper.NAME); if (terms != null) { hasPayloads = terms.hasPayloads(); termsEnum = terms.iterator(); assert termsEnum != null; versions = reader.getNumericDocValues(VersionFieldMapper.NAME); } } this.versions = versions; this.termsEnum = termsEnum; this.hasPayloads = hasPayloads; }
From source file:org.elasticsearch.common.lucene.uid.PerThreadIDVersionAndSeqNoLookup.java
License:Apache License
/** * Initialize lookup for the provided segment *///w w w .ja v a2 s . c om PerThreadIDVersionAndSeqNoLookup(LeafReader reader, String uidField) throws IOException { this.uidField = uidField; Terms terms = reader.terms(uidField); if (terms == null) { throw new IllegalArgumentException("reader misses the [" + uidField + "] field"); } termsEnum = terms.iterator(); if (reader.getNumericDocValues(VersionFieldMapper.NAME) == null) { throw new IllegalArgumentException("reader misses the [" + VersionFieldMapper.NAME + "] field"); } Object readerKey = null; assert (readerKey = reader.getCoreCacheHelper().getKey()) != null; this.readerKey = readerKey; }
From source file:org.elasticsearch.common.lucene.uid.VersionsResolver.java
License:Apache License
/** * Returns the primary term for the given uid term, returning {@code 0} if none is found. *//*from w ww.j a v a2 s .c o m*/ public static long loadPrimaryTerm(IndexReader reader, Term term) throws IOException { assert term.field().equals(UidFieldMapper.NAME) : "can only load _primary_term by uid"; List<LeafReaderContext> leaves = reader.leaves(); if (leaves.isEmpty()) { return 0; } // iterate backwards to optimize for the frequently updated documents // which are likely to be in the last segments for (int i = leaves.size() - 1; i >= 0; i--) { LeafReader leaf = leaves.get(i).reader(); Bits liveDocs = leaf.getLiveDocs(); TermsEnum termsEnum = null; NumericDocValues dvField = null; PostingsEnum docsEnum = null; final Fields fields = leaf.fields(); if (fields != null) { Terms terms = fields.terms(UidFieldMapper.NAME); if (terms != null) { termsEnum = terms.iterator(); assert termsEnum != null; dvField = leaf.getNumericDocValues(SeqNoFieldMapper.PRIMARY_TERM_NAME); assert dvField != null; final BytesRef id = term.bytes(); if (termsEnum.seekExact(id)) { // there may be more than one matching docID, in the // case of nested docs, so we want the last one: docsEnum = termsEnum.postings(docsEnum, 0); int docID = DocIdSetIterator.NO_MORE_DOCS; for (int d = docsEnum.nextDoc(); d != DocIdSetIterator.NO_MORE_DOCS; d = docsEnum .nextDoc()) { if (liveDocs != null && liveDocs.get(d) == false) { continue; } docID = d; } if (docID != DocIdSetIterator.NO_MORE_DOCS) { return dvField.get(docID); } } } } } return 0; }
From source file:org.elasticsearch.xpack.core.security.authz.accesscontrol.FieldSubsetReaderTests.java
License:Open Source License
/** * test filtering two numeric dv fields/*from www . ja v a2 s . co m*/ */ public void testNumericDocValues() throws Exception { Directory dir = newDirectory(); IndexWriterConfig iwc = new IndexWriterConfig(null); IndexWriter iw = new IndexWriter(dir, iwc); // add document with 2 fields Document doc = new Document(); doc.add(new NumericDocValuesField("fieldA", 1)); doc.add(new NumericDocValuesField("fieldB", 2)); iw.addDocument(doc); // open reader DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), new CharacterRunAutomaton(Automata.makeString("fieldA"))); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); NumericDocValues values = segmentReader.getNumericDocValues("fieldA"); assertNotNull(values); assertTrue(values.advanceExact(0)); assertEquals(1, values.longValue()); assertNull(segmentReader.getNumericDocValues("fieldB")); TestUtil.checkReader(ir); IOUtils.close(ir, iw, dir); }