yes, it's less efficient. Lucene database has multiple segments, each
segment can treat as a independent database. The same term may exists in >=
1 segments.
Xapian::TermIterator it = db_in.allterms_begin();
This method traverse all terms in the first segment, then the second
segment, until the last segment.

it_pl = db_in.postlist_begin(*it);
But this method LuceneDatabase::postlist_begin will find all postlists for
a particular term in all segments.

If doing like this, each postlist will be traversed multiple times, so I
write another method LucenePostIterator,
which only traverse the postlist in the current segment, avoid duplicate
traverse.

Actually, I think LucenePostIterator is not quite approriate, it makes
users confused:
why do we have both LucenePostList and LucenePostIterator?


Some ideas:
1. Ignoring the efficience, using the method you suggest.
2. Add a branch in LuceneDatabase::open_post_list(string term_name), this
branch code only open a postlist in current segment which contains the
current visiting term.
Code may like this:
if (true == traverse_mode) {
// open one postlist in current segment. segments[i] means the current
segment which is visiting
postlist = segments[i].open_post_list(term_name);
postlists.merge(postlist);
} else {
// ignoring efficience, open postlists in all segments for the term
for (int i = 0; i < segments.size; i++) {
postlist = segment[i].open_post_list(term_name);
postlists.merge(postlist);
}
}


*You don't need an extra method for that - you can do that iteration like
so:*
* *

*    it_pl = db_in.postlist_begin(*it);
    while (it_pl != db_in.postlist_end(*it)) {*

* *

*Perhaps that's less efficient, though maybe that's solvable. I don't
really follow the code here though - why do we have both LucenePostList and
LucenePostIterator?*


2013/10/17 Olly Betts <notifications@github.com>

> In xapian-core/api/termiterator.cc:
>
> > +TermIterator::postlist_begin() const
> > +{
> > +    LOGCALL(API, PostingIterator, "TermIterator::postlist_begin", NO_ARGS);
> > +    Assert(internal);
> > +    RETURN(internal->postlist_begin());
> > +}
> > +
> > +std::string
> > +TermIterator::get_termname() const
> > +{
> > +    LOGCALL(API, std::string, "TermIterator::get_termname()", NO_ARGS);
> > +    Assert(internal);
> > +    RETURN(internal->get_termname());
> > +}
> > +#endif
> > +
>
> You don't need an extra method for that - you can do that iteration like
> so:
>
>     it_pl = db_in.postlist_begin(*it);
>     while (it_pl != db_in.postlist_end(*it)) {
>
> Perhaps that's less efficient, though maybe that's solvable. I don't
> really follow the code here though - why do we have both LucenePostListand
> LucenePostIterator?
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/xapian/xapian/pull/25/files#r7029552>
> .
>