Search in sources :

Example 6 with LongField

use of org.apache.lucene.document.LongField in project gitblit by gitblit.

the class TicketIndexer method toDocField.

private void toDocField(Document doc, Lucene lucene, Date value) {
    if (value == null) {
        return;
    }
    doc.add(new LongField(lucene.name(), value.getTime(), Store.YES));
    doc.add(new NumericDocValuesField(lucene.name(), value.getTime()));
}
Also used : LongField(org.apache.lucene.document.LongField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField)

Example 7 with LongField

use of org.apache.lucene.document.LongField in project neo4j by neo4j.

the class DatabaseIndexIntegrationTest method createTestDocument.

private Document createTestDocument() {
    Document document = new Document();
    document.add(new TextField("text", "textValue", Field.Store.YES));
    document.add(new LongField("long", 1, Field.Store.YES));
    return document;
}
Also used : LongField(org.apache.lucene.document.LongField) TextField(org.apache.lucene.document.TextField) Document(org.apache.lucene.document.Document)

Example 8 with LongField

use of org.apache.lucene.document.LongField in project gerrit by GerritCodeReview.

the class AbstractLuceneIndex method add.

void add(Document doc, Values<V> values) {
    String name = values.getField().getName();
    FieldType<?> type = values.getField().getType();
    Store store = store(values.getField());
    if (type == FieldType.INTEGER || type == FieldType.INTEGER_RANGE) {
        for (Object value : values.getValues()) {
            doc.add(new IntField(name, (Integer) value, store));
        }
    } else if (type == FieldType.LONG) {
        for (Object value : values.getValues()) {
            doc.add(new LongField(name, (Long) value, store));
        }
    } else if (type == FieldType.TIMESTAMP) {
        for (Object value : values.getValues()) {
            doc.add(new LongField(name, ((Timestamp) value).getTime(), store));
        }
    } else if (type == FieldType.EXACT || type == FieldType.PREFIX) {
        for (Object value : values.getValues()) {
            doc.add(new StringField(name, (String) value, store));
        }
    } else if (type == FieldType.FULL_TEXT) {
        for (Object value : values.getValues()) {
            doc.add(new TextField(name, (String) value, store));
        }
    } else if (type == FieldType.STORED_ONLY) {
        for (Object value : values.getValues()) {
            doc.add(new StoredField(name, (byte[]) value));
        }
    } else {
        throw FieldType.badFieldType(type);
    }
}
Also used : LongField(org.apache.lucene.document.LongField) StoredField(org.apache.lucene.document.StoredField) StringField(org.apache.lucene.document.StringField) Store(org.apache.lucene.document.Field.Store) TextField(org.apache.lucene.document.TextField) IntField(org.apache.lucene.document.IntField) Timestamp(java.sql.Timestamp)

Example 9 with LongField

use of org.apache.lucene.document.LongField in project ignite by apache.

the class GridLuceneIndex method store.

/**
 * Stores given data in this fulltext index.
 *
 * @param k Key.
 * @param v Value.
 * @param ver Version.
 * @param expires Expiration time.
 * @throws IgniteCheckedException If failed.
 */
@SuppressWarnings("ConstantConditions")
public void store(CacheObject k, CacheObject v, GridCacheVersion ver, long expires) throws IgniteCheckedException {
    CacheObjectContext coctx = objectContext();
    Object key = k.isPlatformType() ? k.value(coctx, false) : k;
    Object val = v.isPlatformType() ? v.value(coctx, false) : v;
    Document doc = new Document();
    boolean stringsFound = false;
    if (type.valueTextIndex() || type.valueClass() == String.class) {
        doc.add(new TextField(VAL_STR_FIELD_NAME, val.toString(), Field.Store.YES));
        stringsFound = true;
    }
    for (int i = 0, last = idxdFields.length - 1; i < last; i++) {
        Object fieldVal = type.value(idxdFields[i], key, val);
        if (fieldVal != null) {
            doc.add(new TextField(idxdFields[i], fieldVal.toString(), Field.Store.YES));
            stringsFound = true;
        }
    }
    BytesRef keyByteRef = new BytesRef(k.valueBytes(coctx));
    try {
        final Term term = new Term(KEY_FIELD_NAME, keyByteRef);
        if (!stringsFound) {
            writer.deleteDocuments(term);
            // We did not find any strings to be indexed, will not store data at all.
            return;
        }
        doc.add(new StringField(KEY_FIELD_NAME, keyByteRef, Field.Store.YES));
        if (type.valueClass() != String.class)
            doc.add(new StoredField(VAL_FIELD_NAME, v.valueBytes(coctx)));
        doc.add(new StoredField(VER_FIELD_NAME, ver.toString().getBytes()));
        doc.add(new LongField(EXPIRATION_TIME_FIELD_NAME, expires, Field.Store.YES));
        // Next implies remove than add atomically operation.
        writer.updateDocument(term, doc);
    } catch (IOException e) {
        throw new IgniteCheckedException(e);
    } finally {
        updateCntr.incrementAndGet();
    }
}
Also used : Term(org.apache.lucene.index.Term) IOException(java.io.IOException) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) Document(org.apache.lucene.document.Document) LongField(org.apache.lucene.document.LongField) StoredField(org.apache.lucene.document.StoredField) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

LongField (org.apache.lucene.document.LongField)9 StringField (org.apache.lucene.document.StringField)5 TextField (org.apache.lucene.document.TextField)5 Document (org.apache.lucene.document.Document)4 Field (org.apache.lucene.document.Field)4 DoubleField (org.apache.lucene.document.DoubleField)3 IntField (org.apache.lucene.document.IntField)3 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)3 Date (java.util.Date)2 FloatField (org.apache.lucene.document.FloatField)2 StoredField (org.apache.lucene.document.StoredField)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Timestamp (java.sql.Timestamp)1 ParamConverterProvider (javax.ws.rs.ext.ParamConverterProvider)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 FieldFactory.newAncestorsField (org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newAncestorsField)1 FieldFactory.newDepthField (org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newDepthField)1