@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}); }
@Test public void testSpanNearUnordered() throws Exception { this.addDocuments(this.generateDocuments(1000)); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "nine")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "six")); NearSpanQuery query = new NearSpanQuery(new TermSpanQuery[] {term1, term2}, 4, false); checkHits(query, 609, 629, 639, 649, 659, 669, 679, 689, 699, 906, 926, 936, 946, 956, 966, 976, 986, 996); }
@Test public void testSpanNot() 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 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}); }
@Test public void testSpanNotWindowOne() 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, "forty")); NearSpanQuery near = new NearSpanQuery(new TermSpanQuery[]{term1, term2}, 4, true); TermSpanQuery term3 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "one")); SpanQuery query = new NotSpanQuery(near, term3, 1, 1); checkHits(query, new int[]{840, 842, 843, 844, 845, 846, 847, 848, 849, 1840, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849}); }
@Test public void testSpanNotWindowTwoBefore() 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, "forty")); NearSpanQuery near = new NearSpanQuery(new TermSpanQuery[]{term1, term2}, 4, true); TermSpanQuery term3 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "one")); NotSpanQuery query = new NotSpanQuery(near, term3, 2, 0); checkHits(query, new int[]{840, 841, 842, 843, 844, 845, 846, 847, 848, 849}); }
@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}); }
@Test public void testSpanNearExact() throws Exception { this.addDocuments(this.generateDocuments(500)); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "seventy")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "seven")); NearSpanQuery spanQuery = new NearSpanQuery(new TermSpanQuery[] {term1, term2}, 0, true); this.checkHits(spanQuery, 77, 177, 277, 377, 477); QueryUtils.check(term1); QueryUtils.check(term2); QueryUtils.checkUnequal(term1, term2); }
@Test public void testNotSameNode() throws Exception { this.addDocuments( doc(token("aaa", node(1)), token("bbb", node(2))) ); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "aaa")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "bbb")); NearSpanQuery spanQuery = new NearSpanQuery(new TermSpanQuery[] {term1, term2}, 0, true); Query query = new LuceneProxyNodeQuery(spanQuery); TopDocs hits = searcher.search(query, 100); assertEquals(0, hits.totalHits); }
@Test public void testNearExactOrderedAfterInvalidSpan() throws IOException { this.addDocuments(doc(token("aaa", node(2)), token("bbb", node(2), 2), token("aaa", node(2)), token("bbb", node(2)))); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "aaa")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "bbb")); Query query = new LuceneProxyNodeQuery(new NearSpanQuery(new TermSpanQuery[]{term1, term2}, 0, true)); TopDocs hits = searcher.search(query, 100); assertEquals(1, hits.totalHits); }
@Test public void testNotQueryMatchesNearInclude() throws IOException { this.addDocuments(doc(token("fish", node(1)), token("chips", node(1)))); NearSpanQuery fishandchips = new NearSpanQuery(new TermSpanQuery[]{fish, chips}, 0, true); Query query = new LuceneProxyNodeQuery(new NotSpanQuery(fishandchips, fish)); TopDocs hits = searcher.search(query, 100); assertEquals(0, hits.totalHits); }
@Test public void testSpanNearUnordered() throws Exception { this.addDocuments(this.generateDocuments(1000)); NodeSpanQuery term1 = new NodeSpanQuery(ntq("nine").getQuery()); NodeSpanQuery term2 = new NodeSpanQuery(ntq("six").getQuery()); NearSpanQuery query = new NearSpanQuery(new NodeSpanQuery[] {term1, term2}, 4, false); checkHits(query, 609, 629, 639, 649, 659, 669, 679, 689, 699, 906, 926, 936, 946, 956, 966, 976, 986, 996); }
@Test public void testNotSameParent() throws Exception { this.addDocuments( doc(token("aaa", node(1,1)), token("bbb", node(2,2))) ); NodeSpanQuery term1 = new NodeSpanQuery(ntq("aaa").getQuery()); NodeSpanQuery term2 = new NodeSpanQuery(ntq("bbb").getQuery()); NearSpanQuery spanQuery = new NearSpanQuery(new NodeSpanQuery[] {term1, term2}, 0, true); Query query = new LuceneProxyNodeQuery(spanQuery); TopDocs hits = searcher.search(query, 100); assertEquals(0, hits.totalHits); }
@Test public void testSpanNearOrdered() throws Exception { this.addDocuments(this.generateDocuments(1000)); NodeSpanQuery term1 = new NodeSpanQuery(ntq("nine").getQuery()); NodeSpanQuery term2 = new NodeSpanQuery(ntq("six").getQuery()); NearSpanQuery query = new NearSpanQuery(new NodeSpanQuery[] {term1, term2}, 4, true); checkHits(query, 906, 926, 936, 946, 956, 966, 976, 986, 996); }
@Test public void testNotQueryMatchesNearExclude() throws IOException { this.addDocuments(doc(token("fish", node(1)), token("and", node(1)), token("chips", node(1)), token("somethink", node(1)))); NearSpanQuery fishandchips = new NearSpanQuery(new TermSpanQuery[]{fish, chips}, 1, true); Query query = new LuceneProxyNodeQuery(new NotSpanQuery(fish, fishandchips)); TopDocs hits = searcher.search(query, 100); assertEquals(0, hits.totalHits); }
@Test public void testSetAncestorPointer() { NodeSpanQuery term1 = new NodeSpanQuery(ntq("aaa").getQuery()); NodeSpanQuery term2 = new NodeSpanQuery(ntq("bbb").getQuery()); final NearSpanQuery nsq1 = new NearSpanQuery(new SpanQuery[] {term1, term2}, 0, true); final TwigQuery twig = new TwigQuery(); nsq1.setAncestorPointer(twig); assertSame(twig, nsq1.getAncestorPointer()); // clauses must have been updated assertSame(twig, term1.getAncestorPointer()); }
@Test public void testSpanNearExact() throws Exception { this.addDocuments(this.generateDocuments(500)); NodeSpanQuery term1 = new NodeSpanQuery(ntq("seventy").getQuery()); NodeSpanQuery term2 = new NodeSpanQuery(ntq("seven").getQuery()); NearSpanQuery spanQuery = new NearSpanQuery(new NodeSpanQuery[] {term1, term2}, 0, true); this.checkHits(spanQuery, 77, 177, 277, 377, 477); QueryUtils.check(term1); QueryUtils.check(term2); QueryUtils.checkUnequal(term1, term2); }
@Test public void testNotQueryMatchesButThereIsAnotherPosition() throws IOException { this.addDocuments(doc(token("somethink", node(1)), token("fish", node(1)), token("chips", node(1)), token("rise", node(1)), token("and", node(1)), token("fish", node(1)))); NearSpanQuery fishandchips = new NearSpanQuery(new TermSpanQuery[]{fish, chips}, 0, true); Query query = new LuceneProxyNodeQuery(new NotSpanQuery(fish, fishandchips)); TopDocs hits = searcher.search(query, 100); assertEquals(1, hits.totalHits); }
@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}); }
@Test public void testNotQueryMatchesNearExcludeTwoTimes() throws IOException { this.addDocuments(doc(token("flash", node(1)), token("chips", node(2)), token("fish", node(2)), token("and", node(2)), token("chips", node(2)), token("somethink", node(2)), token("and", node(2)), token("fish", node(2)), token("chips", node(2)))); NearSpanQuery fishandchips = new NearSpanQuery(new TermSpanQuery[]{fish, chips}, 1, false); Query query = new LuceneProxyNodeQuery(new NotSpanQuery(chips, fishandchips)); TopDocs hits = searcher.search(query, 100); assertEquals(0, hits.totalHits); }
@Test public void testExplain() throws IOException { this.addDocuments( doc(token("three", node(1,1)), token("hundred", node(1,2)), token("thirty", node(1,3)), token("three", node(1,4))) ); NodeSpanQuery term1 = new NodeSpanQuery(ntq("three").getQuery()); NodeSpanQuery term2 = new NodeSpanQuery(ntq("thirty").getQuery()); NearSpanQuery near1 = new NearSpanQuery(new SpanQuery[] {term1, term2}, 0, false); Query query = new LuceneProxyNodeQuery(near1); Explanation explanation = searcher.explain(query, 0); assertNotNull(explanation); }