Search in sources :

Example 11 with IntPoint

use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.

the class TestPointQueries method testBasicMultiValuedPointInSetQuery.

public void testBasicMultiValuedPointInSetQuery() 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 IntPoint("int", 42));
    doc.add(new LongPoint("long", 17L));
    doc.add(new LongPoint("long", 42L));
    doc.add(new FloatPoint("float", 17.0f));
    doc.add(new FloatPoint("float", 42.0f));
    doc.add(new DoublePoint("double", 17.0));
    doc.add(new DoublePoint("double", 42.0));
    doc.add(new BinaryPoint("bytes", new byte[] { 0, 17 }));
    doc.add(new BinaryPoint("bytes", new byte[] { 0, 42 }));
    w.addDocument(doc);
    IndexReader r = DirectoryReader.open(w);
    IndexSearcher s = newSearcher(r, false);
    assertEquals(0, s.count(IntPoint.newSetQuery("int", 16)));
    assertEquals(1, s.count(IntPoint.newSetQuery("int", 17)));
    assertEquals(1, s.count(IntPoint.newSetQuery("int", 17, 97, 42)));
    assertEquals(1, s.count(IntPoint.newSetQuery("int", -7, 17, 42, 97)));
    assertEquals(0, s.count(IntPoint.newSetQuery("int", 16, 20, 41, 97)));
    assertEquals(0, s.count(LongPoint.newSetQuery("long", 16)));
    assertEquals(1, s.count(LongPoint.newSetQuery("long", 17)));
    assertEquals(1, s.count(LongPoint.newSetQuery("long", 17, 97, 42)));
    assertEquals(1, s.count(LongPoint.newSetQuery("long", -7, 17, 42, 97)));
    assertEquals(0, s.count(LongPoint.newSetQuery("long", 16, 20, 41, 97)));
    assertEquals(0, s.count(FloatPoint.newSetQuery("float", 16)));
    assertEquals(1, s.count(FloatPoint.newSetQuery("float", 17)));
    assertEquals(1, s.count(FloatPoint.newSetQuery("float", 17, 97, 42)));
    assertEquals(1, s.count(FloatPoint.newSetQuery("float", -7, 17, 42, 97)));
    assertEquals(0, s.count(FloatPoint.newSetQuery("float", 16, 20, 41, 97)));
    assertEquals(0, s.count(DoublePoint.newSetQuery("double", 16)));
    assertEquals(1, s.count(DoublePoint.newSetQuery("double", 17)));
    assertEquals(1, s.count(DoublePoint.newSetQuery("double", 17, 97, 42)));
    assertEquals(1, s.count(DoublePoint.newSetQuery("double", -7, 17, 42, 97)));
    assertEquals(0, s.count(DoublePoint.newSetQuery("double", 16, 20, 41, 97)));
    assertEquals(0, s.count(BinaryPoint.newSetQuery("bytes", new byte[] { 0, 16 })));
    assertEquals(1, s.count(BinaryPoint.newSetQuery("bytes", new byte[] { 0, 17 })));
    assertEquals(1, s.count(BinaryPoint.newSetQuery("bytes", new byte[] { 0, 17 }, new byte[] { 0, 97 }, new byte[] { 0, 42 })));
    assertEquals(1, s.count(BinaryPoint.newSetQuery("bytes", new byte[] { 0, -7 }, new byte[] { 0, 17 }, new byte[] { 0, 42 }, new byte[] { 0, 97 })));
    assertEquals(0, s.count(BinaryPoint.newSetQuery("bytes", new byte[] { 0, 16 }, new byte[] { 0, 20 }, new byte[] { 0, 41 }, new byte[] { 0, 97 })));
    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)

Example 12 with IntPoint

use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.

the class TestPointQueries method testRangeOptimizesIfAllPointsMatch.

public void testRangeOptimizesIfAllPointsMatch() throws IOException {
    final int numDims = TestUtil.nextInt(random(), 1, 3);
    Directory dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    int[] value = new int[numDims];
    for (int i = 0; i < numDims; ++i) {
        value[i] = TestUtil.nextInt(random(), 1, 10);
    }
    doc.add(new IntPoint("point", value));
    w.addDocument(doc);
    IndexReader reader = w.getReader();
    IndexSearcher searcher = new IndexSearcher(reader);
    searcher.setQueryCache(null);
    int[] lowerBound = new int[numDims];
    int[] upperBound = new int[numDims];
    for (int i = 0; i < numDims; ++i) {
        lowerBound[i] = value[i] - random().nextInt(1);
        upperBound[i] = value[i] + random().nextInt(1);
    }
    Query query = IntPoint.newRangeQuery("point", lowerBound, upperBound);
    Weight weight = searcher.createNormalizedWeight(query, false);
    Scorer scorer = weight.scorer(searcher.getIndexReader().leaves().get(0));
    assertEquals(DocIdSetIterator.all(1).getClass(), scorer.iterator().getClass());
    // When not all documents in the query have a value, the optimization is not applicable
    reader.close();
    w.addDocument(new Document());
    w.forceMerge(1);
    reader = w.getReader();
    searcher = new IndexSearcher(reader);
    searcher.setQueryCache(null);
    weight = searcher.createNormalizedWeight(query, false);
    scorer = weight.scorer(searcher.getIndexReader().leaves().get(0));
    assertFalse(DocIdSetIterator.all(1).getClass().equals(scorer.iterator().getClass()));
    reader.close();
    w.close();
    dir.close();
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) 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) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Example 13 with IntPoint

use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.

the class TestPointQueries method testBasicMultiDimPointInSetQuery.

public void testBasicMultiDimPointInSetQuery() 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, 42));
    w.addDocument(doc);
    IndexReader r = DirectoryReader.open(w);
    IndexSearcher s = newSearcher(r, false);
    assertEquals(0, s.count(newMultiDimIntSetQuery("int", 2, 17, 41)));
    assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, 17, 42)));
    assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, -7, -7, 17, 42)));
    assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, 17, 42, -14, -14)));
    w.close();
    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) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 14 with IntPoint

use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.

the class TestAddIndexes method addDocs.

private void addDocs(IndexWriter writer, int numDocs) throws IOException {
    for (int i = 0; i < numDocs; i++) {
        Document doc = new Document();
        doc.add(newTextField("content", "aaa", Field.Store.NO));
        doc.add(new IntPoint("doc", i));
        doc.add(new IntPoint("doc2d", i, i));
        doc.add(new NumericDocValuesField("dv", i));
        writer.addDocument(doc);
    }
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) Document(org.apache.lucene.document.Document) IntPoint(org.apache.lucene.document.IntPoint)

Example 15 with IntPoint

use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.

the class TestAddIndexes method testWithPendingDeletes2.

public void testWithPendingDeletes2() throws IOException {
    // main directory
    Directory dir = newDirectory();
    // auxiliary directory
    Directory aux = newDirectory();
    setUpDirs(dir, aux);
    IndexWriter writer = newWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
    // docs, so 10 pending deletes:
    for (int i = 0; i < 20; i++) {
        Document doc = new Document();
        doc.add(newStringField("id", "" + (i % 10), Field.Store.NO));
        doc.add(newTextField("content", "bbb " + i, Field.Store.NO));
        doc.add(new IntPoint("doc", i));
        doc.add(new IntPoint("doc2d", i, i));
        doc.add(new NumericDocValuesField("dv", i));
        writer.updateDocument(new Term("id", "" + (i % 10)), doc);
    }
    writer.addIndexes(aux);
    // Deletes one of the 10 added docs, leaving 9:
    PhraseQuery q = new PhraseQuery("content", "bbb", "14");
    writer.deleteDocuments(q);
    writer.forceMerge(1);
    writer.commit();
    verifyNumDocs(dir, 1039);
    verifyTermDocs(dir, new Term("content", "aaa"), 1030);
    verifyTermDocs(dir, new Term("content", "bbb"), 9);
    writer.close();
    dir.close();
    aux.close();
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) PhraseQuery(org.apache.lucene.search.PhraseQuery) Document(org.apache.lucene.document.Document) IntPoint(org.apache.lucene.document.IntPoint) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory)

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