From f31eb72b8cad47dcf6515e112eb67a1b5fceabd3 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Tue, 12 Aug 2008 22:06:49 +0200
Subject: [PATCH] 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
---
 inc/fulltext.php | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/inc/fulltext.php b/inc/fulltext.php
index 5af0bfc1b..a1dd1774d 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -260,10 +260,26 @@ 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
  *
-- 
GitLab