Java Code Examples for org.apache.lucene.index.LeafReader#getSortedNumericDocValues()
The following examples show how to use
org.apache.lucene.index.LeafReader#getSortedNumericDocValues() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatisHelper.java From HongsCORE with MIT License | 6 votes |
@Override public LeafCollector getLeafCollector(LeafReaderContext lrc) throws IOException { LeafReader reader = lrc.reader( ); for (int i = 0; i < fields.length; i ++) { if (groups[i][0] >= 1) { if (groups[i][1] == 1) { values[i] = reader.getSortedNumericDocValues("%"+fields[i]); } else { values[i] = reader. getNumericDocValues("#"+fields[i]); } } else { if (groups[i][1] == 1) { values[i] = reader.getSortedSetDocValues("%"+fields[i]); } else { values[i] = reader. getSortedDocValues("#"+fields[i]); } } } return this; }
Example 2
Source File: TestMemoryIndex.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testDocValues_resetIterator() throws Exception { Document doc = new Document(); doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("f"))); doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("d"))); doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("d"))); doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("c"))); doc.add(new SortedNumericDocValuesField("sorted_numeric", 33L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 32L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 32L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 31L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 30L)); MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer); LeafReader leafReader = mi.createSearcher().getIndexReader().leaves().get(0).reader(); SortedSetDocValues sortedSetDocValues = leafReader.getSortedSetDocValues("sorted_set"); assertEquals(3, sortedSetDocValues.getValueCount()); for (int times = 0; times < 3; times++) { assertTrue(sortedSetDocValues.advanceExact(0)); assertEquals(0L, sortedSetDocValues.nextOrd()); assertEquals(1L, sortedSetDocValues.nextOrd()); assertEquals(2L, sortedSetDocValues.nextOrd()); assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSetDocValues.nextOrd()); } SortedNumericDocValues sortedNumericDocValues = leafReader.getSortedNumericDocValues("sorted_numeric"); for (int times = 0; times < 3; times++) { assertTrue(sortedNumericDocValues.advanceExact(0)); assertEquals(5, sortedNumericDocValues.docValueCount()); assertEquals(30L, sortedNumericDocValues.nextValue()); assertEquals(31L, sortedNumericDocValues.nextValue()); assertEquals(32L, sortedNumericDocValues.nextValue()); assertEquals(32L, sortedNumericDocValues.nextValue()); assertEquals(33L, sortedNumericDocValues.nextValue()); } }
Example 3
Source File: DocValuesFieldExistsQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns a {@link DocIdSetIterator} from the given field or null if the field doesn't exist * in the reader or if the reader has no doc values for the field. */ public static DocIdSetIterator getDocValuesDocIdSetIterator(String field, LeafReader reader) throws IOException { FieldInfo fieldInfo = reader.getFieldInfos().fieldInfo(field); final DocIdSetIterator iterator; if (fieldInfo != null) { switch (fieldInfo.getDocValuesType()) { case NONE: iterator = null; break; case NUMERIC: iterator = reader.getNumericDocValues(field); break; case BINARY: iterator = reader.getBinaryDocValues(field); break; case SORTED: iterator = reader.getSortedDocValues(field); break; case SORTED_NUMERIC: iterator = reader.getSortedNumericDocValues(field); break; case SORTED_SET: iterator = reader.getSortedSetDocValues(field); break; default: throw new AssertionError(); } return iterator; } return null; }
Example 4
Source File: FieldCacheImpl.java From lucene-solr with Apache License 2.0 | 5 votes |
private BitsEntry createValueDocValues(LeafReader reader, String field) throws IOException { FieldInfo fieldInfo = reader.getFieldInfos().fieldInfo(field); DocValuesType dvType = fieldInfo.getDocValuesType(); DocIdSetIterator iterator; switch(dvType) { case NUMERIC: iterator = reader.getNumericDocValues(field); break; case BINARY: iterator = reader.getBinaryDocValues(field); break; case SORTED: iterator = reader.getSortedDocValues(field); break; case SORTED_NUMERIC: iterator = reader.getSortedNumericDocValues(field); break; case SORTED_SET: iterator = reader.getSortedSetDocValues(field); break; default: throw new AssertionError(); } FixedBitSet bits = new FixedBitSet(reader.maxDoc()); while (true) { int docID = iterator.nextDoc(); if (docID == DocIdSetIterator.NO_MORE_DOCS) { break; } bits.set(docID); } return new BitsEntry(bits); }
Example 5
Source File: StatisHelper.java From HongsCORE with MIT License | 5 votes |
@Override public LeafCollector getLeafCollector(LeafReaderContext lrc) throws IOException { LeafReader reader = lrc.reader( ); for (int i = 0; i < fields.length; i ++) { if (groups[i][1] == 1) { values[i] = reader.getSortedNumericDocValues("%"+fields[i]); } else { values[i] = reader. getNumericDocValues("#"+fields[i]); } } return this; }
Example 6
Source File: TestMemoryIndex.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testDocValues() throws Exception { Document doc = new Document(); doc.add(new NumericDocValuesField("numeric", 29L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 33L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 32L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 32L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 31L)); doc.add(new SortedNumericDocValuesField("sorted_numeric", 30L)); doc.add(new BinaryDocValuesField("binary", new BytesRef("a"))); doc.add(new SortedDocValuesField("sorted", new BytesRef("b"))); doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("f"))); doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("d"))); doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("d"))); doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("c"))); MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer); LeafReader leafReader = mi.createSearcher().getIndexReader().leaves().get(0).reader(); NumericDocValues numericDocValues = leafReader.getNumericDocValues("numeric"); assertEquals(0, numericDocValues.nextDoc()); assertEquals(29L, numericDocValues.longValue()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, numericDocValues.nextDoc()); SortedNumericDocValues sortedNumericDocValues = leafReader.getSortedNumericDocValues("sorted_numeric"); assertEquals(0, sortedNumericDocValues.nextDoc()); assertEquals(5, sortedNumericDocValues.docValueCount()); assertEquals(30L, sortedNumericDocValues.nextValue()); assertEquals(31L, sortedNumericDocValues.nextValue()); assertEquals(32L, sortedNumericDocValues.nextValue()); assertEquals(32L, sortedNumericDocValues.nextValue()); assertEquals(33L, sortedNumericDocValues.nextValue()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, sortedNumericDocValues.nextDoc()); BinaryDocValues binaryDocValues = leafReader.getBinaryDocValues("binary"); assertEquals(0, binaryDocValues.nextDoc()); assertEquals("a", binaryDocValues.binaryValue().utf8ToString()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, binaryDocValues.nextDoc()); SortedDocValues sortedDocValues = leafReader.getSortedDocValues("sorted"); assertEquals(0, sortedDocValues.nextDoc()); assertEquals("b", sortedDocValues.binaryValue().utf8ToString()); assertEquals(0, sortedDocValues.ordValue()); assertEquals("b", sortedDocValues.lookupOrd(0).utf8ToString()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, sortedDocValues.nextDoc()); SortedSetDocValues sortedSetDocValues = leafReader.getSortedSetDocValues("sorted_set"); assertEquals(3, sortedSetDocValues.getValueCount()); assertEquals(0, sortedSetDocValues.nextDoc()); assertEquals(0L, sortedSetDocValues.nextOrd()); assertEquals(1L, sortedSetDocValues.nextOrd()); assertEquals(2L, sortedSetDocValues.nextOrd()); assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSetDocValues.nextOrd()); assertEquals("c", sortedSetDocValues.lookupOrd(0L).utf8ToString()); assertEquals("d", sortedSetDocValues.lookupOrd(1L).utf8ToString()); assertEquals("f", sortedSetDocValues.lookupOrd(2L).utf8ToString()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, sortedDocValues.nextDoc()); }
Example 7
Source File: TestUtil.java From lucene-solr with Apache License 2.0 | 4 votes |
private static void checkReaderSanity(LeafReader reader) throws IOException { for (FieldInfo info : reader.getFieldInfos()) { // reader shouldn't return normValues if the field does not have them if (!info.hasNorms()) { if (reader.getNormValues(info.name) != null) { throw new RuntimeException("field: " + info.name + " should omit norms but has them!"); } } // reader shouldn't return docValues if the field does not have them // reader shouldn't return multiple docvalues types for the same field. switch(info.getDocValuesType()) { case NONE: if (reader.getBinaryDocValues(info.name) != null || reader.getNumericDocValues(info.name) != null || reader.getSortedDocValues(info.name) != null || reader.getSortedSetDocValues(info.name) != null) { throw new RuntimeException("field: " + info.name + " has docvalues but should omit them!"); } break; case SORTED: if (reader.getBinaryDocValues(info.name) != null || reader.getNumericDocValues(info.name) != null || reader.getSortedNumericDocValues(info.name) != null || reader.getSortedSetDocValues(info.name) != null) { throw new RuntimeException(info.name + " returns multiple docvalues types!"); } break; case SORTED_NUMERIC: if (reader.getBinaryDocValues(info.name) != null || reader.getNumericDocValues(info.name) != null || reader.getSortedSetDocValues(info.name) != null || reader.getSortedDocValues(info.name) != null) { throw new RuntimeException(info.name + " returns multiple docvalues types!"); } break; case SORTED_SET: if (reader.getBinaryDocValues(info.name) != null || reader.getNumericDocValues(info.name) != null || reader.getSortedNumericDocValues(info.name) != null || reader.getSortedDocValues(info.name) != null) { throw new RuntimeException(info.name + " returns multiple docvalues types!"); } break; case BINARY: if (reader.getNumericDocValues(info.name) != null || reader.getSortedDocValues(info.name) != null || reader.getSortedNumericDocValues(info.name) != null || reader.getSortedSetDocValues(info.name) != null) { throw new RuntimeException(info.name + " returns multiple docvalues types!"); } break; case NUMERIC: if (reader.getBinaryDocValues(info.name) != null || reader.getSortedDocValues(info.name) != null || reader.getSortedNumericDocValues(info.name) != null || reader.getSortedSetDocValues(info.name) != null) { throw new RuntimeException(info.name + " returns multiple docvalues types!"); } break; default: throw new AssertionError(); } } }
Example 8
Source File: TestLucene80DocValuesFormat.java From lucene-solr with Apache License 2.0 | 4 votes |
@Nightly public void testSortedNumericAroundBlockSize() throws IOException { final int frontier = 1 << Lucene80DocValuesFormat.DIRECT_MONOTONIC_BLOCK_SHIFT; for (int maxDoc = frontier - 1; maxDoc <= frontier + 1; ++maxDoc) { final Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setMergePolicy(newLogMergePolicy())); ByteBuffersDataOutput buffer = new ByteBuffersDataOutput(); Document doc = new Document(); SortedNumericDocValuesField field1 = new SortedNumericDocValuesField("snum", 0L); doc.add(field1); SortedNumericDocValuesField field2 = new SortedNumericDocValuesField("snum", 0L); doc.add(field2); for (int i = 0; i < maxDoc; ++i) { long s1 = random().nextInt(100); long s2 = random().nextInt(100); field1.setLongValue(s1); field2.setLongValue(s2); w.addDocument(doc); buffer.writeVLong(Math.min(s1, s2)); buffer.writeVLong(Math.max(s1, s2)); } w.forceMerge(1); DirectoryReader r = DirectoryReader.open(w); w.close(); LeafReader sr = getOnlyLeafReader(r); assertEquals(maxDoc, sr.maxDoc()); SortedNumericDocValues values = sr.getSortedNumericDocValues("snum"); assertNotNull(values); ByteBuffersDataInput dataInput = buffer.toDataInput(); for (int i = 0; i < maxDoc; ++i) { assertEquals(i, values.nextDoc()); assertEquals(2, values.docValueCount()); assertEquals(dataInput.readVLong(), values.nextValue()); assertEquals(dataInput.readVLong(), values.nextValue()); } r.close(); dir.close(); } }