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()));
}
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;
}
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);
}
}
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();
}
}
Aggregations