use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class TestIndexSearcher method testGetQueryCachingPolicy.
public void testGetQueryCachingPolicy() throws IOException {
IndexSearcher searcher = new IndexSearcher(new MultiReader());
assertEquals(IndexSearcher.getDefaultQueryCachingPolicy(), searcher.getQueryCachingPolicy());
QueryCachingPolicy dummyPolicy = new QueryCachingPolicy() {
@Override
public boolean shouldCache(Query query) throws IOException {
return false;
}
@Override
public void onUse(Query query) {
}
};
searcher.setQueryCachingPolicy(dummyPolicy);
assertEquals(dummyPolicy, searcher.getQueryCachingPolicy());
IndexSearcher.setDefaultQueryCachingPolicy(dummyPolicy);
searcher = new IndexSearcher(new MultiReader());
assertEquals(dummyPolicy, searcher.getQueryCachingPolicy());
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class QueryUtils method wrapUnderlyingReader.
/**
* Given an IndexSearcher, returns a new IndexSearcher whose IndexReader
* is a MultiReader containing the Reader of the original IndexSearcher,
* as well as several "empty" IndexReaders -- some of which will have
* deleted documents in them. This new IndexSearcher should
* behave exactly the same as the original IndexSearcher.
* @param s the searcher to wrap
* @param edge if negative, s will be the first sub; if 0, s will be in the middle, if positive s will be the last sub
*/
public static IndexSearcher wrapUnderlyingReader(Random random, final IndexSearcher s, final int edge) throws IOException {
IndexReader r = s.getIndexReader();
// we can't put deleted docs before the nested reader, because
// it will throw off the docIds
IndexReader[] readers = new IndexReader[] { edge < 0 ? r : new MultiReader(), new MultiReader(), new MultiReader(edge < 0 ? emptyReader(4) : new MultiReader(), new MultiReader(), 0 == edge ? r : new MultiReader()), 0 < edge ? new MultiReader() : emptyReader(7), new MultiReader(), new MultiReader(0 < edge ? new MultiReader() : emptyReader(5), new MultiReader(), 0 < edge ? r : new MultiReader()) };
IndexSearcher out = LuceneTestCase.newSearcher(new MultiReader(readers));
out.setSimilarity(s.getSimilarity(true));
return out;
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class TestFieldCacheSort method testEmptyIndex.
/** test sorts when there's nothing in the index */
public void testEmptyIndex() throws Exception {
IndexSearcher empty = newSearcher(new MultiReader());
Query query = new TermQuery(new Term("contents", "foo"));
Sort sort = new Sort();
TopDocs td = empty.search(query, 10, sort, true, true);
assertEquals(0, td.totalHits);
sort.setSort(SortField.FIELD_DOC);
td = empty.search(query, 10, sort, true, true);
assertEquals(0, td.totalHits);
sort.setSort(new SortField("int", SortField.Type.INT), SortField.FIELD_DOC);
td = empty.search(query, 10, sort, true, true);
assertEquals(0, td.totalHits);
sort.setSort(new SortField("string", SortField.Type.STRING, true), SortField.FIELD_DOC);
td = empty.search(query, 10, sort, true, true);
assertEquals(0, td.totalHits);
sort.setSort(new SortField("string_val", SortField.Type.STRING_VAL, true), SortField.FIELD_DOC);
td = empty.search(query, 10, sort, true, true);
assertEquals(0, td.totalHits);
sort.setSort(new SortField("float", SortField.Type.FLOAT), new SortField("string", SortField.Type.STRING));
td = empty.search(query, 10, sort, true, true);
assertEquals(0, td.totalHits);
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class TestBooleanRewrites method testRemoveMatchAllFilter.
public void testRemoveMatchAllFilter() throws IOException {
IndexSearcher searcher = newSearcher(new MultiReader());
BooleanQuery bq = new BooleanQuery.Builder().add(new TermQuery(new Term("foo", "bar")), Occur.MUST).add(new MatchAllDocsQuery(), Occur.FILTER).build();
assertEquals(new TermQuery(new Term("foo", "bar")), searcher.rewrite(bq));
bq = new BooleanQuery.Builder().setMinimumNumberShouldMatch(random().nextInt(5)).add(new TermQuery(new Term("foo", "bar")), Occur.MUST).add(new TermQuery(new Term("foo", "baz")), Occur.MUST).add(new MatchAllDocsQuery(), Occur.FILTER).build();
BooleanQuery expected = new BooleanQuery.Builder().setMinimumNumberShouldMatch(bq.getMinimumNumberShouldMatch()).add(new TermQuery(new Term("foo", "bar")), Occur.MUST).add(new TermQuery(new Term("foo", "baz")), Occur.MUST).build();
assertEquals(expected, searcher.rewrite(bq));
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class TestBoostQuery method testRewrite.
public void testRewrite() throws IOException {
IndexSearcher searcher = new IndexSearcher(new MultiReader());
// inner queries are rewritten
Query q = new BoostQuery(new BooleanQuery.Builder().build(), 2);
assertEquals(new BoostQuery(new MatchNoDocsQuery(), 2), searcher.rewrite(q));
// boosts are merged
q = new BoostQuery(new BoostQuery(new MatchAllDocsQuery(), 3), 2);
assertEquals(new BoostQuery(new MatchAllDocsQuery(), 6), searcher.rewrite(q));
// scores are not computed when the boost is 0
q = new BoostQuery(new MatchAllDocsQuery(), 0);
assertEquals(new BoostQuery(new ConstantScoreQuery(new MatchAllDocsQuery()), 0), searcher.rewrite(q));
}
Aggregations