lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: Reopening an index reader still giving me deleted records ?
Date Mon, 07 Nov 2011 17:45:37 GMT
How did you open the first IndexReader (is this an NRT reader or a
"normal" (via IndexReader.open) reader?)?

Also, be careful with threads: I think your code isn't thread-safe
because one thread can finish getIndexSearcher() but not yet incRef'd
the reader, when another thread closes that reader.

Mike McCandless

http://blog.mikemccandless.com

On Mon, Nov 7, 2011 at 8:36 AM, Paul Taylor <paul_t100@fastmail.fm> wrote:
>
> 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-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

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


Mime
View raw message