use of org.apache.lucene.search.SearcherManager in project lucene-solr by apache.
the class AnalyzingInfixSuggester method getCount.
@Override
public long getCount() throws IOException {
if (searcherMgr == null) {
return 0;
}
SearcherManager mgr;
IndexSearcher searcher;
synchronized (searcherMgrLock) {
// acquire & release on same SearcherManager, via local reference
mgr = searcherMgr;
searcher = mgr.acquire();
}
try {
return searcher.getIndexReader().numDocs();
} finally {
mgr.release(searcher);
}
}
use of org.apache.lucene.search.SearcherManager in project lucene-solr by apache.
the class AnalyzingInfixSuggester method ensureOpen.
private synchronized void ensureOpen() throws IOException {
if (writer == null) {
if (DirectoryReader.indexExists(dir)) {
// Already built; open it:
writer = new IndexWriter(dir, getIndexWriterConfig(getGramAnalyzer(), IndexWriterConfig.OpenMode.APPEND));
} else {
writer = new IndexWriter(dir, getIndexWriterConfig(getGramAnalyzer(), IndexWriterConfig.OpenMode.CREATE));
}
synchronized (searcherMgrLock) {
SearcherManager oldSearcherMgr = searcherMgr;
searcherMgr = new SearcherManager(writer, null);
if (oldSearcherMgr != null) {
oldSearcherMgr.close();
}
}
}
}
use of org.apache.lucene.search.SearcherManager in project lucene-solr by apache.
the class TestTryDelete method testTryDeleteDocument.
public void testTryDeleteDocument() throws IOException {
Directory directory = createIndex();
IndexWriter writer = getWriter(directory);
ReferenceManager<IndexSearcher> mgr = new SearcherManager(writer, new SearcherFactory());
IndexSearcher searcher = mgr.acquire();
TopDocs topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100);
assertEquals(1, topDocs.totalHits);
long result;
if (random().nextBoolean()) {
IndexReader r = DirectoryReader.open(writer);
result = writer.tryDeleteDocument(r, 0);
r.close();
} else {
result = writer.tryDeleteDocument(searcher.getIndexReader(), 0);
}
// The tryDeleteDocument should have succeeded:
assertTrue(result != -1);
assertTrue(writer.hasDeletions());
if (random().nextBoolean()) {
writer.commit();
}
assertTrue(writer.hasDeletions());
mgr.maybeRefresh();
searcher = mgr.acquire();
topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100);
assertEquals(0, topDocs.totalHits);
}
use of org.apache.lucene.search.SearcherManager in project lucene-solr by apache.
the class TestTryDelete method testTryDeleteDocumentCloseAndReopen.
public void testTryDeleteDocumentCloseAndReopen() throws IOException {
Directory directory = createIndex();
IndexWriter writer = getWriter(directory);
ReferenceManager<IndexSearcher> mgr = new SearcherManager(writer, new SearcherFactory());
IndexSearcher searcher = mgr.acquire();
TopDocs topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100);
assertEquals(1, topDocs.totalHits);
long result = writer.tryDeleteDocument(DirectoryReader.open(writer), 0);
assertTrue(result != -1);
writer.commit();
assertTrue(writer.hasDeletions());
mgr.maybeRefresh();
searcher = mgr.acquire();
topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100);
assertEquals(0, topDocs.totalHits);
writer.close();
searcher = new IndexSearcher(DirectoryReader.open(directory));
topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100);
assertEquals(0, topDocs.totalHits);
}
use of org.apache.lucene.search.SearcherManager in project neo4j by neo4j.
the class AllNodesCollector method getAllNodes.
public static List<Long> getAllNodes(Directory directory, Value propertyValue) throws IOException {
try (SearcherManager manager = new SearcherManager(directory, new Neo4jSearcherFactory())) {
IndexSearcher searcher = manager.acquire();
Query query = LuceneDocumentStructure.newSeekQuery(propertyValue);
AllNodesCollector collector = new AllNodesCollector();
searcher.search(query, collector);
return collector.nodeIds;
}
}
Aggregations