Search in sources :

Example 16 with Fieldable

use of org.apache.lucene.document.Fieldable in project Solbase by Photobucket.

the class DocumentLoader method mergeOldAndNew.

private Document mergeOldAndNew(Document oldDoc, Document newDoc) {
    SolrInputDocument newInputDoc = new SolrInputDocument();
    @SuppressWarnings("unchecked") List<Fieldable> newFields = newDoc.getFields();
    for (Fieldable field : newFields) {
        String fieldName = field.name();
        String fieldValue = field.stringValue();
        newInputDoc.addField(fieldName, fieldValue);
        oldDoc.removeField(fieldName);
    }
    @SuppressWarnings("unchecked") List<Fieldable> oldFields = oldDoc.getFields();
    for (Fieldable field : oldFields) {
        String fieldName = field.name();
        String fieldValue = field.stringValue();
        newInputDoc.addField(fieldName, fieldValue);
    }
    Document mergedDoc = DocumentBuilder.toDocument(newInputDoc, schema);
    return mergedDoc;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) Fieldable(org.apache.lucene.document.Fieldable) Document(org.apache.lucene.document.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument)

Example 17 with Fieldable

use of org.apache.lucene.document.Fieldable 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)

Example 18 with Fieldable

use of org.apache.lucene.document.Fieldable in project graphdb by neo4j-attic.

the class IndexType method clearDocument.

private void clearDocument(Document document) {
    Set<String> names = new HashSet<String>();
    for (Fieldable field : document.getFields()) {
        names.add(field.name());
    }
    names.remove(LuceneIndex.KEY_DOC_ID);
    for (String name : names) {
        document.removeFields(name);
    }
}
Also used : Fieldable(org.apache.lucene.document.Fieldable) HashSet(java.util.HashSet)

Aggregations

Fieldable (org.apache.lucene.document.Fieldable)18 Document (org.apache.lucene.document.Document)10 Field (org.apache.lucene.document.Field)6 Term (org.apache.lucene.index.Term)4 TokenStream (org.apache.lucene.analysis.TokenStream)3 TermAttribute (org.apache.lucene.analysis.tokenattributes.TermAttribute)3 NumericField (org.apache.lucene.document.NumericField)3 TopDocs (org.apache.lucene.search.TopDocs)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)2 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)2 PropertyState (org.apache.jackrabbit.core.state.PropertyState)2 PayloadAttribute (org.apache.lucene.analysis.tokenattributes.PayloadAttribute)2 EmbeddedSortField (org.apache.lucene.document.EmbeddedSortField)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 Query (org.apache.lucene.search.Query)2