On Wed, Dec 8, 2010 at 2:43 PM, Erick Erickson <erickerick...@gmail.com> wrote: > I don't think this code is doing anything predictable. From the javadocs for > TermDocs.skipTo(): > Skips entries to the first beyond the current whose document number is > greater than or equal to *target*. > > Returns true iff there is such an entry. > You're not testing the return value from skipTo. The document IDs returned > in scoredocs aren't necessarily in ascending doc ID order so I'd guess > that skipTo is returning false a lot of the time and in that case you're > getting > the frequency of a doc that isn't in your result set.
Well I didn't even got that far in the code man :D > > Best > Erick > > > On Wed, Dec 8, 2010 at 12:33 AM, Ranjit Kumar <ranjit.ku...@otssolutions.com >> wrote: > >> Hi, >> Thanks for your replay!!! >> Below is code I am using for search >> String line="sql server"; >> IndexReader reader = IndexReader.open(FSDirectory.open(new >> File(indexpath)), true); // contains index file path >> Searcher searcher = new IndexSearcher(reader); >> Analyzer analyzer = new >> StandardAnalyzer(Version.LUCENE_CURRENT); >> QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field, >> analyzer); >> if (line != null) { >> line = line.trim(); >> Query query = parser.parse(line); >> int n = 100; >> TopDocs docs = searcher.search(query, n); >> TermDocs termDocs = reader.termDocs(new Term(field, line. >> toLowerCase())); >> System.out.println(" " + docs.totalHits + " total matching >> documents\n"); >> for (int i = 0; i < docs.scoreDocs.length; i++) { >> int totalFreq = 0; >> Document document = >> reader.document(docs.scoreDocs[i].doc); >> termDocs.skipTo(i); >> String path = document.get("path"); >> System.out.println("path>>" + path); >> totalFreq = termDocs.freq(); >> System.out.println("totalFreq >>" + totalFreq); >> } >> >> } >> >> >> Thanks & Regards, >> Ranjit Kumar >> =================================================================================================== >> Private, Confidential and Privileged. This e-mail and any files and >> attachments transmitted with it are confidential and/or privileged. They are >> intended solely for the use of the intended recipient. The content of this >> e-mail and any file or attachment transmitted with it may have been changed >> or altered without the consent of the author. If you are not the intended >> recipient, please note that any review, dissemination, disclosure, >> alteration, printing, circulation or Transmission of this e-mail and/or any >> file or attachment transmitted with it, is prohibited and may be unlawful. >> If you have received this e-mail or any file or attachment transmitted with >> it in error please notify OTS Solutions at >> i...@otssolutions.com=================================================================================================== >> > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org