Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 61624 invoked from network); 13 May 2010 10:16:05 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 May 2010 10:16:05 -0000 Received: (qmail 12636 invoked by uid 500); 13 May 2010 10:16:02 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 12544 invoked by uid 500); 13 May 2010 10:16:02 -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 12536 invoked by uid 99); 13 May 2010 10:16:02 -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 10:16:02 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,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 ian.lea@gmail.com designates 72.14.220.157 as permitted sender) Received: from [72.14.220.157] (HELO fg-out-1718.google.com) (72.14.220.157) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 May 2010 10:15:55 +0000 Received: by fg-out-1718.google.com with SMTP id e12so740426fga.5 for ; Thu, 13 May 2010 03:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=so47pEqcDZgG3RhinNwPIsKEAIbYXqLo0XjPx//pzvY=; b=adBFaimJCCELyamusxYzE31DudmeISUJH5QoYIgdIdCGv/fJTT4e3x1DUIru/yi69P PmHx9CZkn3m4yUUyaj4MyiEehnr4CFQ2reEU+vvvlJ+VhbB8nPZeybM+xWlqxOOvSPO/ JH+wW3JQYxJIA1lYsl8SaCJy5c04togw9aTow= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=JlDJo1kgUEih71+GLAlRI4djUu5fTgFzlrDCMhKj/N2UEqYrTsTf7YV6iB3KbIev/0 onI+C3VXGsoos5M3fo3owJ1Dz4EhLexKZDNMPDLQSOOxSewqW3m/vnO40NLxYgwSRt9D if+H6DnDSWSXunyZ/aTEAWzIqyePeYPi/hH5Q= Received: by 10.204.5.65 with SMTP id 1mr91708bku.214.1273745734263; Thu, 13 May 2010 03:15:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.54.198 with HTTP; Thu, 13 May 2010 03:15:14 -0700 (PDT) In-Reply-To: References: From: Ian Lea Date: Thu, 13 May 2010 11:15:14 +0100 Message-ID: Subject: Re: Error of the code To: java-user@lucene.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable You need to replace this: TermFreqVector vector =3D IndexReader.getTermFreqVector(0, "fieldname" ); with IndexReader ir =3D whatever(...); TermFreqVector vector =3D 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 follow= ing > 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: > > =A0*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 =3D *new* StandardAnalyzer(Version.*LUCENE_CURR= ENT* > ); > > *try* { > > Directory directory =3D *new* RAMDirectory(); > > IndexWriter iwriter =3D *new* IndexWriter(directory, analyzer, > *true*,*new*IndexWriter.MaxFieldLength(25000)); > > Document doc =3D *new* Document(); > > String text =3D "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 =3D IndexReader.getTermFreqVector(0, "fieldname" ); > * > > int* size =3D vector.size(); > > *for* ( String term : vector.getTerms() ) > > System.*out*.println( "size =3D " + size ); > > iwriter.close(); > > IndexSearcher isearcher =3D *new* IndexSearcher(directory, *true*); > > QueryParser parser =3D *new* QueryParser(Version.*LUCENE_CURRENT*, "field= name", > analyzer); > > Query query =3D parser.parse("text"); > > ScoreDoc[] hits =3D isearcher.search(query, *null*, 1000).scoreDocs; > > System.*out*.println("hits.length(1) =3D " + hits.length); > > // Iterate through the results: > > *for* (*int* i =3D 0; i < hits.length; i++) { > > Document hitDoc =3D isearcher.doc(hits.doc); > > System.*out*.println("hitDoc.get(\"fieldname\") (This is the text to be > indexed) =3D " + > > 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