diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-11-10 04:39:32 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-11-10 04:39:32 +0000 |
commit | 3ae8de6ca798fb80b93bef3ec03e29c7ed43fbd2 (patch) | |
tree | 463a9021d000f7a9bb81e1e96124b1a7ac0a54ef /mod | |
parent | 8d3cb601f6d6c0528ee9c204e7779739055a5f59 (diff) | |
download | elgg-3ae8de6ca798fb80b93bef3ec03e29c7ed43fbd2.tar.gz elgg-3ae8de6ca798fb80b93bef3ec03e29c7ed43fbd2.tar.bz2 |
Sorting search contexts by longest related substring.
Added more pretty highlight colors.
git-svn-id: http://code.elgg.org/elgg/trunk@3659 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod')
-rw-r--r-- | mod/search/start.php | 14 | ||||
-rw-r--r-- | mod/search/views/default/search/css.php | 21 |
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; } |