lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephane James Vaucher <vauch...@cirano.qc.ca>
Subject Re: Searcher not aware of index changes
Date Wed, 21 Apr 2004 19:48:43 GMT
Normally the code should work, iif your you don't keep references to the
old Searcher (and not try cacheing it). Make sure you aren't doing this by
mistake.

For the design of your facade, you could always implement Searchable and
do the delegation to the up-to-date instance of IndexSearcher.

Quick comment: you should call .close() on your searcher before removing
the reference. If this causes exceptions in future searches, it would
indicate incorrect cacheing.

HTH,
sv

On Wed, 21 Apr 2004 lucene@nitwit.de wrote:

> On Wednesday 21 April 2004 19:20, Stephane James Vaucher wrote:
> > This is not normal behaviour. Normally using a new IndexSearcher should
> > reflect the modified state of your index. Could you post a more
> > informative bit of code?
>
> BTW Why can't Lucene care for it itself?
>
>
> Well, according to my logging it does create a new instance. I use only one
> instance of SessoinFacade:
>
> public class SearchFacade extends Observable
> {
> 	protected class IndexObserver implements Observer
> 	{
> 		private final Log log = LogFactory.getLog(getClass());
>
> 		public Searcher indexSearcher;
>
> 		public IndexObserver()
> 		{
> 			newSearcher();	// init
> 		}
>
> 		public void update(Observable o, Object arg)
> 		{
> 			log.debug("Index has changed, creating new Searcher" );
> 			newSearcher();
> 		}
>
> 		private void newSearcher()
> 		{
> 			try
> 			{
> 				indexSearcher = new
> IndexSearcher(IndexReader.open(Configuration.LuceneIndex.MAIN));
> 			}
> 			catch (IOException e)
> 			{
> 				log.error("Could not instantiate searcher: " + e);
> 			}
> 		}
>
> 		public Searcher getIndexSearcher()
> 		{
> 			return indexSearcher;
> 		}
> 	}
>
> 	private IndexObserver indexObserver;
>
> 	public SearchFacade()
> 	{
> 		addObserver(indexObserver = new IndexObserver());
> 	}
>
> 	public void createIndex()
> 	{
> 		...
> 		setChanged();		// index has changed
> 		notifyObservers();
> 	}
>
> 	public Hits search(String query)
> 	{
> 		Searcher searcher = indexObserver.getIndexSearcher();
> 	}
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>


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


Mime
View raw message