JAVAGeek
JAVAGeek

Reputation: 2794

Lucene's Near RealTime search implementation

This is my code to search something in lucene .

        ScoreDoc[] hits = null;
        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_35);
        QueryParser q = new QueryParser(Version.LUCENE_35, "content", analyzer);
        Query query = q.parse(searchString);

        IndexReader reader = IndexReader.open(IndexWriterSingleton.getIndexWriter(), true);
        IndexSearcher is = new IndexSearcher(reader);
        // IndexSearcher is = new IndexSearcher(index, true);
        TopScoreDocCollector collector = TopScoreDocCollector.create(100, true);
        is.search(query, collector);
        hits = collector.topDocs().scoreDocs;

My question is : does this line (JUST THIS LINE) makes the search Near realtime ?

IndexReader reader = IndexReader.open(IndexWriterSingleton.getIndexWriter(), true);

I am maintaining a single IndexWriter (not closing it anywhere).

Upvotes: 0

Views: 422

Answers (1)

MJB
MJB

Reputation: 9399

don't make your life difficult. Use the NRTManager class to handle all of this.

Upvotes: 1

Related Questions