Search in sources :

Example 51 with IntPoint

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"));
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 52 with IntPoint

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();
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 53 with IntPoint

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();
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) PointValues(org.apache.lucene.index.PointValues) Document(org.apache.lucene.document.Document) LongPoint(org.apache.lucene.document.LongPoint) FloatPoint(org.apache.lucene.document.FloatPoint) BinaryPoint(org.apache.lucene.document.BinaryPoint) DoublePoint(org.apache.lucene.document.DoublePoint) IntPoint(org.apache.lucene.document.IntPoint) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 54 with IntPoint

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();
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) IndexWriter(org.apache.lucene.index.IndexWriter) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) IndexReader(org.apache.lucene.index.IndexReader) Document(org.apache.lucene.document.Document) BinaryPoint(org.apache.lucene.document.BinaryPoint) DoublePoint(org.apache.lucene.document.DoublePoint) LongPoint(org.apache.lucene.document.LongPoint) IntPoint(org.apache.lucene.document.IntPoint) FloatPoint(org.apache.lucene.document.FloatPoint) Directory(org.apache.lucene.store.Directory)

Example 55 with IntPoint

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();
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) FloatPoint(org.apache.lucene.document.FloatPoint) BinaryPoint(org.apache.lucene.document.BinaryPoint) IndexWriter(org.apache.lucene.index.IndexWriter) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) DoublePoint(org.apache.lucene.document.DoublePoint) IndexReader(org.apache.lucene.index.IndexReader) LongPoint(org.apache.lucene.document.LongPoint) Document(org.apache.lucene.document.Document) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

IntPoint (org.apache.lucene.document.IntPoint)69 Document (org.apache.lucene.document.Document)64 Directory (org.apache.lucene.store.Directory)47 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)25 DoublePoint (org.apache.lucene.document.DoublePoint)23 FloatPoint (org.apache.lucene.document.FloatPoint)23 LongPoint (org.apache.lucene.document.LongPoint)23 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)22 IndexReader (org.apache.lucene.index.IndexReader)22 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)20 IndexWriter (org.apache.lucene.index.IndexWriter)19 BinaryPoint (org.apache.lucene.document.BinaryPoint)17 StoredField (org.apache.lucene.document.StoredField)16 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)16 RAMDirectory (org.apache.lucene.store.RAMDirectory)15 BytesRef (org.apache.lucene.util.BytesRef)14 StringField (org.apache.lucene.document.StringField)13 FSDirectory (org.apache.lucene.store.FSDirectory)12 IndexSearcher (org.apache.lucene.search.IndexSearcher)11 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)9