@Override public float scoreInNode() throws IOException { float score = 0.0f; // Sum the score of the sub-spans for (int i = 0; i < subSpans.length; i++) { score += subSpans[i].scoreInNode(); } // compute the sloppy weight float sloppyWeight = this.sloppyWeight(this.getSlop()); return score * sloppyWeight; }
@Override public boolean nextPosition() throws IOException { // move the included spans to its next position if (!includeSpans.nextPosition()) { // no match for included spans return false; } // try to find a non excluded position return this.toNonExcludedPosition(); }
public float scoreInNode() throws IOException { // Sum the score of spans, starting from the top, having the same document and node. // Add the score of the top. return this.sumScoreInNode(1) + this.top().scoreInNode(); }
@Test public void testSpanWithMultipleNotSingle() throws Exception { this.addDocuments(this.generateDocuments(2000)); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "eight")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "one")); NearSpanQuery near = new NearSpanQuery(new TermSpanQuery[]{term1, term2}, 4, true); TermSpanQuery term3 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "forty")); SpanQuery or = new OrSpanQuery(new TermSpanQuery[]{term3}); SpanQuery query = new NotSpanQuery(near, or); checkHits(query, new int[]{801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891}); }
@Override protected void addClause(OrSpanQuery topLevel, Term term, int docFreq, float boost, TermContext states) { final TermSpanQuery q = new TermSpanQuery(term); q.setBoost(boost); topLevel.addClause(q); } };
@Test public void testSpanNot() throws Exception { this.addDocuments(this.generateDocuments(2000)); NodeSpanQuery term1 = new NodeSpanQuery(ntq("eight").getQuery()); NodeSpanQuery term2 = new NodeSpanQuery(ntq("one").getQuery()); NearSpanQuery near = new NearSpanQuery(new SpanQuery[]{term1, term2}, 4, true); NodeSpanQuery term3 = new NodeSpanQuery(ntq("forty").getQuery()); SpanQuery query = new NotSpanQuery(near, term3); checkHits(query, new int[]{801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891}); }
private boolean initSpanQueue(final int target) throws IOException { for (Spans subSpan : subSpans) { if (((target == -1) && subSpan.nextCandidateDocument()) || ((target != -1) && subSpan.skipToCandidate(target))) { queue.add(subSpan); } } return queue.size() != 0; }
@Override protected final boolean lessThan(final Spans spans1, final Spans spans2) { return isSpansOrdered(spans1.start(), spans1.end(), spans2.start(), spans2.end()); }
protected boolean doNextPosition() throws IOException { for (;;) { switch (acceptPosition(this)) { case YES: return true; case NO: if (!spans.nextPosition()) return false; break; } } }
@Override public boolean nextPosition() throws IOException { if (!spans.nextPosition()){ return false; } return doNextPosition(); }
@Override public boolean equals(Object o) { if (!(o instanceof PositionRangeSpanQuery)) return false; final PositionRangeSpanQuery other = (PositionRangeSpanQuery) o; return (this.getBoost() == other.getBoost()) && this.match.equals(other.match) && this.end == other.end && this.start == other.start && this.levelConstraint == other.levelConstraint && this.lowerBound == other.lowerBound && this.upperBound == other.upperBound; }
@Override public boolean equals(Object o) { if (!(o instanceof NotSpanQuery)) return false; final NotSpanQuery other = (NotSpanQuery) o; return (this.getBoost() == other.getBoost()) && this.include != null && this.include.equals(other.include) && this.exclude != null && this.exclude.equals(other.exclude) && this.pre == other.pre && this.post == other.post && this.levelConstraint == other.levelConstraint && this.lowerBound == other.lowerBound && this.upperBound == other.upperBound; }
@Test public void testSpanNotWindowNeg() throws Exception { this.addDocuments(this.generateDocuments(2000)); // test handling of invalid window < 0 TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "eight")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "one")); NearSpanQuery near = new NearSpanQuery(new TermSpanQuery[]{term1, term2}, 4, true); TermSpanQuery term3 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "forty")); OrSpanQuery or = new OrSpanQuery(new TermSpanQuery[]{term3}); NotSpanQuery query = new NotSpanQuery(near, or); checkHits(query, new int[]{801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891}); }
@Test public void testSpanNotWindowDoubleExcludesBefore() throws Exception { // test hitting two excludes before an include this.addDocuments(this.generateDocuments(2000)); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "forty")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "two")); NearSpanQuery near = new NearSpanQuery(new TermSpanQuery[]{term1, term2}, 2, true); TermSpanQuery exclude = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "one")); SpanQuery query = new NotSpanQuery(near, exclude, 4, 1); checkHits(query, new int[]{42, 242, 342, 442, 542, 642, 742, 842, 942}); }