Search in sources :

Example 1 with SearcherFactory

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());
}
Also used : SearcherFactory(org.apache.lucene.search.SearcherFactory) IndexWriter(org.apache.lucene.index.IndexWriter) DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) SearcherManager(org.apache.lucene.search.SearcherManager) Directory(org.apache.lucene.store.Directory) TestDirectory(org.neo4j.test.rule.TestDirectory) Before(org.junit.Before)

Example 2 with 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);
}
Also used : SearcherFactory(org.apache.lucene.search.SearcherFactory) IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) TermQuery(org.apache.lucene.search.TermQuery) SearcherManager(org.apache.lucene.search.SearcherManager) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory)

Example 3 with SearcherFactory

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);
}
Also used : SearcherFactory(org.apache.lucene.search.SearcherFactory) IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) TermQuery(org.apache.lucene.search.TermQuery) SearcherManager(org.apache.lucene.search.SearcherManager) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory)

Example 4 with SearcherFactory

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);
    }
}
Also used : SearcherFactory(org.apache.lucene.search.SearcherFactory) ServerException(org.eclipse.che.api.core.ServerException) IndexWriter(org.apache.lucene.index.IndexWriter) SearcherManager(org.apache.lucene.search.SearcherManager) IOException(java.io.IOException) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 5 with SearcherFactory

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;
    }
}
Also used : SearcherFactory(org.apache.lucene.search.SearcherFactory) IndexSearcher(org.apache.lucene.search.IndexSearcher) Query(org.apache.lucene.search.Query) SearcherManager(org.apache.lucene.search.SearcherManager)

Aggregations

SearcherFactory (org.apache.lucene.search.SearcherFactory)7 SearcherManager (org.apache.lucene.search.SearcherManager)7 IndexSearcher (org.apache.lucene.search.IndexSearcher)5 Directory (org.apache.lucene.store.Directory)5 TermQuery (org.apache.lucene.search.TermQuery)3 TopDocs (org.apache.lucene.search.TopDocs)3 RAMDirectory (org.apache.lucene.store.RAMDirectory)3 IOException (java.io.IOException)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 Document (org.apache.lucene.document.Document)1 IndexReader (org.apache.lucene.index.IndexReader)1 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)1