lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Willnauer <simon.willna...@googlemail.com>
Subject Re: Read large size index
Date Tue, 30 Jun 2009 09:19:07 GMT
Hey there,

On Tue, Jun 30, 2009 at 10:41 AM, <m.harig@gmail.com> wrote:
> Thanks Simon
>
>  this is my code , but am getting null ,
>
> IndexReader open = IndexReader.open(indexDir);
>
>                IndexSearcher searcher = new IndexSearcher(open);
>
>                final String fName = "contents";
>
>                QueryParser parser = new QueryParser(fName, new StopAnalyzer());
>            Query query = parser.parse(qryStr);
>
sorry I was used to 2.4 searcher which has an overloaded method
without a filter.
>                TopDocs topDocs = searcher.search(query, (Filter) null,
>                                500);// am getting negative array exception
if i use Integer.MAX_VALUE;
> //
Sry that was my fault! I did not execute the code at all.  :)
>
>                FieldSelector selector = new FieldSelector() {
>                        public FieldSelectorResult accept(String fieldName)
{
>                                return fieldName == fName ? FieldSelectorResult.LOAD
>                                                : FieldSelectorResult.NO_LOAD;
>                        }
>
>                };
While comparing strings with == is bad practice (my fault again) this
code only loads the field fname / "contents" any other field is not
loaded at all. you have to modify the selector code to your needs,
meaning that you return LOAD or LAZY or whatever for all fields you
need when displaying the results.
>
>
>                int totalHits = topDocs.totalHits;
>                ScoreDoc[] scoreDocs = topDocs.scoreDocs;
>
>                System.out.println(totalHits);
>
>                for (int i = 0; i < totalHits; i++) {
>                        Document doc = open.document(i,selector);//searcher.doc(scoreDocs[i].doc,
selector);
>
>                        System.out.println(doc.get("path"));/// am getting
null here
This whole code loads only the field called "content" if you now
request field "path" you get null as it is not loaded.

simon
>
>                }
>
>
Mime
View raw message