]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Sorting search contexts by longest related substring.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 10 Nov 2009 04:39:32 +0000 (04:39 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 10 Nov 2009 04:39:32 +0000 (04:39 +0000)
Added more pretty highlight colors.

git-svn-id: http://code.elgg.org/elgg/trunk@3659 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/search/start.php
mod/search/views/default/search/css.php

index 19de06dd7f7ccf7ad546b61f113f1c7a08cc672c..6412af8f471c2aab7d9d4211f703dd3e32a00e5e 100644 (file)
@@ -239,7 +239,7 @@ function search_get_highlighted_relevant_substrings($haystack, $needle, $min_mat
                $add_length = floor((($max_length - $total_len) / count($offsets)) / 2);
        }
 
-
+       $lengths = array();
        foreach ($offsets as $i => $offset) {
                $limit = $limits[$i];
                if ($offset == 0 && $add_length) {
@@ -258,19 +258,27 @@ function search_get_highlighted_relevant_substrings($haystack, $needle, $min_mat
                }
 
                $substrings[] = $string;
+               $lengths[] = strlen($string);
        }
 
+       // sort by length of context.
+       asort($lengths);
+
        $matched = '';
-       foreach ($substrings as $string) {
+       foreach ($lengths as $i => $len) {
+               $string = $substrings[$i];
+
                if (strlen($matched) + strlen($string) < $max_length) {
                        $matched .= $string;
                }
        }
 
+       $i = 1;
        foreach ($words as $word) {
                $search = "/($word)/i";
-               $replace = "<strong class=\"searchMatch\">$1</strong>";
+               $replace = "<strong class=\"searchMatch searchMatchColor$i\">$1</strong>";
                $matched = preg_replace($search, $replace, $matched);
+               $i++;
        }
 
        return $matched;
index 936fe5c9d10adc67d7eb11243bcf62df99962ec0..28dc82a4a29b1001637b910a642c0231caa45fd7 100644 (file)
@@ -18,6 +18,27 @@ margin: 6px;
        background-color: #FFFF66;
 }
 
+.searchMatchColor1 {
+       background-color: #FFFF66;
+}
+
+.searchMatchColor2 {
+       background-color: #A0FFFF;
+}
+
+.searchMatchColor3 {
+       background-color: #FF9999;
+}
+
+.searchMatchColor4 {
+       background-color: #FF66FF;
+}
+
+.searchMatchColor5 {
+       background-color: #99FF99;
+}
+
+
 .searchTitle {
        text-decoration: underline;
 }