[Xapian-discuss] Perl example: parse terms, search , get total,
get result, parse result
Kevin SoftDev
kevin.softdev at gmail.com
Wed Mar 8 17:43:53 GMT 2006
Hi,
Thank you all for emailing some answers to my question. I put together
simple Perl script so we do not keep asking the same thing over. As you can
see I had to parse the document data and try to find where is title, body
and url. If someone knows something that was not yet documented and
retrieves the specific document attribute (title,body,url) let me know.
#--------------------------------------------------------- begin of the
script -----------------------------------------------#
my $db = Search::Xapian::Database->new( '/europa' );
my $qp = Search::Xapian::QueryParser->new();
my $enq = $db->enquire($qp->parse_query($terms));
my $total = $db->get_termfreq($terms);
printf "Searching for: '%s' ", $terms;
print "Total matches found" . $total;
#--- display only range of documents for pagination ----#
my @matches = $enq->matches($start, $end);
my($doc,$html,$body,$title,$url);
foreach my $match ( @matches )
{
$doc = $match->get_document();
$html = $doc->get_data();
$html =~ m/body=(.*)/; $body = $1;
$html =~ m/title=(.*)/; $title = $1;
$html =~ m/url=(.*)/; $url = $1;
printf "<table border=0 width=95%><tr><td><font size=2
face=Verdana>Relevance: %s% ", $match->get_percent();
print "<a href=\"$url\"
target=_blank><b>$title</b><BR><i>$url</i></a><BR>$body";
print "</font></td></tr></table><P>";
}
#--------------------------------------------------------- end of the script
-----------------------------------------------#
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.tartarus.org/pipermail/xapian-discuss/attachments/20060308/072db734/attachment.htm
More information about the Xapian-discuss
mailing list