diff --git a/inc/fulltext.php b/inc/fulltext.php
index 5af0bfc1bf5094f3ec74d3a3cac543d77806a7bd..a1dd1774dd3bac68097bfa73d710f658187467ed 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
  *