Search in sources :

Example 26 with MultiReader

use of org.apache.lucene.index.MultiReader in project OpenGrok by OpenGrok.

the class RuntimeEnvironment method getMultiReader.

/**
 * Return collection of IndexReader objects as MultiReader object
 * for given list of projects.
 * The caller is responsible for releasing the IndexSearcher objects
 * so we add them to the map.
 *
 * @param projects list of projects
 * @param searcherList each SuperIndexSearcher produced will be put into this list
 * @return MultiReader for the projects
 */
public MultiReader getMultiReader(SortedSet<String> projects, ArrayList<SuperIndexSearcher> searcherList) {
    IndexReader[] subreaders = new IndexReader[projects.size()];
    int ii = 0;
    // TODO might need to rewrite to Project instead of String, need changes in projects.jspf too.
    for (String proj : projects) {
        try {
            SuperIndexSearcher searcher = getIndexSearcher(proj);
            subreaders[ii++] = searcher.getIndexReader();
            searcherList.add(searcher);
        } catch (IOException | NullPointerException ex) {
            LOGGER.log(Level.SEVERE, "cannot get IndexReader for project " + proj, ex);
            return null;
        }
    }
    MultiReader multiReader = null;
    try {
        multiReader = new MultiReader(subreaders, true);
    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, "cannot construct MultiReader for set of projects", ex);
    }
    return multiReader;
}
Also used : MultiReader(org.apache.lucene.index.MultiReader) IndexReader(org.apache.lucene.index.IndexReader) IOException(java.io.IOException)

Example 27 with MultiReader

use of org.apache.lucene.index.MultiReader in project OpenGrok by OpenGrok.

the class SearchEngine method searchMultiDatabase.

/**
 * Perform search on multiple indexes in parallel.
 * @param paging whether to use paging (if yes, first X pages will load
 * faster)
 * @param root list of projects to search
 * @throws IOException
 */
private void searchMultiDatabase(List<Project> root, boolean paging) throws IOException {
    SortedSet<String> projects = new TreeSet<>();
    for (Project p : root) {
        projects.add(p.getName());
    }
    // We use MultiReader even for single project. This should
    // not matter given that MultiReader is just a cheap wrapper
    // around set of IndexReader objects.
    MultiReader searchables = RuntimeEnvironment.getInstance().getMultiReader(projects, searcherList);
    searcher = new IndexSearcher(searchables);
    searchIndex(searcher, paging);
}
Also used : SuperIndexSearcher(org.opengrok.indexer.configuration.SuperIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) Project(org.opengrok.indexer.configuration.Project) TreeSet(java.util.TreeSet) MultiReader(org.apache.lucene.index.MultiReader)

Example 28 with MultiReader

use of org.apache.lucene.index.MultiReader in project elasticsearch by elastic.

the class RangeQueryRewriteTests method testRewriteEmptyReader.

public void testRewriteEmptyReader() throws Exception {
    IndexService indexService = createIndex("test");
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo").field("type", "date").endObject().endObject().endObject().endObject().string();
    indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false);
    IndexReader reader = new MultiReader();
    QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, indexService.mapperService(), null, null, xContentRegistry(), null, reader, null);
    RangeQueryBuilder range = new RangeQueryBuilder("foo");
    // no values -> DISJOINT
    assertEquals(Relation.DISJOINT, range.getRelation(context));
}
Also used : IndexService(org.elasticsearch.index.IndexService) MultiReader(org.apache.lucene.index.MultiReader) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) IndexReader(org.apache.lucene.index.IndexReader)

Example 29 with MultiReader

use of org.apache.lucene.index.MultiReader in project elasticsearch by elastic.

the class QueryPhaseTests method testPostFilterDisablesCountOptimization.

public void testPostFilterDisablesCountOptimization() throws Exception {
    TestSearchContext context = new TestSearchContext(null);
    context.parsedQuery(new ParsedQuery(new MatchAllDocsQuery()));
    context.setSize(0);
    context.setTask(new SearchTask(123L, "", "", "", null));
    final AtomicBoolean collected = new AtomicBoolean();
    IndexSearcher contextSearcher = new IndexSearcher(new MultiReader()) {

        protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
            collected.set(true);
            super.search(leaves, weight, collector);
        }
    };
    QueryPhase.execute(context, contextSearcher);
    assertEquals(0, context.queryResult().topDocs().totalHits);
    assertFalse(collected.get());
    context.parsedPostFilter(new ParsedQuery(new MatchNoDocsQuery()));
    QueryPhase.execute(context, contextSearcher);
    assertEquals(0, context.queryResult().topDocs().totalHits);
    assertTrue(collected.get());
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestSearchContext(org.elasticsearch.test.TestSearchContext) ParsedQuery(org.elasticsearch.index.query.ParsedQuery) SearchTask(org.elasticsearch.action.search.SearchTask) MultiReader(org.apache.lucene.index.MultiReader) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) Collector(org.apache.lucene.search.Collector) List(java.util.List) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Weight(org.apache.lucene.search.Weight)

Example 30 with MultiReader

use of org.apache.lucene.index.MultiReader in project elasticsearch by elastic.

the class QueryPhaseTests method testMinScoreDisablesCountOptimization.

public void testMinScoreDisablesCountOptimization() throws Exception {
    TestSearchContext context = new TestSearchContext(null);
    context.parsedQuery(new ParsedQuery(new MatchAllDocsQuery()));
    context.setSize(0);
    context.setTask(new SearchTask(123L, "", "", "", null));
    final AtomicBoolean collected = new AtomicBoolean();
    IndexSearcher contextSearcher = new IndexSearcher(new MultiReader()) {

        protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
            collected.set(true);
            super.search(leaves, weight, collector);
        }
    };
    QueryPhase.execute(context, contextSearcher);
    assertEquals(0, context.queryResult().topDocs().totalHits);
    assertFalse(collected.get());
    context.minimumScore(1);
    QueryPhase.execute(context, contextSearcher);
    assertEquals(0, context.queryResult().topDocs().totalHits);
    assertTrue(collected.get());
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestSearchContext(org.elasticsearch.test.TestSearchContext) ParsedQuery(org.elasticsearch.index.query.ParsedQuery) SearchTask(org.elasticsearch.action.search.SearchTask) MultiReader(org.apache.lucene.index.MultiReader) Collector(org.apache.lucene.search.Collector) List(java.util.List) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Weight(org.apache.lucene.search.Weight)

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