private boolean equalsTo(BooleanQuery other) { return getMinimumNumberShouldMatch() == other.getMinimumNumberShouldMatch() && clauseSets.equals(other.clauseSets); }
BulkScorer optionalBulkScorer(LeafReaderContext context) throws IOException { List<BulkScorer> optional = new ArrayList<BulkScorer>(); Iterator<BooleanClause> cIter = query.iterator(); for (Weight w : weights) { BooleanClause c = cIter.next(); if (c.getOccur() != Occur.SHOULD) { continue; } BulkScorer subScorer = w.bulkScorer(context); if (subScorer != null) { optional.add(subScorer); } } if (optional.size() == 0) { return null; } if (query.getMinimumNumberShouldMatch() > optional.size()) { return null; } if (optional.size() == 1) { return optional.get(0); } return new BooleanScorer(this, optional, Math.max(1, query.getMinimumNumberShouldMatch()), needsScores); }
public String toString(String field) { StringBuilder buffer = new StringBuilder(); boolean needParens = getMinimumNumberShouldMatch() > 0; if (needParens) { buffer.append("("); if (getMinimumNumberShouldMatch()>0) { buffer.append('~'); buffer.append(getMinimumNumberShouldMatch());
@Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { int minShouldMatch = query.getMinimumNumberShouldMatch();
@Override public Matches matches(LeafReaderContext context, int doc) throws IOException { final int minShouldMatch = query.getMinimumNumberShouldMatch(); List<Matches> matches = new ArrayList<>(); int shouldMatchCount = 0;
private BooleanQuery rewriteNoScoring() { if (clauseSets.get(Occur.MUST).size() == 0) { return this; } BooleanQuery.Builder newQuery = new BooleanQuery.Builder(); newQuery.setMinimumNumberShouldMatch(getMinimumNumberShouldMatch()); for (BooleanClause clause : clauses) { if (clause.getOccur() == Occur.MUST) { newQuery.add(clause.getQuery(), Occur.FILTER); } else { newQuery.add(clause); } } return newQuery.build(); }
if (query.getMinimumNumberShouldMatch() <= 1) { && query.getMinimumNumberShouldMatch() == 0) { positiveScorer = requiredBulkScorer(context); } else {
builder.setMinimumNumberShouldMatch(getMinimumNumberShouldMatch()); boolean actuallyRewritten = false; for (BooleanClause clause : this) { if (modified) { BooleanQuery.Builder builder = new BooleanQuery.Builder(); builder.setMinimumNumberShouldMatch(getMinimumNumberShouldMatch()); for (BooleanClause clause : clauses) { if (clause.getOccur() != Occur.FILTER) { int minShouldMatch = getMinimumNumberShouldMatch(); .setMinimumNumberShouldMatch(getMinimumNumberShouldMatch()) .add(rewritten, Occur.MUST); for (Query query : clauseSets.get(Occur.SHOULD)) {
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { final int minShouldMatch = query.getMinimumNumberShouldMatch(); List<Explanation> subs = new ArrayList<>(); float sum = 0.0f;
private boolean equalsTo(BooleanQuery other) { return getMinimumNumberShouldMatch() == other.getMinimumNumberShouldMatch() && clauseSets.equals(other.clauseSets); }
/** Returns a hash code value for this object.*/ public int hashCode() { return Float.floatToIntBits(getBoost()) ^ clauses.hashCode() + getMinimumNumberShouldMatch(); }
/** Returns a hash code value for this object.*/ public int hashCode() { return Float.floatToIntBits(getBoost()) ^ clauses.hashCode() + getMinimumNumberShouldMatch(); }
/** Returns true iff <code>o</code> is equal to this. */ public boolean equals(Object o) { if (!(o instanceof BooleanQuery)) return false; BooleanQuery other = (BooleanQuery)o; return (this.getBoost() == other.getBoost()) && this.clauses.equals(other.clauses) && this.getMinimumNumberShouldMatch() == other.getMinimumNumberShouldMatch(); }
/** Returns true iff <code>o</code> is equal to this. */ public boolean equals(Object o) { if (!(o instanceof BooleanQuery)) return false; BooleanQuery other = (BooleanQuery)o; return (this.getBoost() == other.getBoost()) && this.clauses.equals(other.clauses) && this.getMinimumNumberShouldMatch() == other.getMinimumNumberShouldMatch(); }
@Override public void writeObject(final ObjectOutput output, final BooleanQuery query) throws IOException { output.writeBoolean(query.isCoordDisabled()); output.writeFloat(query.getBoost()); UnsignedNumeric.writeUnsignedInt(output, query.getMinimumNumberShouldMatch()); final List<BooleanClause> booleanClauses = query.clauses(); final int numberOfClauses = booleanClauses.size(); UnsignedNumeric.writeUnsignedInt(output, numberOfClauses); for (BooleanClause booleanClause : booleanClauses) { writeClause(output, booleanClause); } }
@Override public void writeObject(final ObjectOutput output, final BooleanQuery query) throws IOException { output.writeBoolean(query.isCoordDisabled()); output.writeFloat(query.getBoost()); UnsignedNumeric.writeUnsignedInt(output, query.getMinimumNumberShouldMatch()); final List<BooleanClause> booleanClauses = query.clauses(); final int numberOfClauses = booleanClauses.size(); UnsignedNumeric.writeUnsignedInt(output, numberOfClauses); for (BooleanClause booleanClause : booleanClauses) { writeClause(output, booleanClause); } }
private static BooleanQuery addClause(BooleanQuery bq, Query query, BooleanClause.Occur occur) { BooleanQuery.Builder newBq = new BooleanQuery.Builder(); newBq.setDisableCoord(bq.isCoordDisabled()); newBq.setMinimumNumberShouldMatch(bq.getMinimumNumberShouldMatch()); for (BooleanClause clause : bq) { newBq.add(clause); } newBq.add(query, occur); return newBq.build(); }
protected Query rewriteBoolean(BooleanQuery bq, IndexSearcher searcher) throws RewriteException, IOException { BooleanQuery.Builder newbq = new BooleanQuery.Builder(); newbq.setMinimumNumberShouldMatch(bq.getMinimumNumberShouldMatch()); for (BooleanClause clause : bq) { BooleanClause.Occur occur = clause.getOccur(); if (occur == BooleanClause.Occur.FILTER) occur = BooleanClause.Occur.MUST; // rewrite FILTER to MUST to ensure scoring newbq.add(rewrite(clause.getQuery(), searcher), occur); } return newbq.build(); }
private static BooleanQuery addClause(BooleanQuery bq, Query query, BooleanClause.Occur occur) { BooleanQuery.Builder newBq = new BooleanQuery.Builder(); newBq.setDisableCoord(bq.isCoordDisabled()); newBq.setMinimumNumberShouldMatch(bq.getMinimumNumberShouldMatch()); for (BooleanClause clause : bq) { newBq.add(clause); } newBq.add(query, occur); return newBq.build(); }
private BooleanQuery rewriteNoScoring() { BooleanQuery.Builder newQuery = new BooleanQuery.Builder(); // ignore disableCoord, which only matters for scores newQuery.setMinimumNumberShouldMatch(getMinimumNumberShouldMatch()); for (BooleanClause clause : clauses) { if (clause.getOccur() == Occur.MUST) { newQuery.add(clause.getQuery(), Occur.FILTER); } else { newQuery.add(clause); } } return newQuery.build(); }