Hi, 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. Any suggestions? I apperaciate your help! Kevin
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
Please send email to the list, not me directly. That way other people can help too, and the discussion is archived in a publicly searchable form. 2008/11/13 Zhiguo Li <zhiguo.li at gmail.com>:> Actually when I tried the above command: > > TermIterator t2 = query.get_terms_begin(); > t2.skip_to(*t1); > > > I got the following error: > InvalidOperationError: VectorTermList::skip_to() not supported > > any suggestion?Oh yes, the query terms are reported in the order they appeared in the query, so skip_to()'s semantics don't make much sense for this case. Simplest other approach is just to stick the terms in a vector of strings, and then use that: vector<string> query_terms(query.get_terms_begin(), query.get_terms_end()); Cheers, Olly