Hello all, I have a question about use the TermGenerator alone by Perl. Someone asked this question before and his code is in C++. (http://lists.xapian.org/pipermail/xapian-discuss/2008-November/006109.html). My code is in Perl. Can I get the term by the position just by TermGenerator? my $analyzer = Search::Xapian::TermGenerator->new; $analyzer->index_text("hello Xapian world"); my $curr_position = $analyzer->get_termpos(); $analyzer->set_termpos(2); $curr_position = $analyzer->get_termpos(); $analyzer->increase_termpos(1); $curr_position = $analyzer->get_termpos(); If I set the document and then use $doc to iterate the term list, terms are order alphabetically. I don't know how to use the positer(). $analyzer->set_document($doc); my $termlist_begin = $doc->termlist_begin(); $termlist_begin++; my $term = $termlist_begin->get_document(); Btw, if I want to use ESet, how to assign the text, similar method like index_text for ESet? Thank you, Ying
Well, the ESet perl package is not available now. I am playing around with the perl modules of Document, TermGenerator, TermIterator, PositionIterator, and PostingIterator. I still have the same question. How can I get the term by the term position? I can move the index to be begin or end of the term, and I can move the index to the next term by alphabetical order and get the term. But how can I index the terms of a document and get a term by the term position. I just start with Xapian, Thank you for your help. Ying Ying Liu wrote:> Hello all, > > I have a question about use the TermGenerator alone by Perl. Someone > asked this question before and his code is in C++. > (http://lists.xapian.org/pipermail/xapian-discuss/2008-November/006109.html). > My code is in Perl. Can I get the term by the position just by > TermGenerator? > > my $analyzer = Search::Xapian::TermGenerator->new; > $analyzer->index_text("hello Xapian world"); > my $curr_position = $analyzer->get_termpos(); > $analyzer->set_termpos(2); $curr_position = $analyzer->get_termpos(); > $analyzer->increase_termpos(1); > $curr_position = $analyzer->get_termpos(); > > If I set the document and then use $doc to iterate the term list, > terms are order alphabetically. I don't know how to use the positer(). > > $analyzer->set_document($doc); > my $termlist_begin = $doc->termlist_begin(); > $termlist_begin++; > my $term = $termlist_begin->get_document(); > > > Btw, if I want to use ESet, how to assign the text, similar method > like index_text for ESet? > > Thank you, > Ying > > _______________________________________________ > Xapian-discuss mailing list > Xapian-discuss at lists.xapian.org > http://lists.xapian.org/mailman/listinfo/xapian-discuss
On Thu, Oct 29, 2009 at 02:26:58PM -0500, Ying Liu wrote:> I have a question about use the TermGenerator alone by Perl. Someone > asked this question before and his code is in C++. > (http://lists.xapian.org/pipermail/xapian-discuss/2008-November/006109.html). > My code is in Perl. Can I get the term by the position just by > TermGenerator? > > my $analyzer = Search::Xapian::TermGenerator->new; > $analyzer->index_text("hello Xapian world"); > my $curr_position = $analyzer->get_termpos(); > $analyzer->set_termpos(2); $curr_position = $analyzer->get_termpos(); > $analyzer->increase_termpos(1); > $curr_position = $analyzer->get_termpos(); > > If I set the document and then use $doc to iterate the term list, terms > are order alphabetically. I don't know how to use the positer(). > > $analyzer->set_document($doc); > my $termlist_begin = $doc->termlist_begin(); > $termlist_begin++; > my $term = $termlist_begin->get_document();Um, that line is wrong as TermIterator doesn't have a get_document() method. I think you mean: my $term = $termlist_begin->get_termname(); To iterator the positions for TermIterator $term_itor you'd do: my $pos_itor = $term_itor->positionlist_begin(); while ($pos_itor ne $term_itor->positionlist_end()) { print $pos_itor->get_termpos(), "\n"; ++$pos_itor; }> Btw, if I want to use ESet, how to assign the text, similar method like > index_text for ESet?The ESet is generated from the same terms used for searching. Cheers, Olly