@Override public Query clone() { NodeQuery nodeClone = (NodeQuery) nodeQuery.clone(); LuceneProxyNodeQuery proxyClone = new LuceneProxyNodeQuery(nodeClone); return proxyClone; }
@Override public Query getLuceneProxyQuery() { return new LuceneProxyNodeQuery(bsq); }
@Override public Query getLuceneProxyQuery() { return new LuceneProxyNodeQuery(npq); }
@Override public Query rewrite(final IndexReader reader) throws IOException { final Query rewroteQuery = nodeQuery.rewrite(reader); if (nodeQuery == rewroteQuery) { return this; } final LuceneProxyNodeQuery q = new LuceneProxyNodeQuery((NodeQuery) rewroteQuery); q.setBoost(nodeQuery.getBoost()); return q; }
protected void checkHits(Query query, int ... results) throws IOException { if (query instanceof NodeQuery) { query = new LuceneProxyNodeQuery((NodeQuery) query); } // Use index order to ensure that the scoring does not influence the order TopDocs hits = searcher.search(query, 1000, Sort.INDEXORDER); assertEquals(results.length, hits.totalHits); for (int i = 0; i < results.length; i++) { assertEquals(results[i], hits.scoreDocs[i].doc); } }
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 testWildcardQuery2() throws Exception { final NodeWildcardQuery q1 = new NodeWildcardQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "st*e.ca?as")); q1.setDatatype("http://www.w3.org/2001/XMLSchema#string"); this._assertSirenQuery(new LuceneProxyNodeQuery(q1), "st*e.ca?as"); }
@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 testNonExistingExcludeTerm() throws IOException { this.addDocuments( doc(token("aaa", node(1)), token("bbb", node(1))) ); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "aaa")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "bbb")); TermSpanQuery term3 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "ccc")); NearSpanQuery span = new NearSpanQuery(new TermSpanQuery[]{ term1, term2 }, 0, true); Query query = new LuceneProxyNodeQuery(new NotSpanQuery(span, term3)); TopDocs hits = searcher.search(query, 100); assertEquals(1, hits.totalHits); }
@Test(expected=AssertionError.class) public void testNumericDatatypeWrongPrecision() throws Exception { final StandardExtendedKeywordQueryParser parser = new StandardExtendedKeywordQueryParser(); // Set the default datatypes final Map<String, Analyzer> datatypes = new HashMap<String, Analyzer>(); datatypes.put("int", new IntNumericAnalyzer(4)); parser.setDatatypeAnalyzers(datatypes); final NodeQuery rangeWrong = NodeNumericRangeQuery.newIntRange(SirenTestCase.DEFAULT_TEST_FIELD, 42, 12, 21, true, true); assertEquals(new LuceneProxyNodeQuery(rangeWrong), parser.parse("int([12 TO 21])", SirenTestCase.DEFAULT_TEST_FIELD)); }
@Test public void testFuzzyQueries() throws Exception { BooleanSpanQuery bsq = new BooleanSpanQuery(0, false); bsq.add(tsq("aaa").getQuery(), NodeBooleanClause.Occur.MUST); NodeFuzzyQuery fuzzy = new NodeFuzzyQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "bbb")); fuzzy.setDatatype("http://www.w3.org/2001/XMLSchema#string"); bsq.add(new MultiTermSpanQuery<>(fuzzy), NodeBooleanClause.Occur.MUST); this._assertSirenQuery(new LuceneProxyNodeQuery(bsq), "(aaa AND bbb~)~0"); }
@Test public void testRegexQueries() throws Exception { BooleanSpanQuery bsq = new BooleanSpanQuery(0, false); bsq.add(tsq("aaa").getQuery(), NodeBooleanClause.Occur.MUST); NodeRegexpQuery regexp = new NodeRegexpQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "s*e")); regexp.setDatatype("http://www.w3.org/2001/XMLSchema#string"); bsq.add(new MultiTermSpanQuery<>(regexp), NodeBooleanClause.Occur.MUST); this._assertSirenQuery(new LuceneProxyNodeQuery(bsq), "(aaa AND /s*e/)~0"); }
@Test public void testExplain() throws IOException { this.addDocuments( doc(token("three", node(1)), token("hundred", node(1)), token("thirty", node(1)), token("three", node(1))) ); TermSpanQuery term1 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "three")); TermSpanQuery term2 = new TermSpanQuery(new Term(DEFAULT_TEST_FIELD, "thirty")); NearSpanQuery near1 = new NearSpanQuery(new TermSpanQuery[] {term1, term2}, 0, false); Query query = new LuceneProxyNodeQuery(near1); Explanation explanation = searcher.explain(query, 0); assertNotNull(explanation); }
@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 testBoostQuery() throws Exception { final BooleanQuery q = new BooleanQuery(); q.add(ntq("c").getLuceneProxyQuery(), BooleanClause.Occur.MUST); final NodeQuery nq = ntq("b").getQuery(); nq.setBoost(2); q.add(new LuceneProxyNodeQuery(nq), BooleanClause.Occur.MUST); this._assertSirenQuery(q, "c b^2"); }
@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 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 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); }