/** * Creates a {@link com.sindicetech.siren.search.spans.BooleanSpans} with the given lists of * required, prohibited and optional spans. In no required spans are added, * at least one of the optional spans will have to match during the search. * * @param required * the list of required spans. * @param prohibited * the list of prohibited spans. * @param optional * the list of optional spans. * @param slop * the maximum allowed slop. * @param inOrder * specify if the required spans must be ordered. */ public BooleanSpans(final List<Spans> required, final List<Spans> optional, final List<Spans> prohibited, final int slop, final boolean inOrder) throws IOException { optionalSpans = optional; requiredSpans = required; prohibitedSpans = prohibited; this.slop = slop; this.inOrder = inOrder; parentSpans = this.buildSpans(); }
/** * Returns the scorer to be used for match counting and score summing. Uses * requiredSpans, optionalSpans and prohibitedSpans. */ private Spans buildSpans() throws IOException { return (requiredSpans.size() == 0) ? this.buildSpansNoReq() : this.buildSpansSomeReq(); }
/** * At least one required scorer. */ private Spans buildSpansSomeReq() throws IOException { final Spans conjunctionSpans = this.buildConjunctionSpans(); if (optionalSpans.isEmpty()) { return this.addProhibitedSpans(conjunctionSpans); } else { return new ReqOptSpans( this.addProhibitedSpans(conjunctionSpans), optionalSpans.size() == 1 ? optionalSpans.get(0) : new OrSpans(optionalSpans), this); } }
/** * No required scorers */ private Spans buildSpansNoReq() throws IOException { Spans requiredSpans = null; if (optionalSpans.size() > 1) { requiredSpans = new OrSpans(optionalSpans); } else if (optionalSpans.size() == 1) { requiredSpans = optionalSpans.get(0); } return this.addProhibitedSpans(requiredSpans); }
return new SpanScorer(this, new BooleanSpans(required, optional, prohibited, slop, inOrder));