lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guilherme Barile <...@prosoma.com.br>
Subject Reloading a searcher
Date Thu, 25 Oct 2007 16:10:05 GMT
Hello
	I wrote a simple class to abstract searching on a text file  
(generate by a legacy system).

	class MyFile { private Searcher s; private long timestamp; }

	It creates a timer and checks every ten minutes if  
textfile.lastModified() is diferent from the number it cached on  
timestamp, and recreates the index. There's  a search(query) method  
which parses the query and returns an arraylist of objects.
	My index lies on RAM, so everytime I rebuild it, i do something like

	private void run() {
		File f = new File(textfile);
		
		if(f.lastModified() == this.timestamp) return;
		
		RAMDirectory idx = new RAMDirectory();
	    	IndexWriter writer = new IndexWriter(idx, new StandardAnalyzer 
(),true);
			// here I parse the text file and add the documents to the index

		// update the searcher and timestamp
		this.s = new IndexSearcher(idx);
	    	timestamp = lastModified;
	}

	Problem is: it seems the searcher is not being updated. All search  
operations occur in this class (using my own search method) accessing  
"this.s" directly

	Is there any better approach for doing this (reloading the searcher) ?

Thanks a lot


gui

---------------------------------------------------------------------
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