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;
}
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);
}
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));
}
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());
}
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());
}
Aggregations