Search in sources :

Example 16 with LegacyIntField

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

the class TestUninvertingReader method testSortedSetInteger.

public void testSortedSetInteger() throws IOException {
    Directory dir = newDirectory();
    IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null));
    Document doc = new Document();
    doc.add(new LegacyIntField("foo", 5, Field.Store.NO));
    iw.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyIntField("foo", 5, Field.Store.NO));
    doc.add(new LegacyIntField("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_INTEGER));
    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.prefixCodedToInt(value));
    value = v.lookupOrd(1);
    assertEquals(5, LegacyNumericUtils.prefixCodedToInt(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) Document(org.apache.lucene.document.Document) BytesRef(org.apache.lucene.util.BytesRef) Directory(org.apache.lucene.store.Directory) LegacyIntField(org.apache.solr.legacy.LegacyIntField)

Example 17 with LegacyIntField

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

the class TestUninvertingReader method testSortedSetFloat.

public void testSortedSetFloat() throws IOException {
    Directory dir = newDirectory();
    IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null));
    Document doc = new Document();
    doc.add(new LegacyIntField("foo", Float.floatToRawIntBits(5f), Field.Store.NO));
    iw.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyIntField("foo", Float.floatToRawIntBits(5f), Field.Store.NO));
    doc.add(new LegacyIntField("foo", Float.floatToRawIntBits(-3f), Field.Store.NO));
    iw.addDocument(doc);
    iw.forceMerge(1);
    iw.close();
    DirectoryReader ir = UninvertingReader.wrap(DirectoryReader.open(dir), Collections.singletonMap("foo", Type.SORTED_SET_FLOAT));
    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(Float.floatToRawIntBits(-3f), LegacyNumericUtils.prefixCodedToInt(value));
    value = v.lookupOrd(1);
    assertEquals(Float.floatToRawIntBits(5f), LegacyNumericUtils.prefixCodedToInt(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) Document(org.apache.lucene.document.Document) BytesRef(org.apache.lucene.util.BytesRef) Directory(org.apache.lucene.store.Directory) LegacyIntField(org.apache.solr.legacy.LegacyIntField)

Example 18 with LegacyIntField

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

the class TestFieldCacheSort method testLegacyIntMissingLast.

/** Tests sorting on type legacy int, specifying the missing value should be treated as Integer.MAX_VALUE */
public void testLegacyIntMissingLast() throws IOException {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyIntField("value", -1, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyIntField("value", 4, Field.Store.YES));
    writer.addDocument(doc);
    IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_INTEGER));
    writer.close();
    IndexSearcher searcher = newSearcher(ir);
    SortField sortField = new SortField("value", SortField.Type.INT);
    sortField.setMissingValue(Integer.MAX_VALUE);
    Sort sort = new Sort(sortField);
    TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
    assertEquals(3, td.totalHits);
    // null is treated as a Integer.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) 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) LegacyIntField(org.apache.solr.legacy.LegacyIntField)

Example 19 with LegacyIntField

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

the class TestFieldCacheSort method testLegacyIntReverse.

/** Tests sorting on type legacy int in reverse */
public void testLegacyIntReverse() throws IOException {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    doc.add(new LegacyIntField("value", 300000, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyIntField("value", -1, Field.Store.YES));
    writer.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyIntField("value", 4, Field.Store.YES));
    writer.addDocument(doc);
    IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_INTEGER));
    writer.close();
    IndexSearcher searcher = newSearcher(ir);
    Sort sort = new Sort(new SortField("value", SortField.Type.INT, true));
    TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
    assertEquals(3, td.totalHits);
    // reverse numeric order
    assertEquals("300000", searcher.doc(td.scoreDocs[0].doc).get("value"));
    assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value"));
    assertEquals("-1", 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) 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) LegacyIntField(org.apache.solr.legacy.LegacyIntField)

Example 20 with LegacyIntField

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

the class TrieDateFieldSource method createField.

@Override
public IndexableField createField(SchemaField field, Object value) {
    boolean indexed = field.indexed();
    boolean stored = field.stored();
    boolean docValues = field.hasDocValues();
    if (!indexed && !stored && !docValues) {
        if (log.isTraceEnabled())
            log.trace("Ignoring unindexed/unstored field: " + field);
        return null;
    }
    LegacyFieldType ft = new LegacyFieldType();
    ft.setStored(stored);
    ft.setTokenized(true);
    ft.setOmitNorms(field.omitNorms());
    ft.setIndexOptions(field.indexOptions());
    switch(type) {
        case INTEGER:
            ft.setNumericType(LegacyNumericType.INT);
            break;
        case FLOAT:
            ft.setNumericType(LegacyNumericType.FLOAT);
            break;
        case LONG:
            ft.setNumericType(LegacyNumericType.LONG);
            break;
        case DOUBLE:
            ft.setNumericType(LegacyNumericType.DOUBLE);
            break;
        case DATE:
            ft.setNumericType(LegacyNumericType.LONG);
            break;
        default:
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
    }
    ft.setNumericPrecisionStep(precisionStep);
    final org.apache.lucene.document.Field f;
    switch(type) {
        case INTEGER:
            int i = (value instanceof Number) ? ((Number) value).intValue() : Integer.parseInt(value.toString());
            f = new LegacyIntField(field.getName(), i, ft);
            break;
        case FLOAT:
            float fl = (value instanceof Number) ? ((Number) value).floatValue() : Float.parseFloat(value.toString());
            f = new LegacyFloatField(field.getName(), fl, ft);
            break;
        case LONG:
            long l = (value instanceof Number) ? ((Number) value).longValue() : Long.parseLong(value.toString());
            f = new LegacyLongField(field.getName(), l, ft);
            break;
        case DOUBLE:
            double d = (value instanceof Number) ? ((Number) value).doubleValue() : Double.parseDouble(value.toString());
            f = new LegacyDoubleField(field.getName(), d, ft);
            break;
        case DATE:
            Date date = (value instanceof Date) ? ((Date) value) : DateMathParser.parseMath(null, value.toString());
            f = new LegacyLongField(field.getName(), date.getTime(), ft);
            break;
        default:
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
    }
    return f;
}
Also used : LegacyFieldType(org.apache.solr.legacy.LegacyFieldType) LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) Date(java.util.Date) MutableValueDate(org.apache.lucene.util.mutable.MutableValueDate) LegacyLongField(org.apache.solr.legacy.LegacyLongField) LegacyFloatField(org.apache.solr.legacy.LegacyFloatField) SolrException(org.apache.solr.common.SolrException) LegacyIntField(org.apache.solr.legacy.LegacyIntField)

Aggregations

LegacyIntField (org.apache.solr.legacy.LegacyIntField)21 Document (org.apache.lucene.document.Document)18 Directory (org.apache.lucene.store.Directory)15 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)13 DirectoryReader (org.apache.lucene.index.DirectoryReader)8 IndexReader (org.apache.lucene.index.IndexReader)8 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)7 LeafReader (org.apache.lucene.index.LeafReader)7 BytesRef (org.apache.lucene.util.BytesRef)7 IndexWriter (org.apache.lucene.index.IndexWriter)6 IndexSearcher (org.apache.lucene.search.IndexSearcher)6 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 LegacyFieldType (org.apache.solr.legacy.LegacyFieldType)5 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)4 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)4 LegacyLongField (org.apache.solr.legacy.LegacyLongField)4 HashSet (java.util.HashSet)3