Matthias Zeichmann
2006-Jan-31 14:08 UTC
[Xapian-discuss] retrieving attributes of searchresults
i use the perl interface of Search::Xapian to index documents, now i got metadata i store with the index like title, date, author, .. and i wonder how to retrieve them from the index again without pulling them from the database. i am pretty sure this is a stupid question and that the answer is obvious i dont seem to be able to find it. regards m ------------>8------------------------------------------------------- ## vital parts of indexer ################################ my $doc = Search::Xapian::Document->new(); $doc->set_data($data->{article_id}); _add_attr($doc, { # pass fields with multifield values as arrayref 'XAID' => $data->{article_id}, 'XTITLE' => $title, # arrayref 'XDATE' => $data->{publicationdate}, 'XTYPE' => $data->{articletype}, 'XTID' => $tid, # arrayref 'XTXC' => $txc, # arrayref }); my @words = _get_text($data,$title); for my $i (0 .. $#words) { my $w = $words[$i]; $w =~ s/[\.-]$//g; $doc->add_posting($w,++$i) if $w; } $db->add_document($doc); sub _add_attr { my ($doc,$data) = @_; for my $k (keys %$data) { if (ref $data->{$k}) { # arrayref / multivalue field for my $v (@{$data->{$k}}) { $doc->add_term($k . lc(decode_entities($v))); } } else { next unless defined $data->{$k}; $doc->add_term($k . lc(decode_entities($data->{$k}))); } } } ------------>8------------------------------------------------------- ------------>8------------------------------------------------------- ## vital parts of search ################################ my @srch = qw/nachrichtenagentur bloomberg t?rkischen XAUTHORcp XTITLEakquisition/; my $q = Search::Xapian::Query->new(OP_AND,@srch); my $enq = $db->enquire($q); my $mset = $enq->get_mset(0,999); my @matches; tie(@matches, 'Search::Xapian::MSet::Tied', $mset); foreach my $match (@matches) { my $doc = $match->get_document(); printf "ID %d %d%% [ %s ]\n", $match->get_docid(), $match->get_percent(), $doc->get_data(); } warn scalar @matches; ------------>8-------------------------------------------------------
James Aylett
2006-Jan-31 14:11 UTC
[Xapian-discuss] retrieving attributes of searchresults
On Tue, Jan 31, 2006 at 02:07:07PM +0000, Matthias Zeichmann wrote:> i use the perl interface of Search::Xapian to index documents, now i > got metadata i store with the index like title, date, author, .. and > i wonder how to retrieve them from the index again without pulling > them from the database.I don't know how the perl bindings work, but the usual way to store metadata is to structure the Xapian::Document data field. See the documentation with omega for an example, but you could stuff anything in there - serialised perl, XML, whatever. J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james@tartarus.org uncertaintydivision.org