Search in sources :

Example 31 with MultiReader

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])));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) MultiReader(org.apache.lucene.index.MultiReader) Term(org.apache.lucene.index.Term) HashSet(java.util.HashSet)

Example 32 with MultiReader

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);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) MultiReader(org.apache.lucene.index.MultiReader) QueryBitSetProducer(org.apache.lucene.search.join.QueryBitSetProducer) Term(org.apache.lucene.index.Term)

Example 33 with MultiReader

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;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) MultiReader(org.apache.lucene.index.MultiReader) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) Sort(org.apache.lucene.search.Sort) Document(org.apache.lucene.document.Document)

Example 34 with MultiReader

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;
}
Also used : MultiReader(org.apache.lucene.index.MultiReader) IndexReader(org.apache.lucene.index.IndexReader)

Example 35 with MultiReader

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();
}
Also used : MultiReader(org.apache.lucene.index.MultiReader) IndexReader(org.apache.lucene.index.IndexReader) Term(org.apache.lucene.index.Term) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Aggregations

MultiReader (org.apache.lucene.index.MultiReader)47 IndexReader (org.apache.lucene.index.IndexReader)20 Term (org.apache.lucene.index.Term)20 IndexSearcher (org.apache.lucene.search.IndexSearcher)14 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)7 Document (org.apache.lucene.document.Document)6 Query (org.apache.lucene.search.Query)6 IOException (java.io.IOException)5 TermQuery (org.apache.lucene.search.TermQuery)5 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 HashSet (java.util.HashSet)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)3 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)3 Sort (org.apache.lucene.search.Sort)3 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)2 LeafReader (org.apache.lucene.index.LeafReader)2