Hey there, so let me quickly explain what is going on here. you search for: sql server (without quotes) which QueryParser will turn into a BooleanQuery like sql OR server since the StandardAnalyzer you are using splits on whitespaces. That query will return all document either containing sql or server. So far so good. If you want to do a phrase search you should put the terms into quotes like that: String line = "\"sql server\"";
Next you are trying to get the term frequency for "sql server" as a single term which does not exist in your index since you used StandardAnalyzer during indexing which again splits your text on white-spaces. This will likely return 0 all the time ey? hope that helps On Wed, Dec 8, 2010 at 6: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