LUCENE-8459: add SearcherTaxonomyManager constructor taking already opened readers

This commit is contained in:
Mike McCandless 2018-09-11 14:57:43 -04:00
parent 89bc082478
commit a9551404fd
3 changed files with 32 additions and 0 deletions

View File

@ -219,6 +219,10 @@ API Changes:
* LUCENE-8422: Static helper functions for Matches and MatchesIterator implementations * LUCENE-8422: Static helper functions for Matches and MatchesIterator implementations
have been moved from Matches to MatchesUtils (Alan Woodward) have been moved from Matches to MatchesUtils (Alan Woodward)
* LUCENE-8459: SearcherTaxonomyManager now has a constructor taking already opened
IndexReaders, allowing the caller to pass a FilterDirectoryReader, for example.
(Mike McCandless)
Bug Fixes: Bug Fixes:
* LUCENE-8445: Tighten condition when two planes are identical to prevent constructing * LUCENE-8445: Tighten condition when two planes are identical to prevent constructing

View File

@ -98,6 +98,20 @@ public class SearcherTaxonomyManager extends ReferenceManager<SearcherTaxonomyMa
taxoEpoch = -1; taxoEpoch = -1;
} }
/**
* Creates this from already opened {@link IndexReader} and {@link DirectoryTaxonomyReader} instances. Note that
* the incoming readers will be closed when you call {@link #close}.
*/
public SearcherTaxonomyManager(IndexReader reader, DirectoryTaxonomyReader taxoReader, SearcherFactory searcherFactory) throws IOException {
if (searcherFactory == null) {
searcherFactory = new SearcherFactory();
}
this.searcherFactory = searcherFactory;
current = new SearcherAndTaxonomy(SearcherManager.getSearcher(searcherFactory, reader, null), taxoReader);
this.taxoWriter = null;
taxoEpoch = -1;
}
@Override @Override
protected void decRef(SearcherAndTaxonomy ref) throws IOException { protected void decRef(SearcherAndTaxonomy ref) throws IOException {
ref.searcher.getIndexReader().decRef(); ref.searcher.getIndexReader().decRef();

View File

@ -32,14 +32,18 @@ import org.apache.lucene.facet.Facets;
import org.apache.lucene.facet.FacetsCollector; import org.apache.lucene.facet.FacetsCollector;
import org.apache.lucene.facet.FacetsConfig; import org.apache.lucene.facet.FacetsConfig;
import org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager.SearcherAndTaxonomy; import org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager.SearcherAndTaxonomy;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexNotFoundException; import org.apache.lucene.index.IndexNotFoundException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.SegmentInfos; import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.index.TieredMergePolicy; import org.apache.lucene.index.TieredMergePolicy;
import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.ReferenceManager; import org.apache.lucene.search.ReferenceManager;
import org.apache.lucene.search.SearcherFactory;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
@ -347,4 +351,14 @@ public class TestSearcherTaxonomyManager extends FacetTestCase {
expectThrows(IndexNotFoundException.class, mgr::maybeRefreshBlocking); expectThrows(IndexNotFoundException.class, mgr::maybeRefreshBlocking);
IOUtils.close(w, tw, mgr, indexDir, taxoDir); IOUtils.close(w, tw, mgr, indexDir, taxoDir);
} }
private SearcherTaxonomyManager getSearcherTaxonomyManager(Directory indexDir, Directory taxoDir, SearcherFactory searcherFactory) throws IOException {
if (random().nextBoolean()) {
return new SearcherTaxonomyManager(indexDir, taxoDir, searcherFactory);
} else {
IndexReader reader = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
return new SearcherTaxonomyManager(reader, taxoReader, searcherFactory);
}
}
} }