[dokuwiki] Sorted search results

  • From: "Todd Augsburger" <todd@xxxxxxxxxxxxxxxx>
  • To: <dokuwiki@xxxxxxxxxxxxx>
  • Date: Wed, 7 Feb 2007 17:23:10 -0500

I understand the "ranked" search results (by hit count) that Dokuwiki 
currently returns, but what about the order of results for the same hit 
count level? They seem to be in an unpredictable order.

Since one of my wikis will often have multiple pages found with identical 
hit counts, I chose to modify inc/fulltext.php to sort them naturally. Is 
there interest in inserting this "feature" in the standard code?


Include this code before ft_pageSearch() returns (line 103 in latest devel):

--------
    // natsort by pagename within hitcount levels
    if(count($docs) > 1) {
      $key_array = array();
      $hitcount_key_array = array();
      $value_prev = 0;
      foreach($docs as $key=>$value) {
        if($value != $value_prev) {
          ft_addSorted($key_array,$hitcount_key_array);
          $hitcount_key_array = array();
          $value_prev = $value;
        }
        $hitcount_key_array[] = $key;
      }
      ft_addSorted($key_array,$hitcount_key_array);
      $sorted_array = array();
      foreach($key_array as $key=>$value) {
        $sorted_array[$value] = $docs[$value];
      }
      $docs = $sorted_array;
    }
--------

And add this function anywhere above:

--------
/**
 * natsort an array of pagenames
 */
function ft_addSorted(&$target,$names){
  global $conf;
  if ($conf['useheading']) {
    // sort by headings
    $title_array = array();
    foreach($names as $key=>$value) {
      if ($title = p_get_first_heading($value))
        $title_array[$key] = $title;
      else
        $title_array[$key] = $value;
    }
    natsort($title_array);
    foreach($title_array as $key=>$value)
      $target[] = $names[$key];
  } else {
    // sort by pagenames
    natsort($names);
    foreach($names as $value)
      $target[] = $value;
  }
}
--------

Todd Augsburger
todd@xxxxxxxxxxxxxxxx
Roller Organs
http://www.rollerorgans.com/


-- 
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts:

  • » [dokuwiki] Sorted search results