@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; }
@Test public void testSetLevelConstraint() { NodeSpanQuery term1 = new NodeSpanQuery(ntq("aaa").getQuery()); final PositionRangeSpanQuery prsq1 = new PositionRangeSpanQuery(term1, 3, 4); prsq1.setLevelConstraint(3); assertEquals(3, prsq1.getLevelConstraint()); // Level constraint must have been transferred to the clauses assertEquals(3, prsq1.getMatch().getLevelConstraint()); }
@Test public void testEquality() throws Exception { NodeSpanQuery term1 = new NodeSpanQuery(ntq("aaa").getQuery()); final PositionRangeSpanQuery prsq1 = new PositionRangeSpanQuery(term1, 3, 4); NodeSpanQuery term2 = new NodeSpanQuery(ntq("aaa").getQuery()); final PositionRangeSpanQuery prsq2 = new PositionRangeSpanQuery(term2, 3, 4); assertEquals(prsq1, prsq2); NodeSpanQuery term3 = new NodeSpanQuery(ntq("bbb").getQuery()); final PositionRangeSpanQuery prsq3 = new PositionRangeSpanQuery(term3, 3, 4); assertNotEquals(prsq1, prsq3); final PositionRangeSpanQuery prsq4 = new PositionRangeSpanQuery(term1, 0, 2); assertNotEquals(prsq1, prsq4); final PositionRangeSpanQuery prsq5 = new PositionRangeSpanQuery(term1, 3, 4); prsq5.setLevelConstraint(3); assertNotEquals(prsq1, prsq5); final PositionRangeSpanQuery prsq6 = new PositionRangeSpanQuery(term1, 3, 4); prsq6.setNodeConstraint(5); assertNotEquals(prsq1, prsq6); }
@Test public void testSetAncestorPointer() { NodeSpanQuery term1 = new NodeSpanQuery(ntq("aaa").getQuery()); final PositionRangeSpanQuery prsq1 = new PositionRangeSpanQuery(term1, 3, 4); final TwigQuery twig = new TwigQuery(); prsq1.setAncestorPointer(twig); assertSame(twig, prsq1.getAncestorPointer()); // clauses must have been updated assertSame(twig, term1.getAncestorPointer()); }
public void testFuzzy() throws Exception { NodeFuzzyQuery fq = new NodeFuzzyQuery(new Term(DEFAULT_TEST_FIELD, "broan")); SpanQuery sfq = new MultiTermSpanQuery<NodeFuzzyQuery>(fq); // will not match quick brown fox PositionRangeSpanQuery sprq = new PositionRangeSpanQuery(sfq, 3, 6); Query query = new LuceneProxyNodeQuery(sprq); assertEquals(2, searcher.search(query, 10).totalHits); }
public void testFuzzy2() throws Exception { // maximum of 1 term expansion NodeFuzzyQuery fq = new NodeFuzzyQuery(new Term(DEFAULT_TEST_FIELD, "broan"), 1, 0, 1, false); SpanQuery sfq = new MultiTermSpanQuery<NodeFuzzyQuery>(fq); // will only match jumps over lazy broun dog PositionRangeSpanQuery sprq = new PositionRangeSpanQuery(sfq, 0, 100); Query query = new LuceneProxyNodeQuery(sprq); assertEquals(1, searcher.search(query, 10).totalHits); }
@Test public void testSpanPositionRange() throws Exception { this.addDocuments(this.generateDocuments(600)); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "five")); PositionRangeSpanQuery query = new PositionRangeSpanQuery(term1, 1, 2); checkHits(query, new int[] {25, 35, 45, 55, 65, 75, 85, 95}); //assertTrue(searcher.explain(query, 25).getValue() > 0.0f); //assertTrue(searcher.explain(query, 95).getValue() > 0.0f); query = new PositionRangeSpanQuery(term1, 6, 7); checkHits(query, new int[]{}); query = new PositionRangeSpanQuery(term1, 0, 1); checkHits(query, new int[] {5, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599}); }
@Override public String toString(String field) { StringBuilder buffer = new StringBuilder(); buffer.append("spanPosRange("); buffer.append(match.toString(field)); buffer.append(", ").append(start).append(", "); buffer.append(end); buffer.append(")"); buffer.append(ToStringUtils.boost(getBoost())); return buffer.toString(); }
@Test public void testSpanPositionRange() throws Exception { this.addDocuments(this.generateDocuments(600)); NodeSpanQuery term1 = new NodeSpanQuery(ntq("five").getQuery()); PositionRangeSpanQuery query = new PositionRangeSpanQuery(term1, 1, 2); checkHits(query, new int[] {25, 35, 45, 55, 65, 75, 85, 95}); //assertTrue(searcher.explain(query, 25).getValue() > 0.0f); //assertTrue(searcher.explain(query, 95).getValue() > 0.0f); query = new PositionRangeSpanQuery(term1, 6, 7); checkHits(query, new int[]{}); query = new PositionRangeSpanQuery(term1, 0, 1); checkHits(query, new int[] {5, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599}); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + Float.floatToIntBits(this.getBoost()); result = prime * result + match.hashCode(); result = prime * result + lowerBound; result = prime * result + upperBound; result = prime * result + levelConstraint; result = prime * result + start; result = prime * result + end; return result; }
SpanQuery termSpanRange = new PositionRangeSpanQuery(termOne, 0, 1); Query query = new LuceneProxyNodeQuery(termSpanRange); TopDocs hits = searcher.search(query, 100); assertEquals(3, hits.totalHits); termSpanRange = new PositionRangeSpanQuery(termOne, 1, 3); query = new LuceneProxyNodeQuery(termSpanRange); hits = searcher.search(query, 100); termSpanRange = new PositionRangeSpanQuery(termTwo, 1, 2); query = new LuceneProxyNodeQuery(termSpanRange); hits = searcher.search(query, 100); assertEquals(2, hits.totalHits); termSpanRange = new PositionRangeSpanQuery(termTwo, 2, 3); query = new LuceneProxyNodeQuery(termSpanRange); hits = searcher.search(query, 100); termSpanRange = new PositionRangeSpanQuery(termTree, 2, 3); query = new LuceneProxyNodeQuery(termSpanRange); hits = searcher.search(query, 100); assertEquals(1, hits.totalHits); termSpanRange = new PositionRangeSpanQuery(termTree, 3, 4); query = new LuceneProxyNodeQuery(termSpanRange); hits = searcher.search(query, 100);