private NodeScorer makeCountingSumScorerNoReq() throws IOException { // No required scorers NodeScorer requiredCountingSumScorer; if (optionalScorers.size() > 1) requiredCountingSumScorer = this.countingDisjunctionSumScorer(optionalScorers); else if (optionalScorers.size() == 1) requiredCountingSumScorer = new SingleMatchScorer(optionalScorers.get(0)); else { requiredCountingSumScorer = this.countingConjunctionSumScorer(optionalScorers); } return this.addProhibitedScorers(requiredCountingSumScorer); }
/** * Returns the scorer to be used for match counting and score summing. Uses * requiredScorers, optionalScorers and prohibitedScorers. */ private NodeScorer makeCountingSumScorer() throws IOException { // each scorer counted as a single matcher return (requiredScorers.size() == 0) ? this.makeCountingSumScorerNoReq() : this.makeCountingSumScorerSomeReq(); }
private NodeScorer countingDisjunctionSumScorer(final List<NodeScorer> scorers) throws IOException { return new NodeDisjunctionScorer(this.getWeight(), scorers) { @Override public float scoreInNode() throws IOException { final float nodeScore = super.scoreInNode(); coordinator.nrMatchers += super.nrMatchers(); return nodeScore; } }; }
@Override public Scorer scorer(final AtomicReaderContext context, final boolean scoreDocsInOrder, final boolean topScorer, final Bits acceptDocs) throws IOException { final List<NodeScorer> required = new ArrayList<NodeScorer>(); final List<NodeScorer> prohibited = new ArrayList<NodeScorer>(); final List<NodeScorer> optional = new ArrayList<NodeScorer>(); final Iterator<NodeBooleanClause> cIter = clauses.iterator(); for (final Weight w : weights) { final NodeBooleanClause c = cIter.next(); final NodeScorer subScorer = (NodeScorer) w.scorer(context, true, false, acceptDocs); if (subScorer == null) { if (c.isRequired()) { return null; } } else if (c.isRequired()) { required.add(subScorer); } else if (c.isProhibited()) { prohibited.add(subScorer); } else { optional.add(subScorer); } } if (required.size() == 0 && optional.size() == 0) { // no required and optional clauses. return null; } return new NodeBooleanScorer(this, required, prohibited, optional); }
/** * Creates a {@link NodeBooleanScorer} with the given lists of * required, prohibited and optional scorers. In no required scorers are added, * at least one of the optional scorers will have to match during the search. * * @param weight * The BooleanWeight to be used. * @param required * the list of required scorers. * @param prohibited * the list of prohibited scorers. * @param optional * the list of optional scorers. */ public NodeBooleanScorer(final AbstractNodeBooleanWeight weight, final List<NodeScorer> required, final List<NodeScorer> prohibited, final List<NodeScorer> optional) throws IOException { super(weight); coordinator = new Coordinator(); optionalScorers = optional; requiredScorers = required; prohibitedScorers = prohibited; coordinator.init(); countingSumScorer = this.makeCountingSumScorer(); }
private NodeScorer makeCountingSumScorerSomeReq() throws IOException { // At least one required scorer. final NodeScorer requiredCountingSumScorer = (requiredScorers.size() == 1) ? new SingleMatchScorer(requiredScorers.get(0)) : this.countingConjunctionSumScorer(requiredScorers); if (optionalScorers.isEmpty()) { return this.addProhibitedScorers(requiredCountingSumScorer); } else { return new NodeReqOptScorer( this.addProhibitedScorers(requiredCountingSumScorer), optionalScorers.size() == 1 ? new SingleMatchScorer(optionalScorers.get(0)) // require 1 in combined, optional scorer. : this.countingDisjunctionSumScorer(optionalScorers)); } }