use of org.apache.lucene.search.SearcherFactory in project neo4j by neo4j.
the class SimpleUniquenessVerifierTest method initLuceneResources.
@Before
public void initLuceneResources() throws Exception {
dirFactory = new DirectoryFactory.InMemoryDirectoryFactory();
Directory dir = dirFactory.open(testDir.directory("test"));
writer = new IndexWriter(dir, IndexWriterConfigs.standard());
searcherManager = new SearcherManager(writer, true, new SearcherFactory());
}
use of org.apache.lucene.search.SearcherFactory 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.SearcherFactory 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.SearcherFactory in project che by eclipse.
the class LuceneSearcher method doInit.
protected final synchronized void doInit() throws ServerException {
try {
luceneIndexWriter = new IndexWriter(makeDirectory(), new IndexWriterConfig(makeAnalyzer()));
searcherManager = new SearcherManager(luceneIndexWriter, true, new SearcherFactory());
closed = false;
} catch (IOException e) {
throw new ServerException(e);
}
}
use of org.apache.lucene.search.SearcherFactory in project neo4j by neo4j.
the class AllNodesCollector method getAllNodes.
public static List<Long> getAllNodes(Directory directory, Object propertyValue) throws IOException {
try (SearcherManager manager = new SearcherManager(directory, new SearcherFactory())) {
IndexSearcher searcher = manager.acquire();
Query query = LuceneDocumentStructure.newSeekQuery(propertyValue);
AllNodesCollector collector = new AllNodesCollector();
searcher.search(query, collector);
return collector.nodeIds;
}
}
Aggregations