Retrieving field or Document using document id.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Retrieving field or Document using document id.

varun sood
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
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving field or Document using document id.

Karl Wettin-3
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: [hidden email]
For additional commands, e-mail: [hidden email]