[Xapian-discuss] Perl example of using termitrator?

Jim jim at fayettedigital.com
Sun Oct 7 15:03:47 BST 2007


Olly Betts wrote:
> On Sun, Sep 30, 2007 at 05:35:00PM -0400, Jim wrote:
>   
>>    foreach my $match ( @matches ) {
>>        my %hit;
>>        my %ht;
>>        my $doc = $match->get_document();
>>        my $per = $match->get_percent();
>>        my $id = $match->get_docid();
>>        my $bterm = $enq->get_matching_terms_begin($id);
>>        for(my $xit=$bterm;$xit != 
>> $enq->get_matching_terms_end($id);$xit++) {
>>            my $term=$xit;
>>            print $term;
>>        }
>>
>> Which doesn't really make any sense.  Xit is a string and I don't see 
>> how incrementing a string will do anything useful.  So how do you 
>> increment the iterator?
>>     
>
> Actually, $xit is an object, but overloads "" so when you print it you
> get a string.  Just use "++" to increment, like you are already doing
> (though the preincrement may be more efficient - i.e. ++$xit).  Or
> you can use "inc".
>   
Hm.  I wasn't aware of that bit of perl's pearls. I don't use objects 
extensively hence didn't realize overloading was available.  I'll have 
to reread the object perldoc.
>   
>> This does return the terms until it hits the end case then it hangs, 
>> perl just keeps clocking time.  I have to kill it.
>>     
>
> Not sure what's going on here.  You used to have to use "ne" not "!=" to
> compare iterators but we added overloads for "!=" ages ago as it was too
> easy to get wrong.
>
> Can you post a complete script to demonstrate this hang?
>   
No, unfortunately (fortunately?) it works fine now.
>   
>> If I run the following, the same thing happens:
>>        my %eterm = $enq->get_matching_terms_end($id);
>>     
>
> That's assigning an iterator object to a hash - what do you expect it to
> do?
>   
Oh. Duh.  Obviously, I meant $eterm and of course, when I did that all 
my troubles went away. 
> Cheers,
>     Olly
>
>   
Thanks,
Jim.



More information about the Xapian-discuss mailing list