Hi All,
Was doing some tests on my system, retrieving documents based on the document id. I
was testing the negative case where I passed in an invalid id (which, admittedly,
would be hard to do b/c of other protections in my code, but...) to
IndexReader.document() and I was getting back a valid document, namely the 0th
document in the index.
Here is the test case for IndexReader that I tried:
public void testDocument() throws IOException {
RAMDirectory d = new RAMDirectory();
// set up writer
IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(), true);
addDocumentWithFields(writer);
writer.close();
// set up reader
IndexReader reader = IndexReader.open(d);
Document doc = reader.document(0);
assertTrue(doc != null); //works
assertTrue(doc.getField("keyword").stringValue().equals("test1")); //works
try
{
doc = reader.document(1000000000);
assertTrue(false);
}
catch (IOException e)
{
assertTrue(true); //works
}
doc = reader.document(1000);
assertTrue(doc == null); // !!!!!!!!!!!! This fails
}
The documentation does not say what should happen when _n_ is not a valid document
number, however, I wouldn't expect it to return a valid document. The issue is that
the document() method does not fail gracefully in my opinion.
I am not 100% sure of the issue, but it appears to stem from the FieldsReader.doc code
in that somehow the position gets set to 0.
Thanks,
Grant
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]