summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2008-08-12 22:06:49 +0200
committerAndreas Gohr <andi@splitbrain.org>2008-08-12 22:06:49 +0200
commitf31eb72b8cad47dcf6515e112eb67a1b5fceabd3 (patch)
tree7481ca1a36cb08fe4d38a46f657ea56dfc759ea6
parent6840140f1fbd74ccb2ccbee2d7aa5793182b93c1 (diff)
downloadrpg-f31eb72b8cad47dcf6515e112eb67a1b5fceabd3.tar.gz
rpg-f31eb72b8cad47dcf6515e112eb67a1b5fceabd3.tar.bz2
Better search for pagename quick searches
The pagename matching search (AJAX and "real" search) now sort results based on the namespace hierarchy levels before doing an alphabetically search. This means pages with fewer namespace (ie. higher up in the hierarchy) wil be shown first. darcs-hash:20080812200649-7ad00-b58f152923864c3440e6412be58fb6fb25373583.gz
-rw-r--r--inc/fulltext.php18
1 files changed, 17 insertions, 1 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 5af0bfc1b..a1dd1774d 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -260,11 +260,27 @@ function _ft_pageLookup(&$data){
}
$pages = array_map('trim',$pages);
- sort($pages);
+ usort($pages,'ft_pagesorter');
return $pages;
}
/**
+ * Sort pages based on their namespace level first, then on their string
+ * values. This makes higher hierarchy pages rank higher than lower hierarchy
+ * pages.
+ */
+function ft_pagesorter($a, $b){
+ $ac = count(explode(':',$a));
+ $bc = count(explode(':',$b));
+ if($ac < $bc){
+ return -1;
+ }elseif($ac > $bc){
+ return 1;
+ }
+ return strcmp ($a,$b);
+}
+
+/**
* Creates a snippet extract
*
* @author Andreas Gohr <andi@splitbrain.org>