The search interface now allows searching for a page by title ("title:foo"), as well...
authorJoey Hess <joey@kodama.kitenet.net>
Wed, 4 Jun 2008 18:13:21 +0000 (14:13 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Wed, 4 Jun 2008 18:13:21 +0000 (14:13 -0400)
IkiWiki/Plugin/search.pm
debian/changelog
doc/ikiwiki/searching.mdwn [new file with mode: 0644]
doc/todo/search_terms.mdwn
templates/searchquery.tmpl
underlays/basewiki/ikiwiki/searching.mdwn [new symlink]

index 29d31dfdc15d0e00ab326a5f9cce0aeeb54eb35c..249f267b970bcf422b698d9a45dcb0183f15bc58 100644 (file)
@@ -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);
index 34112ab26d0e18598e9c325940d62a1ec62ca0cc..6ce6bd06770a9e0f401a81c2ca7a00435f251770 100644 (file)
@@ -9,6 +9,9 @@ ikiwiki (2.49) UNRELEASED; urgency=low
     prevent wikilinks added by filters from being scanned properly. But
     no known filter hook does that, so let's not waste time on it.
   * Pass a destpage parameter to the sanitize hook.
+  * 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").
 
  -- Joey Hess <joeyh@debian.org>  Fri, 30 May 2008 19:08:54 -0400
 
diff --git a/doc/ikiwiki/searching.mdwn b/doc/ikiwiki/searching.mdwn
new file mode 100644 (file)
index 0000000..0eeb5a6
--- /dev/null
@@ -0,0 +1,20 @@
+[[!meta robots="noindex, follow"]]
+
+[[!if test="enabled(search)"
+then="This wiki has searching **enabled**."
+else="This wiki has searching **disabled**."]]
+
+If searching is enabled, you can enter search terms in the search field,
+like you'd expect. There are a few special things you can do to constuct
+more powerful searches.
+
+* To match a phrase, enclose it in double quotes.
+* `AND` can be used to search for documents containing two expressions.
+* `OR` can be used to search for documents containing either one of
+  two expressions.
+* Parentheses can be used to build up complicated search expressions. For
+  example, "(foo AND bar) OR (me AND you)"
+* Prefix a search term with "-" to avoid it from appearing in the results.
+  For example, "-discussion" will omit "discussion".
+* To search for a page with a given title, use "title:foo".
+* To search for pages that contain a "bar" link, use "link:bar".
index 4e3f3aa6b9b97431b7d0b9a1ae515c24fd0173d5..0e5edb520947335b6d4e5cb93ff14c044ed82ea6 100644 (file)
@@ -3,3 +3,5 @@ searches. For example, "title:foo", or "link:somepage", or "author:foo", or
 "copyright:GPL".
 
 Reference: <http://xapian.org/docs/omega/termprefixes.html>
+
+[[done]] for title and link, which seem like the really useful ones.
index 33a7cb6fad600b400f268bf44a1a7c6ba1948800..bf36f3330a86386e1e2a1a2bf83f68204af255ac 100644 (file)
@@ -1,3 +1,5 @@
+$setmap{prefix,title,S}
+$setmap{prefix,link,LINK}
 $set{thousand,$.}$set{decimal,.}$setmap{BN,,Any Country,uk,England,fr,France}
 ${
 $def{PREV,
diff --git a/underlays/basewiki/ikiwiki/searching.mdwn b/underlays/basewiki/ikiwiki/searching.mdwn
new file mode 120000 (symlink)
index 0000000..d94120e
--- /dev/null
@@ -0,0 +1 @@
+../../../doc/ikiwiki/searching.mdwn
\ No newline at end of file