Search in sources :

Example 6 with LegacyLongField

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

the class TestUninvertingReader method testSortedSetLong.

public void testSortedSetLong() throws IOException {
    Directory dir = newDirectory();
    IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null));
    Document doc = new Document();
    doc.add(new LegacyLongField("foo", 5, Field.Store.NO));
    iw.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyLongField("foo", 5, Field.Store.NO));
    doc.add(new LegacyLongField("foo", -3, Field.Store.NO));
    iw.addDocument(doc);
    iw.forceMerge(1);
    iw.close();
    DirectoryReader ir = UninvertingReader.wrap(DirectoryReader.open(dir), Collections.singletonMap("foo", Type.SORTED_SET_LONG));
    LeafReader ar = ir.leaves().get(0).reader();
    SortedSetDocValues v = ar.getSortedSetDocValues("foo");
    assertEquals(2, v.getValueCount());
    assertEquals(0, v.nextDoc());
    assertEquals(1, v.nextOrd());
    assertEquals(SortedSetDocValues.NO_MORE_ORDS, v.nextOrd());
    assertEquals(1, v.nextDoc());
    assertEquals(0, v.nextOrd());
    assertEquals(1, v.nextOrd());
    assertEquals(SortedSetDocValues.NO_MORE_ORDS, v.nextOrd());
    BytesRef value = v.lookupOrd(0);
    assertEquals(-3, LegacyNumericUtils.prefixCodedToLong(value));
    value = v.lookupOrd(1);
    assertEquals(5, LegacyNumericUtils.prefixCodedToLong(value));
    TestUtil.checkReader(ir);
    ir.close();
    dir.close();
}
Also used : LeafReader(org.apache.lucene.index.LeafReader) SortedSetDocValues(org.apache.lucene.index.SortedSetDocValues) IndexWriter(org.apache.lucene.index.IndexWriter) DirectoryReader(org.apache.lucene.index.DirectoryReader) LegacyLongField(org.apache.solr.legacy.LegacyLongField) Document(org.apache.lucene.document.Document) BytesRef(org.apache.lucene.util.BytesRef) Directory(org.apache.lucene.store.Directory)

Example 7 with LegacyLongField

use of org.apache.solr.legacy.LegacyLongField 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 8 with LegacyLongField

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

the class TestLegacyTerms method testLongFieldMinMax.

public void testLongFieldMinMax() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    int numDocs = atLeast(100);
    long minValue = Long.MAX_VALUE;
    long maxValue = Long.MIN_VALUE;
    for (int i = 0; i < numDocs; i++) {
        Document doc = new Document();
        long num = random().nextLong();
        minValue = Math.min(num, minValue);
        maxValue = Math.max(num, maxValue);
        doc.add(new LegacyLongField("field", num, Field.Store.NO));
        w.addDocument(doc);
    }
    IndexReader r = w.getReader();
    Terms terms = MultiFields.getTerms(r, "field");
    assertEquals(new Long(minValue), LegacyNumericUtils.getMinLong(terms));
    assertEquals(new Long(maxValue), LegacyNumericUtils.getMaxLong(terms));
    r.close();
    w.close();
    dir.close();
}
Also used : LegacyLongField(org.apache.solr.legacy.LegacyLongField) 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 9 with LegacyLongField

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

the class TestLegacyFieldCache method testLongFieldCache.

// Make sure that the use of GrowableWriter doesn't prevent from using the full long range
public void testLongFieldCache() throws IOException {
    Directory dir = newDirectory();
    IndexWriterConfig cfg = newIndexWriterConfig(new MockAnalyzer(random()));
    cfg.setMergePolicy(newLogMergePolicy());
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir, cfg);
    Document doc = new Document();
    LegacyLongField field = new LegacyLongField("f", 0L, Store.YES);
    doc.add(field);
    final long[] values = new long[TestUtil.nextInt(random(), 1, 10)];
    Set<Integer> missing = new HashSet<>();
    for (int i = 0; i < values.length; ++i) {
        final long v;
        switch(random().nextInt(10)) {
            case 0:
                v = Long.MIN_VALUE;
                break;
            case 1:
                v = 0;
                break;
            case 2:
                v = Long.MAX_VALUE;
                break;
            default:
                v = TestUtil.nextLong(random(), -10, 10);
                break;
        }
        values[i] = v;
        if (v == 0 && random().nextBoolean()) {
            // missing
            iw.addDocument(new Document());
            missing.add(i);
        } else {
            field.setLongValue(v);
            iw.addDocument(doc);
        }
    }
    iw.forceMerge(1);
    final DirectoryReader reader = iw.getReader();
    final NumericDocValues longs = FieldCache.DEFAULT.getNumerics(getOnlyLeafReader(reader), "f", FieldCache.LEGACY_LONG_PARSER);
    for (int i = 0; i < values.length; ++i) {
        if (missing.contains(i) == false) {
            assertEquals(i, longs.nextDoc());
            assertEquals(values[i], longs.longValue());
        }
    }
    assertEquals(NO_MORE_DOCS, longs.nextDoc());
    reader.close();
    iw.close();
    dir.close();
}
Also used : NumericDocValues(org.apache.lucene.index.NumericDocValues) DirectoryReader(org.apache.lucene.index.DirectoryReader) Document(org.apache.lucene.document.Document) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) LegacyLongField(org.apache.solr.legacy.LegacyLongField) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) HashSet(java.util.HashSet)

Example 10 with LegacyLongField

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

the class TestFieldCacheSort method testLegacyLongMissingLast.

/** Tests sorting on type legacy long, specifying the missing value should be treated as Long.MAX_VALUE */
public void testLegacyLongMissingLast() throws IOException {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyLongField("value", -1, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyLongField("value", 4, Field.Store.YES));
    writer.addDocument(doc);
    IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_LONG));
    writer.close();
    IndexSearcher searcher = newSearcher(ir);
    SortField sortField = new SortField("value", SortField.Type.LONG);
    sortField.setMissingValue(Long.MAX_VALUE);
    Sort sort = new Sort(sortField);
    TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
    assertEquals(3, td.totalHits);
    // null is treated as Long.MAX_VALUE
    assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value"));
    assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value"));
    assertNull(searcher.doc(td.scoreDocs[2].doc).get("value"));
    TestUtil.checkReader(ir);
    ir.close();
    dir.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) LegacyLongField(org.apache.solr.legacy.LegacyLongField) 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

LegacyLongField (org.apache.solr.legacy.LegacyLongField)12 Document (org.apache.lucene.document.Document)11 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)9 Directory (org.apache.lucene.store.Directory)9 IndexReader (org.apache.lucene.index.IndexReader)6 DirectoryReader (org.apache.lucene.index.DirectoryReader)4 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 Sort (org.apache.lucene.search.Sort)4 SortField (org.apache.lucene.search.SortField)4 TopDocs (org.apache.lucene.search.TopDocs)4 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)3 IndexWriter (org.apache.lucene.index.IndexWriter)3 LeafReader (org.apache.lucene.index.LeafReader)3 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)3 BytesRef (org.apache.lucene.util.BytesRef)3 LegacyDoubleField (org.apache.solr.legacy.LegacyDoubleField)2 LegacyFieldType (org.apache.solr.legacy.LegacyFieldType)2 LegacyFloatField (org.apache.solr.legacy.LegacyFloatField)2 LegacyIntField (org.apache.solr.legacy.LegacyIntField)2