FAQ
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

Search Discussions

  • Karl wettin at May 9, 2006 at 6:24 pm

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedMay 9, '06 at 5:53p
activeMay 9, '06 at 6:24p
posts2
users2
websitelucene.apache.org

2 users in discussion

Karl wettin: 1 post Varun sood: 1 post

People

Translate

site design / logo © 2022 Grokbase