use of org.apache.lucene.document.NumericField in project querydsl by querydsl.
the class LuceneSerializerTest method createDocument.
private Document createDocument() {
Document doc = new Document();
doc.add(new Field("title", new StringReader("Jurassic Park")));
doc.add(new Field("author", new StringReader("Michael Crichton")));
doc.add(new Field("text", new StringReader("It's a UNIX system! I know this!")));
doc.add(new Field("rating", new StringReader("Good")));
doc.add(new Field("publisher", "", Store.YES, Index.ANALYZED));
doc.add(new NumericField("year", Store.YES, true).setIntValue(1990));
doc.add(new NumericField("gross", Store.YES, true).setDoubleValue(900.00));
doc.add(new NumericField("longField", Store.YES, true).setLongValue(1));
doc.add(new NumericField("shortField", Store.YES, true).setIntValue(1));
doc.add(new NumericField("byteField", Store.YES, true).setIntValue(1));
doc.add(new NumericField("floatField", Store.YES, true).setFloatValue(1));
return doc;
}
use of org.apache.lucene.document.NumericField in project exhibitor by soabase.
the class IndexBuilder method makeDocument.
private Document makeDocument(TxnHeader header, EntryTypes type, AtomicInteger count, AtomicLong from, AtomicLong to) {
count.incrementAndGet();
if (header.getTime() < from.get()) {
from.set(header.getTime());
}
if (header.getTime() > to.get()) {
to.set(header.getTime());
}
NumericField dateField = new NumericField(FieldNames.DATE, Field.Store.YES, true);
dateField.setLongValue(header.getTime());
Document document = new Document();
document.add(new Field(FieldNames.TYPE, Integer.toString(type.getId()), Field.Store.YES, Field.Index.NOT_ANALYZED));
document.add(dateField);
return document;
}
use of org.apache.lucene.document.NumericField in project exhibitor by soabase.
the class IndexBuilder method indexRecord.
private void indexRecord(TxnHeader header, Record record, AtomicInteger count, AtomicLong from, AtomicLong to) throws IOException {
if (record instanceof CreateTxn) {
CreateTxn createTxn = (CreateTxn) record;
EntryTypes type = createTxn.getEphemeral() ? EntryTypes.CREATE_EPHEMERAL : EntryTypes.CREATE_PERSISTENT;
Document document = makeDocument(header, type, count, from, to);
addPath(document, createTxn.getPath());
addData(document, createTxn.getData());
writer.addDocument(document);
} else if (record instanceof DeleteTxn) {
DeleteTxn deleteTxn = (DeleteTxn) record;
Document document = makeDocument(header, EntryTypes.DELETE, count, from, to);
addPath(document, deleteTxn.getPath());
writer.addDocument(document);
} else if (record instanceof SetDataTxn) {
SetDataTxn setDataTxn = (SetDataTxn) record;
NumericField versionField = new NumericField(FieldNames.VERSION, Field.Store.YES, true);
versionField.setIntValue(setDataTxn.getVersion());
Document document = makeDocument(header, EntryTypes.SET_DATA, count, from, to);
addPath(document, setDataTxn.getPath());
addData(document, setDataTxn.getData());
document.add(versionField);
writer.addDocument(document);
}
}
use of org.apache.lucene.document.NumericField in project exhibitor by soabase.
the class LogSearch method toResult.
public SearchItem toResult(int documentId) throws IOException {
Document document = searcher.doc(documentId);
String type = document.getFieldable(FieldNames.TYPE).stringValue();
NumericField date = (NumericField) document.getFieldable(FieldNames.DATE);
Fieldable path = document.getFieldable(FieldNames.PATH);
NumericField version = (NumericField) document.getFieldable(FieldNames.VERSION);
return new SearchItem(Integer.parseInt(type), path.stringValue(), (version != null) ? version.getNumericValue().intValue() : -1, new Date(date.getNumericValue().longValue()));
}
use of org.apache.lucene.document.NumericField in project graphdb by neo4j-attic.
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;
}
Aggregations