[Xapian-discuss] TermIterator question

Zhiguo Li zhiguo.li at gmail.com
Thu Nov 13 17:24:00 GMT 2008


Hi, Olly,

Thanks a lot for the help. This discuss group is really helpful for 
playing with Xapian. Guess I would have a lot more to learn about C++.

Kevin

Olly Betts wrote:
> 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