Search in sources :

Example 1 with NumericField

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;
}
Also used : Field(org.apache.lucene.document.Field) NumericField(org.apache.lucene.document.NumericField) NumericField(org.apache.lucene.document.NumericField) StringReader(java.io.StringReader) Document(org.apache.lucene.document.Document)

Example 2 with NumericField

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

Example 3 with NumericField

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);
    }
}
Also used : CreateTxn(org.apache.zookeeper.txn.CreateTxn) NumericField(org.apache.lucene.document.NumericField) SetDataTxn(org.apache.zookeeper.txn.SetDataTxn) Document(org.apache.lucene.document.Document) DeleteTxn(org.apache.zookeeper.txn.DeleteTxn)

Example 4 with NumericField

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()));
}
Also used : Fieldable(org.apache.lucene.document.Fieldable) NumericField(org.apache.lucene.document.NumericField) Document(org.apache.lucene.document.Document) Date(java.util.Date)

Example 5 with NumericField

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

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