Search in sources :

Example 1 with LegacyDoubleField

use of org.apache.solr.legacy.LegacyDoubleField in project lucene-solr by apache.

the class TestFieldCacheSort method testLegacyDoubleMissingLast.

/** Tests sorting on type legacy double, specifying the missing value should be treated as Double.MAX_VALUE */
public void testLegacyDoubleMissingLast() throws IOException {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", -1.3, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", 4.2333333333333, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", 4.2333333333332, Field.Store.YES));
    writer.addDocument(doc);
    IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_DOUBLE));
    writer.close();
    IndexSearcher searcher = newSearcher(ir);
    SortField sortField = new SortField("value", SortField.Type.DOUBLE);
    sortField.setMissingValue(Double.MAX_VALUE);
    Sort sort = new Sort(sortField);
    TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
    assertEquals(4, td.totalHits);
    // null treated as Double.MAX_VALUE
    assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
    assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[1].doc).get("value"));
    assertEquals("4.2333333333333", searcher.doc(td.scoreDocs[2].doc).get("value"));
    assertNull(searcher.doc(td.scoreDocs[3].doc).get("value"));
    TestUtil.checkReader(ir);
    ir.close();
    dir.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) IndexReader(org.apache.lucene.index.IndexReader) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) Document(org.apache.lucene.document.Document) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Example 2 with LegacyDoubleField

use of org.apache.solr.legacy.LegacyDoubleField in project lucene-solr by apache.

the class TestFieldCacheSort method testLegacyDoubleReverse.

/** Tests sorting on type legacy double in reverse */
public void testLegacyDoubleReverse() throws IOException {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    doc.add(new LegacyDoubleField("value", 30.1, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", -1.3, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", 4.2333333333333, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", 4.2333333333332, Field.Store.YES));
    writer.addDocument(doc);
    IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_DOUBLE));
    writer.close();
    IndexSearcher searcher = newSearcher(ir);
    Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE, true));
    TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
    assertEquals(4, td.totalHits);
    // numeric order
    assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value"));
    assertEquals("4.2333333333333", searcher.doc(td.scoreDocs[1].doc).get("value"));
    assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[2].doc).get("value"));
    assertEquals("-1.3", searcher.doc(td.scoreDocs[3].doc).get("value"));
    TestUtil.checkReader(ir);
    ir.close();
    dir.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) IndexReader(org.apache.lucene.index.IndexReader) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) Document(org.apache.lucene.document.Document) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Example 3 with LegacyDoubleField

use of org.apache.solr.legacy.LegacyDoubleField in project lucene-solr by apache.

the class TestLegacyFieldCache method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    NUM_DOCS = atLeast(500);
    directory = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), directory, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
    long theLong = Long.MAX_VALUE;
    double theDouble = Double.MAX_VALUE;
    int theInt = Integer.MAX_VALUE;
    float theFloat = Float.MAX_VALUE;
    if (VERBOSE) {
        System.out.println("TEST: setUp");
    }
    for (int i = 0; i < NUM_DOCS; i++) {
        Document doc = new Document();
        doc.add(new LegacyLongField("theLong", theLong--, Field.Store.NO));
        doc.add(new LegacyDoubleField("theDouble", theDouble--, Field.Store.NO));
        doc.add(new LegacyIntField("theInt", theInt--, Field.Store.NO));
        doc.add(new LegacyFloatField("theFloat", theFloat--, Field.Store.NO));
        if (i % 2 == 0) {
            doc.add(new LegacyIntField("sparse", i, Field.Store.NO));
        }
        if (i % 2 == 0) {
            doc.add(new LegacyIntField("numInt", i, Field.Store.NO));
        }
        writer.addDocument(doc);
    }
    IndexReader r = writer.getReader();
    reader = SlowCompositeReaderWrapper.wrap(r);
    TestUtil.checkReader(reader);
    writer.close();
}
Also used : MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) LegacyLongField(org.apache.solr.legacy.LegacyLongField) IndexReader(org.apache.lucene.index.IndexReader) LegacyFloatField(org.apache.solr.legacy.LegacyFloatField) Document(org.apache.lucene.document.Document) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) LegacyIntField(org.apache.solr.legacy.LegacyIntField) BeforeClass(org.junit.BeforeClass)

Example 4 with LegacyDoubleField

use of org.apache.solr.legacy.LegacyDoubleField in project lucene-solr by apache.

the class TestLegacyTerms method testDoubleFieldMinMax.

public void testDoubleFieldMinMax() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    int numDocs = atLeast(100);
    double minValue = Double.POSITIVE_INFINITY;
    double maxValue = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < numDocs; i++) {
        Document doc = new Document();
        double num = random().nextDouble();
        minValue = Math.min(num, minValue);
        maxValue = Math.max(num, maxValue);
        doc.add(new LegacyDoubleField("field", num, Field.Store.NO));
        w.addDocument(doc);
    }
    IndexReader r = w.getReader();
    Terms terms = MultiFields.getTerms(r, "field");
    assertEquals(minValue, NumericUtils.sortableLongToDouble(LegacyNumericUtils.getMinLong(terms)), 0.0);
    assertEquals(maxValue, NumericUtils.sortableLongToDouble(LegacyNumericUtils.getMaxLong(terms)), 0.0);
    r.close();
    w.close();
    dir.close();
}
Also used : LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) IndexReader(org.apache.lucene.index.IndexReader) Terms(org.apache.lucene.index.Terms) Document(org.apache.lucene.document.Document) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Example 5 with LegacyDoubleField

use of org.apache.solr.legacy.LegacyDoubleField in project lucene-solr by apache.

the class TestFieldCacheSort method testLegacyDoubleMissing.

/** Tests sorting on type legacy double with a missing value */
public void testLegacyDoubleMissing() throws IOException {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", -1.3, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", 4.2333333333333, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyDoubleField("value", 4.2333333333332, Field.Store.YES));
    writer.addDocument(doc);
    IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_DOUBLE));
    writer.close();
    IndexSearcher searcher = newSearcher(ir);
    Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE));
    TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
    assertEquals(4, td.totalHits);
    // null treated as a 0
    assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
    assertNull(searcher.doc(td.scoreDocs[1].doc).get("value"));
    assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[2].doc).get("value"));
    assertEquals("4.2333333333333", searcher.doc(td.scoreDocs[3].doc).get("value"));
    TestUtil.checkReader(ir);
    ir.close();
    dir.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) IndexReader(org.apache.lucene.index.IndexReader) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) Document(org.apache.lucene.document.Document) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Aggregations

LegacyDoubleField (org.apache.solr.legacy.LegacyDoubleField)9 Document (org.apache.lucene.document.Document)7 IndexReader (org.apache.lucene.index.IndexReader)7 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)7 Directory (org.apache.lucene.store.Directory)6 IndexSearcher (org.apache.lucene.search.IndexSearcher)5 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)5 Sort (org.apache.lucene.search.Sort)5 SortField (org.apache.lucene.search.SortField)5 TopDocs (org.apache.lucene.search.TopDocs)5 LegacyFloatField (org.apache.solr.legacy.LegacyFloatField)2 LegacyIntField (org.apache.solr.legacy.LegacyIntField)2 LegacyLongField (org.apache.solr.legacy.LegacyLongField)2 Date (java.util.Date)1 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 DoubleDocValuesField (org.apache.lucene.document.DoubleDocValuesField)1 DoublePoint (org.apache.lucene.document.DoublePoint)1 Field (org.apache.lucene.document.Field)1 StoredField (org.apache.lucene.document.StoredField)1 Terms (org.apache.lucene.index.Terms)1