Search in sources :

Example 6 with TermEnum

use of gate.creole.annic.apache.lucene.index.TermEnum in project gate-core by GateNLP.

the class FieldCacheImpl method getFloats.

// inherit javadocs
@Override
public float[] getFloats(IndexReader reader, String field) throws IOException {
    field = field.intern();
    Object ret = lookup(reader, field, SortField.FLOAT);
    if (ret == null) {
        final float[] retArray = new float[reader.maxDoc()];
        if (retArray.length > 0) {
            TermDocs termDocs = reader.termDocs();
            TermEnum termEnum = reader.terms(new Term(field, ""));
            try {
                if (termEnum.term() == null) {
                    throw new RuntimeException("no terms in field " + field);
                }
                do {
                    Term term = termEnum.term();
                    if (term.field() != field)
                        break;
                    float termval = Float.parseFloat(term.text());
                    termDocs.seek(termEnum);
                    while (termDocs.next()) {
                        retArray[termDocs.doc()] = termval;
                    }
                } while (termEnum.next());
            } finally {
                termDocs.close();
                termEnum.close();
            }
        }
        store(reader, field, SortField.FLOAT, retArray);
        return retArray;
    }
    return (float[]) ret;
}
Also used : TermDocs(gate.creole.annic.apache.lucene.index.TermDocs) Term(gate.creole.annic.apache.lucene.index.Term) TermEnum(gate.creole.annic.apache.lucene.index.TermEnum)

Example 7 with TermEnum

use of gate.creole.annic.apache.lucene.index.TermEnum in project gate-core by GateNLP.

the class FieldCacheImpl method getStrings.

// inherit javadocs
@Override
public String[] getStrings(IndexReader reader, String field) throws IOException {
    field = field.intern();
    Object ret = lookup(reader, field, SortField.STRING);
    if (ret == null) {
        final String[] retArray = new String[reader.maxDoc()];
        if (retArray.length > 0) {
            TermDocs termDocs = reader.termDocs();
            TermEnum termEnum = reader.terms(new Term(field, ""));
            try {
                if (termEnum.term() == null) {
                    throw new RuntimeException("no terms in field " + field);
                }
                do {
                    Term term = termEnum.term();
                    if (term.field() != field)
                        break;
                    String termval = term.text();
                    termDocs.seek(termEnum);
                    while (termDocs.next()) {
                        retArray[termDocs.doc()] = termval;
                    }
                } while (termEnum.next());
            } finally {
                termDocs.close();
                termEnum.close();
            }
        }
        store(reader, field, SortField.STRING, retArray);
        return retArray;
    }
    return (String[]) ret;
}
Also used : TermDocs(gate.creole.annic.apache.lucene.index.TermDocs) Term(gate.creole.annic.apache.lucene.index.Term) TermEnum(gate.creole.annic.apache.lucene.index.TermEnum)

Aggregations

Term (gate.creole.annic.apache.lucene.index.Term)7 TermEnum (gate.creole.annic.apache.lucene.index.TermEnum)7 TermDocs (gate.creole.annic.apache.lucene.index.TermDocs)5 SearchException (gate.creole.annic.SearchException)1 Document (gate.creole.annic.apache.lucene.document.Document)1 IndexReader (gate.creole.annic.apache.lucene.index.IndexReader)1 BooleanQuery (gate.creole.annic.apache.lucene.search.BooleanQuery)1 Hits (gate.creole.annic.apache.lucene.search.Hits)1 IndexSearcher (gate.creole.annic.apache.lucene.search.IndexSearcher)1 TermQuery (gate.creole.annic.apache.lucene.search.TermQuery)1 File (java.io.File)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1