Search in sources :

Example 6 with NumericField

use of org.apache.lucene.document.NumericField in project neo4j-mobile-android by neo4j-contrib.

the class IndexType method instantiateField.

Fieldable instantiateField(String key, Object value, Index analyzed) {
    Fieldable field = null;
    if (value instanceof Number) {
        Number number = (Number) value;
        NumericField numberField = new NumericField(key, Store.YES, true);
        if (value instanceof Long) {
            numberField.setLongValue(number.longValue());
        } else if (value instanceof Float) {
            numberField.setFloatValue(number.floatValue());
        } else if (value instanceof Double) {
            numberField.setDoubleValue(number.doubleValue());
        } else {
            numberField.setIntValue(number.intValue());
        }
        field = numberField;
    } else {
        field = new Field(key, value.toString(), Store.YES, analyzed);
    }
    return field;
}
Also used : Field(org.apache.lucene.document.Field) NumericField(org.apache.lucene.document.NumericField) Fieldable(org.apache.lucene.document.Fieldable) NumericField(org.apache.lucene.document.NumericField)

Example 7 with NumericField

use of org.apache.lucene.document.NumericField in project querydsl by querydsl.

the class LuceneQueryTest method createDocument.

private Document createDocument(final String docTitle, final String docAuthor, final String docText, final int docYear, final double docGross) {
    final Document doc = new Document();
    doc.add(new Field("title", docTitle, Store.YES, Index.ANALYZED));
    doc.add(new Field("author", docAuthor, Store.YES, Index.ANALYZED));
    doc.add(new Field("text", docText, Store.YES, Index.ANALYZED));
    doc.add(new NumericField("year", Store.YES, true).setIntValue(docYear));
    doc.add(new NumericField("gross", Store.YES, true).setDoubleValue(docGross));
    return doc;
}
Also used : Field(org.apache.lucene.document.Field) NumericField(org.apache.lucene.document.NumericField) NumericField(org.apache.lucene.document.NumericField) Document(org.apache.lucene.document.Document)

Aggregations

NumericField (org.apache.lucene.document.NumericField)7 Document (org.apache.lucene.document.Document)5 Field (org.apache.lucene.document.Field)5 Fieldable (org.apache.lucene.document.Fieldable)3 StringReader (java.io.StringReader)1 Date (java.util.Date)1 CreateTxn (org.apache.zookeeper.txn.CreateTxn)1 DeleteTxn (org.apache.zookeeper.txn.DeleteTxn)1 SetDataTxn (org.apache.zookeeper.txn.SetDataTxn)1