You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by varun sood <vs...@gmail.com> on 2006/05/09 19:53:09 UTC
Retrieving field or Document using document id.
Hi,
I have "Doc. Id" of the document stored in the database. Now I want to
query database on that "Doc. Id" (which will always return one document).
How can I do this?
To avoid confusion, I am talking about the "Doc. Id" which Lucene
automatically creates for every document and hence is unique for every
Document.
String Database = null;
QueryParser queryParser = new QueryParser("Doc. Id",new
WhitespaceAnalyzer());
Query query;
Hits hits;
try {
query = queryParser.parse(String.valueOf(docIDs[i]));
hits = searcher.search(query);
Document doc = hits.doc(0);
Database = doc.get("title");
} catch (ParseException e) {
e.printStackTrace();
}
Kindly suggest me.
Thanks
Re: Retrieving field or Document using document id.
Posted by karl wettin <ka...@snigel.net>.
On Tue, 2006-05-09 at 13:53 -0400, varun sood wrote:
> Hi,
> I have "Doc. Id" of the document stored in the database. Now I want to
> query database on that "Doc. Id" (which will always return one document).
> How can I do this?
Are you aware that the document number created by Lucene is considered
be unsafe?
This is how you do it:
IndexReader ir = IndexReader.open(directory);
ir.document(7);
See:
class IndexReader {
/**
* Returns the stored fields of the n:th Document
* in this index.
*/
public abstract Document document(int n) throws IOException;
}
> QueryParser queryParser = new QueryParser("Doc. Id",new
You can not send a document number to the QueryParser.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org