use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestPointValues method testMergedStatsOneSegmentWithoutPoints.
public void testMergedStatsOneSegmentWithoutPoints() throws IOException {
Directory dir = new RAMDirectory();
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null).setMergePolicy(NoMergePolicy.INSTANCE));
w.addDocument(new Document());
DirectoryReader.open(w).close();
Document doc = new Document();
doc.add(new IntPoint("field", Integer.MIN_VALUE));
w.addDocument(doc);
IndexReader reader = DirectoryReader.open(w);
assertArrayEquals(new byte[4], PointValues.getMinPackedValue(reader, "field"));
assertArrayEquals(new byte[4], PointValues.getMaxPackedValue(reader, "field"));
assertEquals(1, PointValues.getDocCount(reader, "field"));
assertEquals(1, PointValues.size(reader, "field"));
assertNull(PointValues.getMinPackedValue(reader, "field2"));
assertNull(PointValues.getMaxPackedValue(reader, "field2"));
assertEquals(0, PointValues.getDocCount(reader, "field2"));
assertEquals(0, PointValues.size(reader, "field2"));
}
use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestPointValues method testPointsFieldMissingFromOneSegment.
public void testPointsFieldMissingFromOneSegment() throws Exception {
Directory dir = FSDirectory.open(createTempDir());
IndexWriterConfig iwc = new IndexWriterConfig(null);
IndexWriter w = new IndexWriter(dir, iwc);
Document doc = new Document();
doc.add(new StringField("id", "0", Field.Store.NO));
doc.add(new IntPoint("int0", 0));
w.addDocument(doc);
w.commit();
doc = new Document();
doc.add(new IntPoint("int1", 17));
w.addDocument(doc);
w.forceMerge(1);
w.close();
dir.close();
}
use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestPointValues method testSparsePoints.
public void testSparsePoints() throws Exception {
Directory dir = newDirectory();
int numDocs = atLeast(1000);
int numFields = TestUtil.nextInt(random(), 1, 10);
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
int[] fieldDocCounts = new int[numFields];
int[] fieldSizes = new int[numFields];
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
for (int field = 0; field < numFields; field++) {
String fieldName = "int" + field;
if (random().nextInt(100) == 17) {
doc.add(new IntPoint(fieldName, random().nextInt()));
fieldDocCounts[field]++;
fieldSizes[field]++;
if (random().nextInt(10) == 5) {
// add same field again!
doc.add(new IntPoint(fieldName, random().nextInt()));
fieldSizes[field]++;
}
}
}
w.addDocument(doc);
}
IndexReader r = w.getReader();
for (int field = 0; field < numFields; field++) {
int docCount = 0;
int size = 0;
String fieldName = "int" + field;
for (LeafReaderContext ctx : r.leaves()) {
PointValues points = ctx.reader().getPointValues(fieldName);
if (points != null) {
docCount += points.getDocCount();
size += points.size();
}
}
assertEquals(fieldDocCounts[field], docCount);
assertEquals(fieldSizes[field], size);
}
r.close();
w.close();
dir.close();
}
use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestPointQueries method testInversePointRange.
public void testInversePointRange() throws IOException {
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
final int numDims = TestUtil.nextInt(random(), 1, 3);
// we need multiple leaves to enable this optimization
final int numDocs = atLeast(10 * BKDWriter.DEFAULT_MAX_POINTS_IN_LEAF_NODE);
for (int i = 0; i < numDocs; ++i) {
Document doc = new Document();
int[] values = new int[numDims];
Arrays.fill(values, i);
doc.add(new IntPoint("f", values));
w.addDocument(doc);
}
w.forceMerge(1);
IndexReader r = DirectoryReader.open(w);
w.close();
IndexSearcher searcher = newSearcher(r);
int[] low = new int[numDims];
int[] high = new int[numDims];
Arrays.fill(high, numDocs - 2);
assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high)));
Arrays.fill(low, 1);
assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high)));
Arrays.fill(high, numDocs - 1);
assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high)));
Arrays.fill(low, BKDWriter.DEFAULT_MAX_POINTS_IN_LEAF_NODE + 1);
assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high)));
Arrays.fill(high, numDocs - BKDWriter.DEFAULT_MAX_POINTS_IN_LEAF_NODE);
assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high)));
r.close();
dir.close();
}
use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestPointQueries method testEmptyPointInSetQuery.
public void testEmptyPointInSetQuery() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig();
iwc.setCodec(getCodec());
IndexWriter w = new IndexWriter(dir, iwc);
Document doc = new Document();
doc.add(new IntPoint("int", 17));
doc.add(new LongPoint("long", 17L));
doc.add(new FloatPoint("float", 17.0f));
doc.add(new DoublePoint("double", 17.0));
doc.add(new BinaryPoint("bytes", new byte[] { 0, 17 }));
w.addDocument(doc);
IndexReader r = DirectoryReader.open(w);
IndexSearcher s = newSearcher(r, false);
assertEquals(0, s.count(IntPoint.newSetQuery("int")));
assertEquals(0, s.count(LongPoint.newSetQuery("long")));
assertEquals(0, s.count(FloatPoint.newSetQuery("float")));
assertEquals(0, s.count(DoublePoint.newSetQuery("double")));
assertEquals(0, s.count(BinaryPoint.newSetQuery("bytes")));
w.close();
r.close();
dir.close();
}
Aggregations