[Xapian-discuss] Perl example: parse terms, search , get total,
get result, parse result
Olly Betts
olly at survex.com
Thu Mar 9 00:38:05 GMT 2006
On Wed, Mar 08, 2006 at 09:43:53AM -0800, Kevin SoftDev wrote:
> my $total = $db->get_termfreq($terms);
This looks up the frequency of a single term, so it'll be fine for a one
term query, but will return zero for anything more complicated (unless
you happen to have terms with spaces, etc in).
As I explained just now, you want MSet::get_matches_estimated().
> $html = $doc->get_data();
>
> $html =~ m/body=(.*)/; $body = $1;
That's kind of risky - you only want to match body at the start of a
line, but this doesn't specify that, so it'll match wrongly if there's
an earlier line containing "body=" anywhere in it. I suggest:
my ($body) = $html =~ m/^body=(.*)/m;
> print "<a href=\"$url\"
> target=_blank><b>$title</b><BR><i>$url</i></a><BR>$body";
You really want to be escaping values put into HTML output, unless
you've carefully sanitised them at indexing time. Otherwise you're
opening yourself to cross-site scripting type exploits.
Cheers,
Olly
More information about the Xapian-discuss
mailing list