[Xapian-discuss] retrieving attributes of searchresults

Matthias Zeichmann matthias at volltext.net
Tue Jan 31 14:07:07 GMT 2006


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, at 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-------------------------------------------------------




More information about the Xapian-discuss mailing list