<<<can you please tune my code to work it faster and better>>>
Are you willing to pay me to do your job for you? Sorry to besnarky, but please be aware that we're volunteers here, it's pretty presumptuous to ask for this. You still haven't answered what it is you're trying to do. Why are you collecting 1,000 titles? What's the purpose? Are you just experimenting? Because I don't understand your use-case. There's no point in trying to make code efficient unless you're trying to solve a real problem. *Of course* you'll see memory grow until the garbage collector kicks in. This is what java does. System.out.printlns are pretty slow. First queries are slow. So unless and until you clearly state the problem you're trying to solve, there's not much we can do. Best Erick On Tue, Jun 30, 2009 at 8:38 AM, m.harig <m.ha...@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")); > > } > > 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-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org > >