FAQ
Hi.
I have a question about retrieving information.
Lets say I have an index which contents a millions of documents with 2-3
small fields an a 10 large fields.
Then I run a query which returns me a 1000 of hits. But I am interested
only one small field, and I don't want to load other fields.

Can I do something like what?

int id = hits.id(n);

FieldSelector fieldSelector = new FieldSelector() {
public FieldSelectorResult accept(String fieldName) {
if(fieldName.equals(field))
return FieldSelectorResult.LOAD_AND_BREAK;
return FieldSelectorResult.NO_LOAD;
}
};

Document doc = reader.document(id, fieldSelector);
if(doc == null)
throw new IOException("Document with id "+id+" not found");
return doc.get(field);

n from 0 to hits.length().

Best regards,
Sergey

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org

Search Discussions

  • Grant Ingersoll at Mar 7, 2008 at 12:11 pm
    You sure can. Or you can use the SetBasedFieldSelector that already
    exists in o.a.lucene.document.

    -Grant
    On Mar 7, 2008, at 5:26 AM, Sergey Kabashnyuk wrote:

    Hi.
    I have a question about retrieving information.
    Lets say I have an index which contents a millions of documents with
    2-3 small fields an a 10 large fields.
    Then I run a query which returns me a 1000 of hits. But I am
    interested only one small field, and I don't want to load other
    fields.

    Can I do something like what?

    int id = hits.id(n);

    FieldSelector fieldSelector = new FieldSelector() {
    public FieldSelectorResult accept(String fieldName) {
    if(fieldName.equals(field))
    return FieldSelectorResult.LOAD_AND_BREAK;
    return FieldSelectorResult.NO_LOAD;
    }
    };

    Document doc = reader.document(id, fieldSelector);
    if(doc == null)
    throw new IOException("Document with id "+id+" not found");
    return doc.get(field);

    n from 0 to hits.length().

    Best regards,
    Sergey

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
    --------------------------
    Grant Ingersoll
    http://www.lucenebootcamp.com
    Next Training: April 7, 2008 at ApacheCon Europe in Amsterdam

    Lucene Helpful Hints:
    http://wiki.apache.org/lucene-java/BasicsOfPerformance
    http://wiki.apache.org/lucene-java/LuceneFAQ






    ---------------------------------------------------------------------
    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
postedMar 7, '08 at 10:26a
activeMar 7, '08 at 12:11p
posts2
users2
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase