@Override public void extractTerms(Set<Term> terms) { int i = 0; for (BooleanClause clause : query) { if (clause.isScoring() || (needsScores == false && clause.isProhibited() == false)) { weights.get(i).extractTerms(terms); } i++; } }
BooleanWeight(BooleanQuery query, IndexSearcher searcher, boolean needsScores, float boost) throws IOException { super(query); this.query = query; this.needsScores = needsScores; this.similarity = searcher.getSimilarity(needsScores); weights = new ArrayList<>(); for (BooleanClause c : query) { Weight w = searcher.createWeight(c.getQuery(), needsScores && c.isScoring(), boost); weights.add(w); } }
private BulkScorer requiredBulkScorer(LeafReaderContext context) throws IOException { BulkScorer scorer = null; Iterator<BooleanClause> cIter = query.iterator(); for (Weight w : weights) { BooleanClause c = cIter.next(); if (c.isRequired() == false) { continue; } if (scorer != null) { // we don't have a BulkScorer for conjunctions return null; } scorer = w.bulkScorer(context); if (scorer == null) { // no matches return null; } if (c.isScoring() == false && needsScores) { scorer = disableScoring(scorer); } } return scorer; }
Explanation e = w.explain(context, doc); if (e.isMatch()) { if (c.isScoring()) { subs.add(e); sum += e.getValue();
@Override public float getValueForNormalization() throws IOException { float sum = 0.0f; int i = 0; for (BooleanClause clause : query) { // call sumOfSquaredWeights for all clauses in case of side effects float s = weights.get(i).getValueForNormalization(); // sum sub weights if (clause.isScoring()) { // only add to sum for scoring clauses sum += s; } i += 1; } return sum ; }
@Override public float getValueForNormalization() throws IOException { float sum = 0.0f; int i = 0; for (BooleanClause clause : query) { // call sumOfSquaredWeights for all clauses in case of side effects float s = weights.get(i).getValueForNormalization(); // sum sub weights if (clause.isScoring()) { // only add to sum for scoring clauses sum += s; } i += 1; } return sum ; }
@Override public void extractTerms(Set<Term> terms) { int i = 0; for (BooleanClause clause : query) { if (clause.isScoring() || (needsScores == false && clause.isProhibited() == false)) { weights.get(i).extractTerms(terms); } i++; } }
@Override public void extractTerms(Set<Term> terms) { int i = 0; for (BooleanClause clause : query) { if (clause.isScoring() || (needsScores == false && clause.isProhibited() == false)) { weights.get(i).extractTerms(terms); } i++; } }
@Override public void extractTerms(Set<Term> terms) { int i = 0; for (BooleanClause clause : query) { if (clause.isScoring() || (needsScores == false && clause.isProhibited() == false)) { weights.get(i).extractTerms(terms); } i++; } }
BooleanWeight(BooleanQuery query, IndexSearcher searcher, boolean needsScores, float boost) throws IOException { super(query); this.query = query; this.needsScores = needsScores; this.similarity = searcher.getSimilarity(needsScores); weights = new ArrayList<>(); for (BooleanClause c : query) { Weight w = searcher.createWeight(c.getQuery(), needsScores && c.isScoring(), boost); weights.add(w); } }
@SuppressFBWarnings( value = "OCP_OVERLY_CONCRETE_PARAMETER", justification = "Using a specific type is required as different behaviour are expected") protected void flattenQuery(BooleanQuery query, float pathBoost, Object sourceOverride, IndexReader reader, Callback callback) { for (BooleanClause clause : query) { // Exclude FILTER clauses with isScoring(), before lucene 5 most of // these queries were wrapped inside a FitleredQuery // but now the prefered way is to add a boolean clause with // Occur.FILTER // e.g. the _type filter with elasticsearch now uses this type of // construct. if (!clause.isProhibited() && clause.isScoring()) { flatten(clause.getQuery(), pathBoost, sourceOverride, reader, callback); } } }
private BulkScorer requiredBulkScorer(LeafReaderContext context) throws IOException { BulkScorer scorer = null; Iterator<BooleanClause> cIter = query.iterator(); for (Weight w : weights) { BooleanClause c = cIter.next(); if (c.isRequired() == false) { continue; } if (scorer != null) { // we don't have a BulkScorer for conjunctions return null; } scorer = w.bulkScorer(context); if (scorer == null) { // no matches return null; } if (c.isScoring() == false && needsScores) { scorer = disableScoring(scorer); } } return scorer; }
private BulkScorer requiredBulkScorer(LeafReaderContext context) throws IOException { BulkScorer scorer = null; Iterator<BooleanClause> cIter = query.iterator(); for (Weight w : weights) { BooleanClause c = cIter.next(); if (c.isRequired() == false) { continue; } if (scorer != null) { // we don't have a BulkScorer for conjunctions return null; } scorer = w.bulkScorer(context); if (scorer == null) { // no matches return null; } if (c.isScoring() == false) { if (needsScores) { scorer = disableScoring(scorer); } } else { assert maxCoord == 1; } } return scorer; }
private BulkScorer requiredBulkScorer(LeafReaderContext context) throws IOException { BulkScorer scorer = null; Iterator<BooleanClause> cIter = query.iterator(); for (Weight w : weights) { BooleanClause c = cIter.next(); if (c.isRequired() == false) { continue; } if (scorer != null) { // we don't have a BulkScorer for conjunctions return null; } scorer = w.bulkScorer(context); if (scorer == null) { // no matches return null; } if (c.isScoring() == false) { if (needsScores) { scorer = disableScoring(scorer); } } else { assert maxCoord == 1; } } return scorer; }
Explanation e = w.explain(context, doc); if (e.isMatch()) { if (c.isScoring()) { subs.add(e); sum += e.getValue();
Explanation e = w.explain(context, doc); if (e.isMatch()) { if (c.isScoring()) { subs.add(e); sum += e.getValue();
@Test @TestForIssue(jiraKey = "HSEARCH-2034") public void testBooleanWithoutScoring() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); //must + disable scoring Query query = monthQb .bool() .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() ) .disableScoring() .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 1 ); assertTrue( query instanceof BooleanQuery ); BooleanQuery bq = (BooleanQuery) query; BooleanClause firstBooleanClause = bq.clauses().get( 0 ); assertFalse( firstBooleanClause.isScoring() ); }
@Test @TestForIssue(jiraKey = "HSEARCH-2037") public void testBooleanWithOnlyNegationQueries() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); //must + disable scoring Query query = monthQb .bool() .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() ) .not() //expectation: exclude January .must( monthQb.keyword().onField( "mythology" ).matching( "snowboarding" ).createQuery() ) .not() //expectation: exclude February .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 3 ); assertTrue( query instanceof BooleanQuery ); BooleanQuery bq = (BooleanQuery) query; BooleanClause firstBooleanClause = bq.clauses().get( 0 ); assertFalse( firstBooleanClause.isScoring() ); }