0
votes

Someone has an idea, how to load fields lazy by lucene searcher? I don't get it...

My Lucene-Indexs' Documents contains fields like this:

  • UF1: Unstored Field 1
  • UF2: Unstored Field 2
  • ...: Some other unstored Fields
  • SF1 - Stored Field 1
  • SF2 - Stored Field 2 -> But this one has very very much text

So now I'm searching on the index. When I get very much result docs, it seems, that all content in SF2 is beeing loaded by lucene, so RAM goes up very very fast. But, the only field I need to get by this search is SF1. SF2 will never be used by this search.

Is it possible to exclude that special Field "SF2" from beeing loaded into the resulting Documents.

// Some initializing and query preparing...
final IndexSearcher searcher = new IndexSearcher(this.getReader());
TopDocs hits = searcher.search(query, maxResults);
ScoreDoc[] scoreDocs = hits.scoreDocs;
for (final ScoreDoc score : scoreDocs) {
    final Document document = searcher.doc(score.doc);
    final String value = document.get("SF1"); // <-- This is the only needed field of result doc
    // collecting value ...
}

edit: Lucene 4.1 Java-API

1

1 Answers

2
votes

Both IndexReader and IndexSearcher have method .document(int docID, Set<String> fieldsToLoad) where you can specify which fields do you want to load.

Simply use that and exclude what is not necessary.