aboutsummaryrefslogtreecommitdiff
path: root/mod/search
diff options
context:
space:
mode:
Diffstat (limited to 'mod/search')
-rw-r--r--mod/search/start.php14
-rw-r--r--mod/search/views/default/search/css.php21
2 files changed, 32 insertions, 3 deletions
diff --git a/mod/search/start.php b/mod/search/start.php
index 19de06dd7..6412af8f4 100644
--- a/mod/search/start.php
+++ b/mod/search/start.php
@@ -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;
diff --git a/mod/search/views/default/search/css.php b/mod/search/views/default/search/css.php
index 936fe5c9d..28dc82a4a 100644
--- a/mod/search/views/default/search/css.php
+++ b/mod/search/views/default/search/css.php
@@ -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;
}