use of org.apache.lucene.index.MultiReader in project elasticsearch by elastic.
the class BlendedTermQueryTests method testExtractTerms.
public void testExtractTerms() throws IOException {
Set<Term> terms = new HashSet<>();
int num = scaledRandomIntBetween(1, 10);
for (int i = 0; i < num; i++) {
terms.add(new Term(TestUtil.randomRealisticUnicodeString(random(), 1, 10), TestUtil.randomRealisticUnicodeString(random(), 1, 10)));
}
BlendedTermQuery blendedTermQuery = random().nextBoolean() ? BlendedTermQuery.dismaxBlendedQuery(terms.toArray(new Term[0]), random().nextFloat()) : BlendedTermQuery.booleanBlendedQuery(terms.toArray(new Term[0]), random().nextBoolean());
Set<Term> extracted = new HashSet<>();
IndexSearcher searcher = new IndexSearcher(new MultiReader());
searcher.createNormalizedWeight(blendedTermQuery, false).extractTerms(extracted);
assertThat(extracted.size(), equalTo(terms.size()));
assertThat(extracted, containsInAnyOrder(terms.toArray(new Term[0])));
}
use of org.apache.lucene.index.MultiReader in project elasticsearch by elastic.
the class ESToParentBlockJoinQueryTests method testRewrite.
public void testRewrite() throws IOException {
Query q = new ESToParentBlockJoinQuery(// rewrites to a TermQuery
new PhraseQuery("body", "term"), new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))), ScoreMode.Avg, "nested");
Query expected = new ESToParentBlockJoinQuery(new TermQuery(new Term("body", "term")), new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))), ScoreMode.Avg, "nested");
Query rewritten = q.rewrite(new MultiReader());
assertEquals(expected, rewritten);
}
use of org.apache.lucene.index.MultiReader in project neo4j by neo4j.
the class LuceneLegacyIndex method search.
private IndexHits<Document> search(IndexReference searcherRef, IndexSearcher fulltextTransactionStateSearcher, Query query, QueryContext additionalParametersOrNull, Collection<EntityId> removed) throws IOException {
if (fulltextTransactionStateSearcher != null && !removed.isEmpty()) {
letThroughAdditions(fulltextTransactionStateSearcher, query, removed);
}
IndexSearcher searcher = fulltextTransactionStateSearcher == null ? searcherRef.getSearcher() : new IndexSearcher(new MultiReader(searcherRef.getSearcher().getIndexReader(), fulltextTransactionStateSearcher.getIndexReader()));
IndexHits<Document> result;
if (additionalParametersOrNull != null && additionalParametersOrNull.getTop() > 0) {
result = new TopDocsIterator(query, additionalParametersOrNull, searcher);
} else {
Sort sorting = additionalParametersOrNull != null ? additionalParametersOrNull.getSorting() : null;
boolean forceScore = additionalParametersOrNull == null || !additionalParametersOrNull.getTradeCorrectnessForSpeed();
DocValuesCollector collector = new DocValuesCollector(forceScore);
searcher.search(query, collector);
return collector.getIndexHits(sorting);
}
return result;
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class TestDocSet method dummyMultiReader.
public IndexReader dummyMultiReader(int nSeg, int maxDoc) throws IOException {
if (nSeg == 1 && rand.nextBoolean())
return dummyIndexReader(rand.nextInt(maxDoc));
IndexReader[] subs = new IndexReader[rand.nextInt(nSeg) + 1];
for (int i = 0; i < subs.length; i++) {
subs[i] = dummyIndexReader(rand.nextInt(maxDoc));
}
MultiReader mr = new MultiReader(subs);
return mr;
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class TestFuzzyQuery method testTieBreaker.
/**
* MultiTermQuery provides (via attribute) information about which values
* must be competitive to enter the priority queue.
*
* FuzzyQuery optimizes itself around this information, if the attribute
* is not implemented correctly, there will be problems!
*/
public void testTieBreaker() throws Exception {
Directory directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
addDoc("a123456", writer);
addDoc("c123456", writer);
addDoc("d123456", writer);
addDoc("e123456", writer);
Directory directory2 = newDirectory();
RandomIndexWriter writer2 = new RandomIndexWriter(random(), directory2);
addDoc("a123456", writer2);
addDoc("b123456", writer2);
addDoc("b123456", writer2);
addDoc("b123456", writer2);
addDoc("c123456", writer2);
addDoc("f123456", writer2);
IndexReader ir1 = writer.getReader();
IndexReader ir2 = writer2.getReader();
MultiReader mr = new MultiReader(ir1, ir2);
IndexSearcher searcher = newSearcher(mr);
FuzzyQuery fq = new FuzzyQuery(new Term("field", "z123456"), 1, 0, 2, false);
TopDocs docs = searcher.search(fq, 2);
// 5 docs, from the a and b's
assertEquals(5, docs.totalHits);
mr.close();
ir1.close();
ir2.close();
writer.close();
writer2.close();
directory.close();
directory2.close();
}
Aggregations