Hey there, On Tue, Jun 30, 2009 at 10:41 AM, <m.ha...@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 > > } > >