Thanks so much for your help Balasubramanian. Interestingly enough, I
tried doing the following:
indexWriter.addDocument(doc);
indexWriter.commit();
indexWriter.optimize();
indexReader.reopen();
indexSearcher = new IndexSearcher(indexReader);
so that a new indexSearcher would be used after the writer has added new
documents [obviously this is NOT optimized :) but I'm just trying to get
the core functionality down first] and that still didn't work. The idea
gave me a different thing to try though-- I created a brand new
indexSearcher from the FSDirectory and that searcher worked excellent.
Not sure why reopen and creating a new searcher wouldn't work, but I'll
look into it a little more and hopefully be able to figure something out.
Thanks!
balasubramanian sudaakeran wrote:
Hi Eric LeVin,
I think whenever you reopen the indexReader you have to re-create indexSearcher
also. This is because reopen of indexReader will give you a new instance if the
underlying data is changed.
Function documentation for IndexReader.reopen
* If the index has not changed since this instance was (re)opened, then this
* call is a NOOP and returns this instance. Otherwise, a new instance is
* returned. The old instance is <b>not</b> closed and remains usable.<br>
* <b>Note:</b> The re-opened reader instance and the old instance might share
* the same resources. For this reason no index modification operations
* (e. g. {...@link #deleteDocument(int)}, {...@link #setNorm(int, String, byte)})
* should be performed using one of the readers until the old reader instance
* is closed. <b>Otherwise, the behavior of the readers is undefined.</b>
* <p>
----- Original Message ----
From: Eric LeVin <ejlevin1....@gmail.com>
To: java-user@lucene.apache.org
Sent: Monday, May 18, 2009 7:30:47 PM
Subject: Problems searching index
Hi Everyone--
So I'm not quite sure what is going on with my Lucene index, but I'm having
some issues searching. I've created a simple little index of 10 documents as
follows:
id: 1
type: Article
content: <<some content>>
....
id: 10
type: Article
content: <<other content>>
So I created a simple TermQuery for starters that would pull back all of my
Article types:
BooleanQuery bq = new BooleanQuery();
bq.add(new TermQuery(new Term(FIELD_TYPE, "Article")), Occur.MUST);
I realize that I could simply do a TermQuery, but I want to be able to add
additional content constraints after I get this working. So here is where my
confusion comes in:
If I run the query against my IndexSearcher, I get 0 results; however, if I run
it as a delete on the IndexWriter, I can open it in Luke and see the entire
index deleted. So why would the writer be finding documents and the searcher
wouldn't? As a note, whenever I am adding documents, I am calling reopen() on
the reader. Here is how I'm creating the writer/reader/searcher:
KeywordAnalyzer ka = new KeywordAnalyzer();
analyzer.addAnalyzer(FIELD_ID, ka);
analyzer.addAnalyzer(FIELD_TYPE, ka);
analyzer.addAnalyzer(FIELD_CONTENT, contentAnalyser);
indexWriter = new IndexWriter(directory, analyzer, true,
MaxFieldLength.UNLIMITED);
indexReader = IndexReader.open(directory);
indexSearcher = new IndexSearcher(indexReader);
Any thoughts? Thanks so much for all the help!
-Eric LeVin
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org