summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-06-04 14:13:21 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-06-04 14:13:21 -0400
commite4119f048c9ddd8795df378ff1ad676dca28de82 (patch)
tree46ac0e2defa99a166985e12a74a278dfb5a86fbd /IkiWiki/Plugin
parent319e2c94deeffc3ffe1244d8afe27c6007b9b47b (diff)
The search interface now allows searching for a page by title ("title:foo"), as well as for pages that contain a given link ("link:bar").
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/search.pm21
1 files changed, 18 insertions, 3 deletions
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
index 29d31dfdc..249f267b9 100644
--- a/IkiWiki/Plugin/search.pm
+++ b/IkiWiki/Plugin/search.pm
@@ -62,7 +62,15 @@ sub index (@) { #{{{
my $db=xapiandb();
my $doc=Search::Xapian::Document->new();
- my $title=IkiWiki::pagetitle($params{page});
+ my $caption=IkiWiki::pagetitle($params{page});
+ my $title;
+ if (exists $pagestate{$params{page}}{meta} &&
+ exists $pagestate{$params{page}}{meta}{title}) {
+ $title=$pagestate{$params{page}}{meta}{title};
+ }
+ else {
+ $title=$caption;
+ }
# Remove html from text to be indexed.
if (! defined $scrubber) {
@@ -93,11 +101,12 @@ sub index (@) { #{{{
$doc->set_data(
"url=".urlto($params{page}, "")."\n".
"sample=".decode_entities($sample)."\n".
- "caption=".decode_entities($title)."\n".
+ "caption=".decode_entities($caption)."\n".
"modtime=$IkiWiki::pagemtime{$params{page}}\n".
"size=".length($params{content})."\n"
);
+ # Index document and add terms for other metadata.
my $tg = Search::Xapian::TermGenerator->new();
if (! $stemmer) {
my $langcode=$ENV{LANG} || "en";
@@ -110,9 +119,15 @@ sub index (@) { #{{{
$tg->set_stemmer($stemmer);
$tg->set_document($doc);
$tg->index_text($params{page}, 2);
- $tg->index_text($title, 2);
+ $tg->index_text($caption, 2);
+ $tg->index_text($title, 2) if $title ne $caption;
$tg->index_text($toindex);
+ $tg->index_text(lc($title), 1, "ZS"); # for title:foo
+ foreach my $link (@{$links{$params{page}}}) {
+ $tg->index_text(lc($link), 1, "ZLINK"); # for link:bar
+ }
+ # A unique pageterm is used to identify the document for a page.
my $pageterm=pageterm($params{page});
$doc->add_term($pageterm);
$db->replace_document_by_term($pageterm, $doc);