Search in sources :

Example 11 with LegacyLongField

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

the class TestUninvertingReader method testSortedSetDouble.

public void testSortedSetDouble() throws IOException {
    Directory dir = newDirectory();
    IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null));
    Document doc = new Document();
    doc.add(new LegacyLongField("foo", Double.doubleToRawLongBits(5d), Field.Store.NO));
    iw.addDocument(doc);
    doc = new Document();
    doc.add(new LegacyLongField("foo", Double.doubleToRawLongBits(5d), Field.Store.NO));
    doc.add(new LegacyLongField("foo", Double.doubleToRawLongBits(-3d), Field.Store.NO));
    iw.addDocument(doc);
    iw.forceMerge(1);
    iw.close();
    DirectoryReader ir = UninvertingReader.wrap(DirectoryReader.open(dir), Collections.singletonMap("foo", Type.SORTED_SET_DOUBLE));
    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(Double.doubleToRawLongBits(-3d), LegacyNumericUtils.prefixCodedToLong(value));
    value = v.lookupOrd(1);
    assertEquals(Double.doubleToRawLongBits(5d), 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 12 with LegacyLongField

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

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