Java Code Examples for org.apache.lucene.document.NumericDocValuesField#setLongValue()
The following examples show how to use
org.apache.lucene.document.NumericDocValuesField#setLongValue() .
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: BaseCompressingDocValuesFormatTestCase.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testSingleBigValueCompression() throws IOException { try (final Directory dir = new ByteBuffersDirectory()) { final IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); final IndexWriter iwriter = new IndexWriter(dir, iwc); final Document doc = new Document(); final NumericDocValuesField dvf = new NumericDocValuesField("dv", 0); doc.add(dvf); for (int i = 0; i < 20000; ++i) { dvf.setLongValue(i & 1023); iwriter.addDocument(doc); } iwriter.forceMerge(1); final long size1 = dirSize(dir); dvf.setLongValue(Long.MAX_VALUE); iwriter.addDocument(doc); iwriter.forceMerge(1); final long size2 = dirSize(dir); // make sure the new value did not grow the bpv for every other value assertTrue(size2 < size1 + (20000 * (63 - 10)) / 8); } }
Example 2
Source File: TestRangeFacetCounts.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testBasicLong() throws Exception { Directory d = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), d); Document doc = new Document(); NumericDocValuesField field = new NumericDocValuesField("field", 0L); doc.add(field); for(long l=0;l<100;l++) { field.setLongValue(l); w.addDocument(doc); } // Also add Long.MAX_VALUE field.setLongValue(Long.MAX_VALUE); w.addDocument(doc); IndexReader r = w.getReader(); w.close(); FacetsCollector fc = new FacetsCollector(); IndexSearcher s = newSearcher(r); s.search(new MatchAllDocsQuery(), fc); Facets facets = new LongRangeFacetCounts("field", fc, new LongRange("less than 10", 0L, true, 10L, false), new LongRange("less than or equal to 10", 0L, true, 10L, true), new LongRange("over 90", 90L, false, 100L, false), new LongRange("90 or above", 90L, true, 100L, false), new LongRange("over 1000", 1000L, false, Long.MAX_VALUE, true)); FacetResult result = facets.getTopChildren(10, "field"); assertEquals("dim=field path=[] value=22 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (1)\n", result.toString()); r.close(); d.close(); }
Example 3
Source File: TestRangeFacetCounts.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testLongGetAllDims() throws Exception { Directory d = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), d); Document doc = new Document(); NumericDocValuesField field = new NumericDocValuesField("field", 0L); doc.add(field); for(long l=0;l<100;l++) { field.setLongValue(l); w.addDocument(doc); } // Also add Long.MAX_VALUE field.setLongValue(Long.MAX_VALUE); w.addDocument(doc); IndexReader r = w.getReader(); w.close(); FacetsCollector fc = new FacetsCollector(); IndexSearcher s = newSearcher(r); s.search(new MatchAllDocsQuery(), fc); Facets facets = new LongRangeFacetCounts("field", fc, new LongRange("less than 10", 0L, true, 10L, false), new LongRange("less than or equal to 10", 0L, true, 10L, true), new LongRange("over 90", 90L, false, 100L, false), new LongRange("90 or above", 90L, true, 100L, false), new LongRange("over 1000", 1000L, false, Long.MAX_VALUE, true)); List<FacetResult> result = facets.getAllDims(10); assertEquals(1, result.size()); assertEquals("dim=field path=[] value=22 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (1)\n", result.get(0).toString()); r.close(); d.close(); }
Example 4
Source File: TestRangeFacetCounts.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testLongMinMax() throws Exception { Directory d = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), d); Document doc = new Document(); NumericDocValuesField field = new NumericDocValuesField("field", 0L); doc.add(field); field.setLongValue(Long.MIN_VALUE); w.addDocument(doc); field.setLongValue(0); w.addDocument(doc); field.setLongValue(Long.MAX_VALUE); w.addDocument(doc); IndexReader r = w.getReader(); w.close(); FacetsCollector fc = new FacetsCollector(); IndexSearcher s = newSearcher(r); s.search(new MatchAllDocsQuery(), fc); Facets facets = new LongRangeFacetCounts("field", fc, new LongRange("min", Long.MIN_VALUE, true, Long.MIN_VALUE, true), new LongRange("max", Long.MAX_VALUE, true, Long.MAX_VALUE, true), new LongRange("all0", Long.MIN_VALUE, true, Long.MAX_VALUE, true), new LongRange("all1", Long.MIN_VALUE, false, Long.MAX_VALUE, true), new LongRange("all2", Long.MIN_VALUE, true, Long.MAX_VALUE, false), new LongRange("all3", Long.MIN_VALUE, false, Long.MAX_VALUE, false)); FacetResult result = facets.getTopChildren(10, "field"); assertEquals("dim=field path=[] value=3 childCount=6\n min (1)\n max (1)\n all0 (3)\n all1 (2)\n all2 (2)\n all3 (1)\n", result.toString()); r.close(); d.close(); }
Example 5
Source File: TestRangeFacetCounts.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testOverlappedEndStart() throws Exception { Directory d = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), d); Document doc = new Document(); NumericDocValuesField field = new NumericDocValuesField("field", 0L); doc.add(field); for(long l=0;l<100;l++) { field.setLongValue(l); w.addDocument(doc); } field.setLongValue(Long.MAX_VALUE); w.addDocument(doc); IndexReader r = w.getReader(); w.close(); FacetsCollector fc = new FacetsCollector(); IndexSearcher s = newSearcher(r); s.search(new MatchAllDocsQuery(), fc); Facets facets = new LongRangeFacetCounts("field", fc, new LongRange("0-10", 0L, true, 10L, true), new LongRange("10-20", 10L, true, 20L, true), new LongRange("20-30", 20L, true, 30L, true), new LongRange("30-40", 30L, true, 40L, true)); FacetResult result = facets.getTopChildren(10, "field"); assertEquals("dim=field path=[] value=41 childCount=4\n 0-10 (11)\n 10-20 (11)\n 20-30 (11)\n 30-40 (11)\n", result.toString()); r.close(); d.close(); }
Example 6
Source File: TestRangeFacetCounts.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testMissingValues() throws Exception { Directory d = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), d); Document doc = new Document(); NumericDocValuesField field = new NumericDocValuesField("field", 0L); doc.add(field); for(long l=0;l<100;l++) { if (l % 5 == 0) { // Every 5th doc is missing the value: w.addDocument(new Document()); continue; } field.setLongValue(l); w.addDocument(doc); } IndexReader r = w.getReader(); FacetsCollector fc = new FacetsCollector(); IndexSearcher s = newSearcher(r); s.search(new MatchAllDocsQuery(), fc); Facets facets = new LongRangeFacetCounts("field", fc, new LongRange("less than 10", 0L, true, 10L, false), new LongRange("less than or equal to 10", 0L, true, 10L, true), new LongRange("over 90", 90L, false, 100L, false), new LongRange("90 or above", 90L, true, 100L, false), new LongRange("over 1000", 1000L, false, Long.MAX_VALUE, false)); assertEquals("dim=field path=[] value=16 childCount=5\n less than 10 (8)\n less than or equal to 10 (8)\n over 90 (8)\n 90 or above (8)\n over 1000 (0)\n", facets.getTopChildren(10, "field").toString()); w.close(); IOUtils.close(r, d); }
Example 7
Source File: BaseCompressingDocValuesFormatTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testUniqueValuesCompression() throws IOException { try (final Directory dir = new ByteBuffersDirectory()) { final IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); final IndexWriter iwriter = new IndexWriter(dir, iwc); final int uniqueValueCount = TestUtil.nextInt(random(), 1, 256); final List<Long> values = new ArrayList<>(); final Document doc = new Document(); final NumericDocValuesField dvf = new NumericDocValuesField("dv", 0); doc.add(dvf); for (int i = 0; i < 300; ++i) { final long value; if (values.size() < uniqueValueCount) { value = random().nextLong(); values.add(value); } else { value = RandomPicks.randomFrom(random(), values); } dvf.setLongValue(value); iwriter.addDocument(doc); } iwriter.forceMerge(1); final long size1 = dirSize(dir); for (int i = 0; i < 20; ++i) { dvf.setLongValue(RandomPicks.randomFrom(random(), values)); iwriter.addDocument(doc); } iwriter.forceMerge(1); final long size2 = dirSize(dir); // make sure the new longs did not cost 8 bytes each assertTrue(size2 < size1 + 8 * 20); } }
Example 8
Source File: BaseCompressingDocValuesFormatTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testDateCompression() throws IOException { try (final Directory dir = new ByteBuffersDirectory()) { final IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); final IndexWriter iwriter = new IndexWriter(dir, iwc); final long base = 13; // prime final long day = 1000L * 60 * 60 * 24; final Document doc = new Document(); final NumericDocValuesField dvf = new NumericDocValuesField("dv", 0); doc.add(dvf); for (int i = 0; i < 300; ++i) { dvf.setLongValue(base + random().nextInt(1000) * day); iwriter.addDocument(doc); } iwriter.forceMerge(1); final long size1 = dirSize(dir); for (int i = 0; i < 50; ++i) { dvf.setLongValue(base + random().nextInt(1000) * day); iwriter.addDocument(doc); } iwriter.forceMerge(1); final long size2 = dirSize(dir); // make sure the new longs costed less than if they had only been packed assertTrue(size2 < size1 + (PackedInts.bitsRequired(day) * 50) / 8); } }
Example 9
Source File: Test2BNumericDocValues.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testNumerics() throws Exception { BaseDirectoryWrapper dir = newFSDirectory(createTempDir("2BNumerics")); if (dir instanceof MockDirectoryWrapper) { ((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER); } IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random())) .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH) .setRAMBufferSizeMB(256.0) .setMergeScheduler(new ConcurrentMergeScheduler()) .setMergePolicy(newLogMergePolicy(false, 10)) .setOpenMode(IndexWriterConfig.OpenMode.CREATE) .setCodec(TestUtil.getDefaultCodec())); Document doc = new Document(); NumericDocValuesField dvField = new NumericDocValuesField("dv", 0); doc.add(dvField); for (int i = 0; i < IndexWriter.MAX_DOCS; i++) { dvField.setLongValue(i); w.addDocument(doc); if (i % 100000 == 0) { System.out.println("indexed: " + i); System.out.flush(); } } w.forceMerge(1); w.close(); System.out.println("verifying..."); System.out.flush(); DirectoryReader r = DirectoryReader.open(dir); long expectedValue = 0; for (LeafReaderContext context : r.leaves()) { LeafReader reader = context.reader(); NumericDocValues dv = reader.getNumericDocValues("dv"); for (int i = 0; i < reader.maxDoc(); i++) { assertEquals(i, dv.nextDoc()); assertEquals(expectedValue, dv.longValue()); expectedValue++; } } r.close(); dir.close(); }