
simon.willnauer at googlemail
Jun 30, 2009, 7:22 AM
Post #7 of 7
(420 views)
Permalink
|
On Tue, Jun 30, 2009 at 3:21 PM, Ian Lea<ian.lea[at]gmail.com> wrote: > Have you read the javadocs? What does collector.getTotalHits() return? > Â Does it return the same when you use new TopDocCollector(1000) and > some other number? Â Are you asking basically the same questions in 2 > different threads at the same time? > > You are still iterating over many hits and that will still take longer > than if you iterate over fewer hits. > > > -- > Ian. > > > > > On Tue, Jun 30, 2009 at 1:38 PM, m.harig<m.harig[at]gmail.com> wrote: >> >> Thanks eric >> >> in Ian's link, particularly see the section "Don't iterate over morehits >> than necessary". >> >> A couple of other things: >> 1> Loading the entire document just to get a field or two isn't >> Â Â very efficient, think about lazy loading (See FieldSelector) >> Â i done it , but have couple of questions >> >> 2> What do you mean when you say "not very good"? Using too >> Â Â Â much memory? Slow? >> Â yes , of course , it went for java heap space . >> >> >> here is my code >> >> Â Â Â Â Â Â Â Â IndexReader open = IndexReader.open(indexDir); >> Â Â Â Â Â Â Â Â IndexSearcher searcher = new IndexSearcher(open); >> Â Â Â Â Â Â Â Â final String fName = "title"; >> Â Â Â Â Â Â Â Â QueryParser parser = new QueryParser("contents", new StopAnalyzer()); >> Â Â Â Â Â Â Â Â Query query = parser.parse(qryStr); >> >> Â Â Â Â Â Â Â Â TopDocCollector collector = new TopDocCollector(1000);// >> Â Â Â Â Â Â Â Â searcher.search(query, collector); >> >> Â Â Â Â Â Â Â Â FieldSelector selector = new FieldSelector() { >> Â Â Â Â Â Â Â Â Â Â Â Â public FieldSelectorResult accept(String fieldName) { >> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return fieldName == fName ? FieldSelectorResult.LOAD >> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â : FieldSelectorResult.LAZY_LOAD; >> Â Â Â Â Â Â Â Â Â Â Â Â } >> >> >> Â Â Â Â Â Â Â Â }; >> >> Â Â Â Â Â Â Â Â final int totalHits = collector.getTotalHits(); >> Â Â Â Â Â Â Â Â ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs; >> >> >> Â Â Â Â Â Â Â Â for (int i = 0; i < totalHits; i++) { >> Â Â Â Â Â Â Â Â Â Â Â Â Document doc = searcher.doc(scoreDocs[i].doc, selector); >> >> Â Â Â Â Â Â Â Â Â Â Â Â System.out.println(i+" ) "+doc.get("title")); >> Â Â Â Â Â Â Â Â Â Â Â Â System.out.println(doc.get("path")); >> >> Â Â Â Â Â Â Â Â } funny that you past the code I did send you as an example and ask in a separate thread for tuning :D simon >> >> can you please tune my code to work it faster and better, Â is it possible to >> display total hits like google , since am using new TopDocCollector(1000); >> it won't allow you to pick total hits ?? am i right??? >> >> -- >> View this message in context: http://www.nabble.com/optimized-searching-tp24266553p24271145.html >> Sent from the Lucene - Java Users mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: java-user-unsubscribe[at]lucene.apache.org >> For additional commands, e-mail: java-user-help[at]lucene.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe[at]lucene.apache.org > For additional commands, e-mail: java-user-help[at]lucene.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe[at]lucene.apache.org For additional commands, e-mail: java-user-help[at]lucene.apache.org
|