Search in sources :

Example 6 with Fieldable

use of org.apache.lucene.document.Fieldable in project zm-mailbox by Zimbra.

the class LuceneViewer method dumpDocument.

private void dumpDocument(int docNum, Document doc) throws IOException {
    outputLn();
    outputLn("Document " + docNum);
    if (doc == null) {
        outputLn("    deleted");
        return;
    }
    // note: only stored fields will be returned
    for (Fieldable field : doc.getFields()) {
        String fieldName = field.name();
        boolean isDate = "l.date".equals(fieldName);
        outputLn("    Field [" + fieldName + "]: " + field.toString());
        String[] values = doc.getValues(fieldName);
        if (values != null) {
            int i = 0;
            for (String value : values) {
                output("         " + "(" + i++ + ") " + value);
                if (isDate) {
                    try {
                        Date date = DateTools.stringToDate(value);
                        output(" (" + date.toString() + " (" + date.getTime() + "))");
                    } catch (java.text.ParseException e) {
                        assert false;
                    }
                }
                outputLn();
            }
        }
    }
}
Also used : Fieldable(org.apache.lucene.document.Fieldable) Date(java.util.Date)

Example 7 with Fieldable

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

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

the class LuceneBatchInserterIndex method removeFromCache.

private void removeFromCache(long entityId) throws IOException, CorruptIndexException {
    IndexSearcher searcher = searcher();
    Query query = type.idTermQuery(entityId);
    TopDocs docs = searcher.search(query, 1);
    if (docs.totalHits > 0) {
        Document document = searcher.doc(docs.scoreDocs[0].doc);
        for (Fieldable field : document.getFields()) {
            String key = field.name();
            Object value = field.stringValue();
            removeFromCache(entityId, key, value);
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) Query(org.apache.lucene.search.Query) Fieldable(org.apache.lucene.document.Fieldable) Document(org.apache.lucene.document.Document)

Example 9 with Fieldable

use of org.apache.lucene.document.Fieldable in project polymap4-core by Polymap4.

the class LuceneRecordState method remove.

public LuceneRecordState remove(String key) {
    checkCopyOnWrite();
    doc.removeField(key);
    // remove additional fields generated by ValueCoder
    for (Iterator<Fieldable> it = doc.getFields().iterator(); it.hasNext(); ) {
        Fieldable field = it.next();
        if (field.name().startsWith(key)) {
            it.remove();
        }
    }
    return this;
}
Also used : Fieldable(org.apache.lucene.document.Fieldable)

Example 10 with Fieldable

use of org.apache.lucene.document.Fieldable in project eol-globi-data by jhpoelen.

the class TaxonLookupServiceImpl method findTaxon.

private Taxon[] findTaxon(String fieldName1, String fieldValue) throws IOException {
    Taxon[] terms = new TaxonImpl[0];
    if (StringUtils.isNotBlank(fieldValue) && indexSearcher != null) {
        PhraseQuery query = new PhraseQuery();
        query.add(new Term(fieldName1, fieldValue));
        TopDocs docs = indexSearcher.search(query, getMaxHits());
        if (docs.totalHits > 0) {
            int maxResults = Math.min(docs.totalHits, getMaxHits());
            terms = new TaxonImpl[maxResults];
            for (int i = 0; i < maxResults; i++) {
                ScoreDoc scoreDoc = docs.scoreDocs[i];
                Document foundDoc = indexSearcher.doc(scoreDoc.doc);
                Taxon term = new TaxonImpl();
                Fieldable idField = foundDoc.getFieldable(FIELD_ID);
                if (idField != null) {
                    term.setExternalId(idField.stringValue());
                }
                Fieldable rankPathField = foundDoc.getFieldable(FIELD_RANK_PATH);
                if (rankPathField != null) {
                    term.setPath(rankPathField.stringValue());
                }
                Fieldable rankPathIdsField = foundDoc.getFieldable(FIELD_RANK_PATH_IDS);
                if (rankPathIdsField != null) {
                    term.setPathIds(rankPathIdsField.stringValue());
                }
                Fieldable rankPathNamesField = foundDoc.getFieldable(FIELD_RANK_PATH_NAMES);
                if (rankPathNamesField != null) {
                    term.setPathNames(rankPathNamesField.stringValue());
                }
                Fieldable commonNamesFields = foundDoc.getFieldable(FIELD_COMMON_NAMES);
                if (commonNamesFields != null) {
                    term.setCommonNames(commonNamesFields.stringValue());
                }
                Fieldable fieldName = foundDoc.getFieldable(FIELD_RECOMMENDED_NAME);
                if (fieldName != null) {
                    term.setName(fieldName.stringValue());
                }
                terms[i] = term;
            }
        }
    }
    return terms;
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) PhraseQuery(org.apache.lucene.search.PhraseQuery) Fieldable(org.apache.lucene.document.Fieldable) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc)

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