use of org.apache.lucene.search.MatchNoDocsQuery in project lucene-solr by apache.
the class BoostingQueryTest method testRewrite.
public void testRewrite() throws IOException {
IndexReader reader = new MultiReader();
BoostingQuery q = new BoostingQuery(new BooleanQuery.Builder().build(), new MatchAllDocsQuery(), 3);
Query rewritten = new IndexSearcher(reader).rewrite(q);
Query expectedRewritten = new BoostingQuery(new MatchNoDocsQuery(), new MatchAllDocsQuery(), 3);
assertEquals(expectedRewritten, rewritten);
assertSame(rewritten, rewritten.rewrite(reader));
}
use of org.apache.lucene.search.MatchNoDocsQuery in project lucene-solr by apache.
the class TestJoinUtil method testRewrite.
public void testRewrite() throws IOException {
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
Document doc = new Document();
doc.add(new SortedDocValuesField("join_field", new BytesRef("abc")));
w.addDocument(doc);
doc = new Document();
doc.add(new SortedDocValuesField("join_field", new BytesRef("abd")));
w.addDocument(doc);
IndexReader reader = w.getReader();
IndexSearcher searcher = newSearcher(reader);
OrdinalMap ordMap = OrdinalMap.build(null, new SortedDocValues[0], 0f);
Query joinQuery = JoinUtil.createJoinQuery("join_field", new MatchNoDocsQuery(), new MatchNoDocsQuery(), searcher, RandomPicks.randomFrom(random(), ScoreMode.values()), ordMap, 0, Integer.MAX_VALUE);
// no exception due to missing rewrites
searcher.search(joinQuery, 1);
reader.close();
w.close();
dir.close();
}
use of org.apache.lucene.search.MatchNoDocsQuery in project lucene-solr by apache.
the class TestQueryBitSetProducer method testSimple.
public void testSimple() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig().setMergePolicy(NoMergePolicy.INSTANCE);
RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc);
w.addDocument(new Document());
DirectoryReader reader = w.getReader();
QueryBitSetProducer producer = new QueryBitSetProducer(new MatchNoDocsQuery());
assertNull(producer.getBitSet(reader.leaves().get(0)));
assertEquals(1, producer.cache.size());
producer = new QueryBitSetProducer(new MatchAllDocsQuery());
BitSet bitSet = producer.getBitSet(reader.leaves().get(0));
assertEquals(1, bitSet.length());
assertEquals(true, bitSet.get(0));
assertEquals(1, producer.cache.size());
IOUtils.close(reader, w, dir);
}
use of org.apache.lucene.search.MatchNoDocsQuery in project lucene-solr by apache.
the class TestQPHelper method testStopwords.
public void testStopwords() throws Exception {
StandardQueryParser qp = new StandardQueryParser();
CharacterRunAutomaton stopSet = new CharacterRunAutomaton(new RegExp("the|foo").toAutomaton());
qp.setAnalyzer(new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, stopSet));
Query result = qp.parse("a:the OR a:foo", "a");
assertNotNull("result is null and it shouldn't be", result);
assertTrue("result is not a MatchNoDocsQuery", result instanceof MatchNoDocsQuery);
result = qp.parse("a:woo OR a:the", "a");
assertNotNull("result is null and it shouldn't be", result);
assertTrue("result is not a TermQuery", result instanceof TermQuery);
result = qp.parse("(fieldX:xxxxx OR fieldy:xxxxxxxx)^2 AND (fieldx:the OR fieldy:foo)", "a");
Query expected = new BooleanQuery.Builder().add(new TermQuery(new Term("fieldX", "xxxxx")), Occur.SHOULD).add(new TermQuery(new Term("fieldy", "xxxxxxxx")), Occur.SHOULD).build();
expected = new BoostQuery(expected, 2f);
assertEquals(expected, result);
}
use of org.apache.lucene.search.MatchNoDocsQuery in project lucene-solr by apache.
the class TestMultiFieldQPHelper method testStaticMethod1.
public void testStaticMethod1() throws QueryNodeException {
String[] fields = { "b", "t" };
String[] queries = { "one", "two" };
Query q = QueryParserUtil.parse(queries, fields, new MockAnalyzer(random()));
assertEquals("b:one t:two", q.toString());
String[] queries2 = { "+one", "+two" };
q = QueryParserUtil.parse(queries2, fields, new MockAnalyzer(random()));
assertEquals("b:one t:two", q.toString());
String[] queries3 = { "one", "+two" };
q = QueryParserUtil.parse(queries3, fields, new MockAnalyzer(random()));
assertEquals("b:one t:two", q.toString());
String[] queries4 = { "one +more", "+two" };
q = QueryParserUtil.parse(queries4, fields, new MockAnalyzer(random()));
assertEquals("(b:one +b:more) t:two", q.toString());
String[] queries5 = { "blah" };
// expected exception, array length differs
expectThrows(IllegalArgumentException.class, () -> {
QueryParserUtil.parse(queries5, fields, new MockAnalyzer(random()));
});
// check also with stop words for this static form (qtxts[], fields[]).
TestQPHelper.QPTestAnalyzer stopA = new TestQPHelper.QPTestAnalyzer();
String[] queries6 = { "((+stop))", "+((stop))" };
q = QueryParserUtil.parse(queries6, fields, stopA);
assertEquals("MatchNoDocsQuery(\"\") MatchNoDocsQuery(\"\")", q.toString());
//assertEquals(" ", q.toString());
String[] queries7 = { "one ((+stop)) +more", "+((stop)) +two" };
q = QueryParserUtil.parse(queries7, fields, stopA);
assertEquals("(b:one +b:more) (+t:two)", q.toString());
}
Aggregations