I don't know why the termDocs option did not work for you. Perhaps you did
not (re)open the searcher after the index was populated?  Anyhow, here is a
small code snippet that does just this, see if it works for you, then you
can compare it to your code...

  void numberOfTermOcc() throws Exception {
    System.out.println("======== populate index");
    RAMDirectory dir = new RAMDirectory();
    IndexWriter iw = new IndexWriter(dir,
                                     new StandardAnalyzer(),true);
    for (int i = 0; i < 10; i++) {
      Document doc = new Document();
      for (int j = 0; j < 10; j++) {
        doc.add(new Field("field_"+(i+j), "value_"+(i+j),
                          Field.Store.NO, Field.Index.TOKENIZED));
        doc.add(new Field("field_"+(i+j), "value_"+(i+j),
                          Field.Store.NO, Field.Index.TOKENIZED));
        doc.add(new Field("field_"+(i+j), "value_"+(i+j+1),
                          Field.Store.NO, Field.Index.TOKENIZED));
      }
      iw.addDocument(doc);
    }
    iw.close();

    IndexReader ir = IndexReader.open(dir);
    printTermDocs(ir, new Term("field_7","value_7"));
    printTermDocs(ir, new Term("field_7","value_8"));
  }

  void printTermDocs(IndexReader ir, Term t) throws IOException {
    System.out.println("========= iterate docs for "+t);
    TermDocs td = ir.termDocs(t);

    while (td.next()) {
      System.out.println("term frequency in doc "+td.doc()+
                         " is: "+ td.freq());
    };
  }

"beatriz ramos" <[EMAIL PROTECTED]> wrote on 24/10/2006
02:24:47:

> Hi, thanks for all your answers, but they don't work
>
> I have tried the 3 options and with all of them we get termDoc = 0
> I have checked my index with Luke software and termDoc is 1 here, so my
> index is correct.
>
> is it possible I have a problem with the reader? (because my index is
> allright)
>
> Thanks
>
> (when I talk about termDocs, it means number of documents in which term
> appears)
>
>
>
> On 24/10/06, Grant Ingersoll <[EMAIL PROTECTED]> wrote:
> >
> > You can also use Term Vectors, at the cost of extra storage.  Search
> > this list for Term Vectors for info on how to implement.
> >
> > On Oct 23, 2006, at 5:50 AM, beatriz ramos wrote:
> >
> > > Hello,
> > > I´m working with Lucene. I need to get the number of occurrences of
> > > the term
> > > in the document. I had seen the documentations ant I don´t find
> > > anything.
> > > Do you have any idea?
> > > Thanks.
> >
> > --------------------------
> > Grant Ingersoll
> > Sr. Software Engineer
> > Center for Natural Language Processing
> > Syracuse University
> > 335 Hinds Hall
> > Syracuse, NY 13244
> > http://www.cnlp.org
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to