Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 88684 invoked from network); 13 May 2010 12:17:06 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 May 2010 12:17:06 -0000 Received: (qmail 19144 invoked by uid 500); 13 May 2010 12:17:04 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 19088 invoked by uid 500); 13 May 2010 12:17:03 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 19080 invoked by uid 99); 13 May 2010 12:17:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 May 2010 12:17:03 +0000 X-ASF-Spam-Status: No, hits=4.2 required=10.0 tests=AWL,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of manjula53@gmail.com designates 209.85.212.176 as permitted sender) Received: from [209.85.212.176] (HELO mail-px0-f176.google.com) (209.85.212.176) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 May 2010 12:16:56 +0000 Received: by pxi10 with SMTP id 10so784441pxi.35 for ; Thu, 13 May 2010 05:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=ZE5s/QU2n4LszxD0RF7+Dh0Dtlg2oP5jul5AeaVV7sM=; b=jJSKhNEIPJXuDDPBDsKM/wUwuD+zDy7MGig82KB7KHL1EzztorCSAWc8G3+QEb39F0 KZQGavWZCqMNDl6lfbO6Mtw+AlhBo0dpyrrK99aGcjpCa2+gnmC+/O1xAjS+R/gk4Icr dgfgkBc+sT5ySVPUVd0rnlVspmIXIvisxpPwc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=onOZiMTLx+t6pW0Oe0f06KDdYll3zMvdGY8csEc/c5nj/QfGUTD0YhqFI99wjNeZ4r ++jbMAK3ubNxE47pcZO5URRs6WFjTYM/HxHW82qo4nBFTn3sD9vQ+xjs8p4b5LHKMcYr CVX81DwMhoKKQk1KPXB9niWVgwB578A1LcfYc= MIME-Version: 1.0 Received: by 10.141.213.36 with SMTP id p36mr6206542rvq.5.1273752996679; Thu, 13 May 2010 05:16:36 -0700 (PDT) Received: by 10.140.147.1 with HTTP; Thu, 13 May 2010 05:16:36 -0700 (PDT) In-Reply-To: References: Date: Thu, 13 May 2010 17:46:36 +0530 Message-ID: Subject: Re: Error of the code From: manjula wijewickrema To: java-user@lucene.apache.org Content-Type: multipart/alternative; boundary=000e0cd1b72ae6104e048678ba2c --000e0cd1b72ae6104e048678ba2c Content-Type: text/plain; charset=ISO-8859-1 Dear Ian, Thanks a lot for your immediate reply. As you have mentioned I replaced the lines as follows. IndexReader ir=IndexReader.open(directory); TermFreqVector vector=ir.getTermFreqVector(0,"fieldname"); Now the error has been vanished and thanks for it. But I can't still see the results although I have moved those lines after iwriter.close(). What's the reason for this? sample code after modifications: ......................... ........................ String text = "This is the text to be indexed."; doc.add(*new* Field("fieldname", text, Field.Store.*YES*,Field.Index.* ANALYZED*,Field.TermVector.*WITH_POSITIONS_OFFSETS*)); iwriter.addDocument(doc); iwriter.close(); IndexReader ir=IndexReader.open(directory); TermFreqVector vector=ir.getTermFreqVector(0,"fieldname"); * int* size = vector.size(); *for* ( String term : vector.getTerms() ) System.*out*.println( "size = " + size ); IndexSearcher isearcher = *new* IndexSearcher(directory, *true*); .......... .......... I appreciate your kind coperation Manjula On Thu, May 13, 2010 at 3:45 PM, Ian Lea wrote: > You need to replace this: > > TermFreqVector vector = IndexReader.getTermFreqVector(0, "fieldname" ); > > with > > IndexReader ir = whatever(...); > TermFreqVector vector = ir.getTermFreqVector(0, "fieldname" ); > > And you'll need to move it to after the writer.close() call if you > want it to see the doc you've just added. > > > > -- > Ian. > > > > On Thu, May 13, 2010 at 11:07 AM, manjula wijewickrema > wrote: > > Dear All, > > > > I am trying to get the term frequencies (through TermFreqVector) of a > > document (using Lucene 2.9.1). In order to do that I have used the > following > > code. But there is a compile time error in the code and I can't figure it > > out. Could somebody can guide me what's wrong with it. > > Compile time error I got: > > Cannot make a static reference to the non-static method > > getTermFreqVector(int, String) from the type IndexReader. > > > > Code: > > > > *import* org.apache.lucene.analysis.standard.StandardAnalyzer; > > > > *import* org.apache.lucene.document.Document; > > * > > > > import* org.apache.lucene.document.Field; > > * > > > > import* org.apache.lucene.index.IndexWriter; > > * > > > > import* org.apache.lucene.queryParser.ParseException; > > * > > > > import* org.apache.lucene.queryParser.QueryParser; > > * > > > > import* org.apache.lucene.search.*; > > * > > > > import* org.apache.lucene.store.Directory; > > * > > > > import* org.apache.lucene.store.RAMDirectory; > > * > > > > import* org.apache.lucene.util.Version; > > > > * > > > > import* org.apache.lucene.index.IndexReader; > > * > > > > import* org.apache.lucene.index.TermEnum; > > * > > > > import* org.apache.lucene.index.Term; > > * > > > > import* org.apache.lucene.index.TermFreqVector; > > > > * > > > > import* java.io.IOException; > > * > > > > public* *class* DemoTest { > > > > *public* *static* *void* main(String[] args) { > > > > StandardAnalyzer analyzer = *new* > StandardAnalyzer(Version.*LUCENE_CURRENT* > > ); > > > > *try* { > > > > Directory directory = *new* RAMDirectory(); > > > > IndexWriter iwriter = *new* IndexWriter(directory, analyzer, > > *true*,*new*IndexWriter.MaxFieldLength(25000)); > > > > Document doc = *new* Document(); > > > > String text = "This is the text to be indexed."; > > > > doc.add(*new* Field("fieldname", text, Field.Store.*YES*,Field.Index.* > > ANALYZED*,Field.TermVector.*WITH_POSITIONS_OFFSETS*)); > > > > iwriter.addDocument(doc); > > > > TermFreqVector vector = IndexReader.getTermFreqVector(0, "fieldname" ); > > * > > > > int* size = vector.size(); > > > > *for* ( String term : vector.getTerms() ) > > > > System.*out*.println( "size = " + size ); > > > > iwriter.close(); > > > > IndexSearcher isearcher = *new* IndexSearcher(directory, *true*); > > > > QueryParser parser = *new* QueryParser(Version.*LUCENE_CURRENT*, > "fieldname", > > analyzer); > > > > Query query = parser.parse("text"); > > > > ScoreDoc[] hits = isearcher.search(query, *null*, 1000).scoreDocs; > > > > System.*out*.println("hits.length(1) = " + hits.length); > > > > // Iterate through the results: > > > > *for* (*int* i = 0; i < hits.length; i++) { > > > > Document hitDoc = isearcher.doc(hits.doc); > > > > System.*out*.println("hitDoc.get(\"fieldname\") (This is the text to be > > indexed) = " + > > > > hitDoc.get("fieldname")); > > > > } > > > > isearcher.close(); > > > > directory.close(); > > > > } *catch* (Exception ex) { > > > > ex.printStackTrace(); > > > > } > > > > } > > > > } > > > > > > > > Thanks in advance > > > > Manjula > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > For additional commands, e-mail: java-user-help@lucene.apache.org > > --000e0cd1b72ae6104e048678ba2c--