lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From luc...@nitwit.de
Subject Re: Searcher not aware of index changes
Date Wed, 21 Apr 2004 18:41:12 GMT
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


Mime
View raw message