本文整理了Java中org.apache.lucene.search.Query.rewrite
方法的一些代码示例,展示了Query.rewrite
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.rewrite
方法的具体详情如下:
包路径:org.apache.lucene.search.Query
类名称:Query
方法名:rewrite
[英]Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
[中]专家:调用以将查询重新写入原始查询。例如,PrefixQuery将被重写为包含TermQuerys的布尔查询。
代码示例来源:origin: org.apache.lucene/lucene-core
/** Expert: called to re-write queries into primitive queries.
* @throws BooleanQuery.TooManyClauses If a query would exceed
* {@link BooleanQuery#getMaxClauseCount()} clauses.
*/
public Query rewrite(Query original) throws IOException {
Query query = original;
for (Query rewrittenQuery = query.rewrite(reader); rewrittenQuery != query;
rewrittenQuery = query.rewrite(reader)) {
query = rewrittenQuery;
}
return query;
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query indexRewrite = indexQuery.rewrite(reader);
Query dvRewrite = dvQuery.rewrite(reader);
if (indexQuery != indexRewrite || dvQuery != dvRewrite) {
return new IndexOrDocValuesQuery(indexRewrite, dvRewrite);
}
return this;
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
if (lowerValue == null && upperValue == null) {
return new DocValuesFieldExistsQuery(field);
}
return super.rewrite(reader);
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
if (lowerValue == Long.MIN_VALUE && upperValue == Long.MAX_VALUE) {
return new DocValuesFieldExistsQuery(field);
}
return super.rewrite(reader);
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query rewritten = query.rewrite(reader);
if (rewritten != query) {
return new ConstantScoreQuery(rewritten);
}
if (rewritten.getClass() == ConstantScoreQuery.class) {
return rewritten;
}
if (rewritten.getClass() == BoostQuery.class) {
return new ConstantScoreQuery(((BoostQuery) rewritten).getQuery());
}
return super.rewrite(reader);
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
FeatureFunction rewritten = function.rewrite(reader);
if (function != rewritten) {
return new FeatureQuery(fieldName, featureName, rewritten);
}
return super.rewrite(reader);
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
if (terms.length == 0) {
return new MatchNoDocsQuery("empty PhraseQuery");
} else if (terms.length == 1) {
return new TermQuery(terms[0]);
} else if (positions[0] != 0) {
int[] newPositions = new int[positions.length];
for (int i = 0; i < positions.length; ++i) {
newPositions[i] = positions[i] - positions[0];
}
return new PhraseQuery(slop, terms, newPositions);
} else {
return super.rewrite(reader);
}
}
代码示例来源:origin: oracle/opengrok
rewrittenQuery = query.rewrite(getIndexReader());
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
final Query rewritten = query.rewrite(reader);
if (boost == 1f) {
return rewritten;
}
if (rewritten.getClass() == BoostQuery.class) {
BoostQuery in = (BoostQuery) rewritten;
return new BoostQuery(in.query, boost * in.boost);
}
if (boost == 0f && rewritten.getClass() != ConstantScoreQuery.class) {
// so that we pass needScores=false
return new BoostQuery(new ConstantScoreQuery(rewritten), 0f);
}
if (query != rewritten) {
return new BoostQuery(rewritten, boost);
}
return super.rewrite(reader);
}
代码示例来源:origin: org.apache.lucene/lucene-core
/** Optimize our representation and our subqueries representations
* @param reader the IndexReader we query
* @return an optimized copy of us (which may not be a copy if there is nothing to optimize) */
@Override
public Query rewrite(IndexReader reader) throws IOException {
if (disjuncts.length == 1) {
return disjuncts[0];
}
if (tieBreakerMultiplier == 1.0f) {
BooleanQuery.Builder builder = new BooleanQuery.Builder();
for (Query sub : disjuncts) {
builder.add(sub, BooleanClause.Occur.SHOULD);
}
return builder.build();
}
boolean actuallyRewritten = false;
List<Query> rewrittenDisjuncts = new ArrayList<>();
for (Query sub : disjuncts) {
Query rewrittenSub = sub.rewrite(reader);
actuallyRewritten |= rewrittenSub != sub;
rewrittenDisjuncts.add(rewrittenSub);
}
if (actuallyRewritten) {
return new DisjunctionMaxQuery(rewrittenDisjuncts, tieBreakerMultiplier);
}
return super.rewrite(reader);
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
if (termArrays.length == 0) {
return new MatchNoDocsQuery("empty MultiPhraseQuery");
} else if (termArrays.length == 1) { // optimize one-term case
Term[] terms = termArrays[0];
BooleanQuery.Builder builder = new BooleanQuery.Builder();
for (Term term : terms) {
builder.add(new TermQuery(term), BooleanClause.Occur.SHOULD);
}
return builder.build();
} else {
return super.rewrite(reader);
}
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
final int threshold = Math.min(BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD, BooleanQuery.getMaxClauseCount());
if (termData.size() <= threshold) {
BooleanQuery.Builder bq = new BooleanQuery.Builder();
TermIterator iterator = termData.iterator();
for (BytesRef term = iterator.next(); term != null; term = iterator.next()) {
bq.add(new TermQuery(new Term(iterator.field(), BytesRef.deepCopyOf(term))), Occur.SHOULD);
}
return new ConstantScoreQuery(bq.build());
}
return super.rewrite(reader);
}
代码示例来源:origin: org.apache.lucene/lucene-core
for (BooleanClause clause : this) {
Query query = clause.getQuery();
Query rewritten = query.rewrite(reader);
if (rewritten != query) {
actuallyRewritten = true;
return super.rewrite(reader);
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
protected ScoreFunction rewrite(IndexReader reader) throws IOException {
Query newFilter = filter.rewrite(reader);
if (newFilter == filter) {
return this;
}
return new FilterScoreFunction(newFilter, function);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query rewritten = super.rewrite(reader);
if (rewritten != this) {
return rewritten;
}
Query newQ = subQuery.rewrite(reader);
ScoreFunction[] newFunctions = new ScoreFunction[functions.length];
boolean needsRewrite = (newQ != subQuery);
for (int i = 0; i < functions.length; i++) {
newFunctions[i] = functions[i].rewrite(reader);
needsRewrite |= (newFunctions[i] != functions[i]);
}
if (needsRewrite) {
return new FunctionScoreQuery(newQ, scoreMode, newFunctions, combineFunction, minScore, maxBoost);
}
return this;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query innerRewrite = query.rewrite(reader);
if (innerRewrite != query) {
// Right now ToParentBlockJoinQuery always rewrites to a ToParentBlockJoinQuery
// so the else block will never be used. It is useful in the case that
// ToParentBlockJoinQuery one day starts to rewrite to a different query, eg.
// a MatchNoDocsQuery if it realizes that it cannot match any docs and rewrites
// to a MatchNoDocsQuery. In that case it would be fine to lose information
// about the nested path.
if (innerRewrite instanceof ToParentBlockJoinQuery) {
return new ESToParentBlockJoinQuery((ToParentBlockJoinQuery) innerRewrite, path);
} else {
return innerRewrite;
}
}
return super.rewrite(reader);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query rewritten = super.rewrite(reader);
if (rewritten != this) {
return rewritten;
}
boolean hasPayloads = false;
for (LeafReaderContext context : reader.leaves()) {
final Terms terms = context.reader().terms(term.field());
if (terms != null) {
if (terms.hasPayloads()) {
hasPayloads = true;
break;
}
}
}
// if the terms does not exist we could return a MatchNoDocsQuery but this would break the unified highlighter
// which rewrites query with an empty reader.
if (hasPayloads == false) {
return new TermQuery(term);
}
return this;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query rewritten = super.rewrite(reader);
if (rewritten != this) {
return rewritten;
}
IndexReaderContext context = reader.getContext();
TermContext[] ctx = new TermContext[terms.length];
int[] docFreqs = new int[ctx.length];
for (int i = 0; i < terms.length; i++) {
ctx[i] = TermContext.build(context, terms[i]);
docFreqs[i] = ctx[i].docFreq();
}
final int maxDoc = reader.maxDoc();
blend(ctx, maxDoc, reader);
return topLevelQuery(terms, ctx, docFreqs, maxDoc);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query rewritten = super.rewrite(reader);
if (rewritten != this) {
return rewritten;
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query rewritten = super.rewrite(reader);
if (rewritten != this) {
return rewritten;
}
XMoreLikeThis mlt = new XMoreLikeThis(reader, similarity == null ? new ClassicSimilarity() : similarity);
mlt.setFieldNames(moreLikeFields);
mlt.setAnalyzer(analyzer);
mlt.setMinTermFreq(minTermFrequency);
mlt.setMinDocFreq(minDocFreq);
mlt.setMaxDocFreq(maxDocFreq);
mlt.setMaxQueryTerms(maxQueryTerms);
mlt.setMinWordLen(minWordLen);
mlt.setMaxWordLen(maxWordLen);
mlt.setStopWords(stopWords);
mlt.setBoost(boostTerms);
mlt.setBoostFactor(boostTermsFactor);
if (this.unlikeText != null || this.unlikeFields != null) {
handleUnlike(mlt, this.unlikeText, this.unlikeFields);
}
return createQuery(mlt);
}
内容来源于网络,如有侵权,请联系作者删除!