I build indexes from scratch every three hours in a seperate process, then when they are built I replace the old indexes with these new ones in my search server.
Then I tell the search to reload the indexes as follows:

public void reloadIndex() throws CorruptIndexException, IOException {

        if (indexSearcher != null) {
            IndexReader oldReader = indexSearcher.getIndexReader();
            IndexReader newReader = oldReader.reopen();
            if (oldReader != newReader) {
                Similarity similarity = indexSearcher.getSimilarity();
                indexSearcher = new IndexSearcher(newReader);
                indexSearcher.setSimilarity(similarity);
                this.setLastServerUpdatedDate();
                oldReader.close();
            }
        }
    }


What I'm finding is that new searches are finding new records added BUT still find records that have been deleted and no longer exist in the index. This is in one query, thus must mean I'm getting NEW AND OLD results for my new index reader rather than still using the old one, so am I misunderstanding what reopen() does, or it not working correctly ?

thanks Paul

(This code is only other plaae where reader is accessed:

public Results searchLucene(String query, int offset, int limit) throws IOException, ParseException {

        IndexSearcher searcher=null;
        try {
            searcher = getIndexSearcher();
            searcher.getIndexReader().incRef();
TopDocs topdocs = searcher.search(parseQuery(query), offset + limit);
            searchCount.incrementAndGet();
            return processResults(searcher, topdocs, offset);
        }
        finally {
            searcher.getIndexReader().decRef();
        }
    }
)




---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to