Unexpected TermEnum behavior

2004-12-08 Thread Alexey Lef
My application needs to enumerate all terms for a specific field. To do that
I get the TermEnum using the following code:

TermEnum terms = reader.terms(new Term(fieldName, ));

I noticed that initially TermEnum is positioned at the first term. In other
words, I don't have to call terms.next() before calling terms.term(). This
is different from the behavior of Iterator,  Enumeration and ResultSet whose
initial position is before the first result. I wonder whether it is this way
by design.

If it is by design, what is the defined TermEnum behavior if there are no
terms for the field name in question? Will the call to terms.term() return
null? Or get positioned at the first term with the field name that comes
after the provided field name? What if there are no field names after it?

In any case, some javadoc describing the behavior would be extremely useful.
Being used to Iterators and ResultSets, I automatically wrote the code the
same way, calling next() first. Fortunately, I had a field with only 2
terms, that's why I noticed that I am missing the first element.

Thanks,

Alexey


Re: Unexpected TermEnum behavior

2004-12-08 Thread Chris Hostetter
:   TermEnum terms = reader.terms(new Term(fieldName, ));
:
: I noticed that initially TermEnum is positioned at the first term. In other
: words, I don't have to call terms.next() before calling terms.term(). This
: is different from the behavior of Iterator,  Enumeration and ResultSet whose

Well, strictly speeking it's very different -- in particular, the next
method doesn't return the item, which is also very different from
Iterators and Enumeration.

I agree it's a little confusing, esecially since TermDocs and TermEnum are
different.

: If it is by design, what is the defined TermEnum behavior if there are no
: terms for the field name in question? Will the call to terms.term() return
: null? Or get positioned at the first term with the field name that comes
: after the provided field name? What if there are no field names after it?

I believe that in those cases, the TermEnum object itself will be null.

: In any case, some javadoc describing the behavior would be extremely useful.

I thought it was documented in the TermEnum interface, but looking at it
now I realize that not only does the TermEnum javadoc not explain it
very well, but the class FilteredTermEnum (which implements TermEnum)
acctually documents the oposite behavior...

  public Term term()

  Returns the current Term in the enumeration. Initially
  invalid, valid  after next() called for the first time.


-Hoss


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



Re: Unexpected TermEnum behavior

2004-12-08 Thread Morus Walter
Chris Hostetter writes:
 
 I thought it was documented in the TermEnum interface, but looking at it
 now I realize that not only does the TermEnum javadoc not explain it
 very well, but the class FilteredTermEnum (which implements TermEnum)
 acctually documents the oposite behavior...
 
   public Term term()
 
   Returns the current Term in the enumeration. Initially
   invalid, valid  after next() called for the first time.
 
That's a documentation bug. Fixed in CVS.

http://issues.apache.org/bugzilla/show_bug.cgi?id=32353

Morus

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