[Xapian-discuss] TermIterator question
Olly Betts
olly at survex.com
Thu Nov 13 11:59:54 GMT 2008
On 13/11/2008, zhiguo li <zhiguo.li at gmail.com> wrote:
> I would like to have two term iterators to go over the list of terms like
> the following:
>
> for (t1 = query.get_terms_begin(); t1 != query.get_terms_end(); t1++)
>
> for (t2=t1+1; t2 != query.get_terms_end(); t2++)
>
> {
>
> do something terms pointed by t1 and t2...
>
> }
>
> When I tried the above, I got error since I cannot perform t2 = t1 + 1 or t2
> = ++t1.
You can't useful copy a TermIterator like this, since it what the C++ STL terms
an "input iterator" - advancing it invalidates any copies at the old position.
Instead write the inner loop as:
TermIterator t2 = query.get_terms_begin();
t2.skip_to(*t1);
if (t2 != query.get_terms_end()) ++t2;
for ( ; t2 != query.get_terms_end(); ++t2) {
// ...
}
Or take a copy of the terms in your own data structure and work from that.
Cheers,
Olly
More information about the Xapian-discuss
mailing list