Search in sources :

Example 1 with Term

use of org.apache.lucene.index.Term in project elasticsearch by elastic.

the class ShardGetService method innerGet.

private GetResult innerGet(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext) {
    fetchSourceContext = normalizeFetchSourceContent(fetchSourceContext, gFields);
    Engine.GetResult get = null;
    if (type == null || type.equals("_all")) {
        for (String typeX : mapperService.types()) {
            get = indexShard.get(new Engine.Get(realtime, new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(typeX, id))).version(version).versionType(versionType));
            if (get.exists()) {
                type = typeX;
                break;
            } else {
                get.release();
            }
        }
        if (get == null) {
            return new GetResult(shardId.getIndexName(), type, id, -1, false, null, null);
        }
        if (!get.exists()) {
            // no need to release here as well..., we release in the for loop for non exists
            return new GetResult(shardId.getIndexName(), type, id, -1, false, null, null);
        }
    } else {
        get = indexShard.get(new Engine.Get(realtime, new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(type, id))).version(version).versionType(versionType));
        if (!get.exists()) {
            get.release();
            return new GetResult(shardId.getIndexName(), type, id, -1, false, null, null);
        }
    }
    try {
        // break between having loaded it from translog (so we only have _source), and having a document to load
        return innerGetLoadFromStoredFields(type, id, gFields, fetchSourceContext, get, mapperService);
    } finally {
        get.release();
    }
}
Also used : Term(org.apache.lucene.index.Term) Engine(org.elasticsearch.index.engine.Engine)

Example 2 with Term

use of org.apache.lucene.index.Term in project elasticsearch by elastic.

the class CommonTermsQueryBuilder method parseQueryString.

private static Query parseQueryString(ExtendedCommonTermsQuery query, Object queryString, String field, Analyzer analyzer, String lowFreqMinimumShouldMatch, String highFreqMinimumShouldMatch) throws IOException {
    // Logic similar to QueryParser#getFieldQuery
    try (TokenStream source = analyzer.tokenStream(field, queryString.toString())) {
        source.reset();
        CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class);
        BytesRefBuilder builder = new BytesRefBuilder();
        while (source.incrementToken()) {
            // UTF-8
            builder.copyChars(termAtt);
            query.add(new Term(field, builder.toBytesRef()));
        }
    }
    query.setLowFreqMinimumNumberShouldMatch(lowFreqMinimumShouldMatch);
    query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch);
    return query;
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) CharTermAttribute(org.apache.lucene.analysis.tokenattributes.CharTermAttribute) Term(org.apache.lucene.index.Term)

Example 3 with Term

use of org.apache.lucene.index.Term in project elasticsearch by elastic.

the class StringFieldType method regexpQuery.

@Override
public final Query regexpQuery(String value, int flags, int maxDeterminizedStates, MultiTermQuery.RewriteMethod method, QueryShardContext context) {
    failIfNotIndexed();
    RegexpQuery query = new RegexpQuery(new Term(name(), indexedValueForSearch(value)), flags, maxDeterminizedStates);
    if (method != null) {
        query.setRewriteMethod(method);
    }
    return query;
}
Also used : Term(org.apache.lucene.index.Term) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 4 with Term

use of org.apache.lucene.index.Term in project elasticsearch by elastic.

the class AggregatedDfs method writeTo.

@Override
public void writeTo(final StreamOutput out) throws IOException {
    out.writeVInt(termStatistics.size());
    for (ObjectObjectCursor<Term, TermStatistics> c : termStatistics()) {
        Term term = c.key;
        out.writeString(term.field());
        out.writeBytesRef(term.bytes());
        TermStatistics stats = c.value;
        out.writeBytesRef(stats.term());
        out.writeVLong(stats.docFreq());
        out.writeVLong(DfsSearchResult.addOne(stats.totalTermFreq()));
    }
    DfsSearchResult.writeFieldStats(out, fieldStatistics);
    out.writeVLong(maxDoc);
}
Also used : Term(org.apache.lucene.index.Term) TermStatistics(org.apache.lucene.search.TermStatistics)

Example 5 with Term

use of org.apache.lucene.index.Term in project elasticsearch by elastic.

the class DfsSearchResult method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    id = in.readLong();
    int termsSize = in.readVInt();
    if (termsSize == 0) {
        terms = EMPTY_TERMS;
    } else {
        terms = new Term[termsSize];
        for (int i = 0; i < terms.length; i++) {
            terms[i] = new Term(in.readString(), in.readBytesRef());
        }
    }
    this.termStatistics = readTermStats(in, terms);
    readFieldStats(in, fieldStatistics);
    maxDoc = in.readVInt();
}
Also used : Term(org.apache.lucene.index.Term)

Aggregations

Term (org.apache.lucene.index.Term)1892 TermQuery (org.apache.lucene.search.TermQuery)777 Document (org.apache.lucene.document.Document)508 BooleanQuery (org.apache.lucene.search.BooleanQuery)472 Query (org.apache.lucene.search.Query)402 IndexReader (org.apache.lucene.index.IndexReader)351 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)349 Directory (org.apache.lucene.store.Directory)348 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)333 Test (org.junit.Test)302 IndexSearcher (org.apache.lucene.search.IndexSearcher)293 ArrayList (java.util.ArrayList)235 TopDocs (org.apache.lucene.search.TopDocs)214 PhraseQuery (org.apache.lucene.search.PhraseQuery)205 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)192 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)183 SpanQuery (org.apache.lucene.search.spans.SpanQuery)167 IndexWriter (org.apache.lucene.index.IndexWriter)165 BytesRef (org.apache.lucene.util.BytesRef)164 IOException (java.io.IOException)162