]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3550. Merged slightly modified pull request 166 from sembrestels.
authorBrett Profitt <brett.profitt@gmail.com>
Sat, 25 Feb 2012 20:58:21 +0000 (12:58 -0800)
committerBrett Profitt <brett.profitt@gmail.com>
Sat, 25 Feb 2012 20:58:21 +0000 (12:58 -0800)
mod/search/pages/search/index.php
mod/search/search_hooks.php
mod/search/start.php

index 91817096b543db16222f9998f1e7a86fed08f678..fcd95c43e9acea272b656e6fe034da55724ef067 100644 (file)
@@ -257,7 +257,11 @@ if ($search_type != 'entities' || $search_type == 'all') {
 }
 
 // highlight search terms
-$searched_words = search_remove_ignored_words($display_query, 'array');
+if ($search_type == 'tags') {
+       $searched_words = array($display_query);
+} else {
+       $searched_words = search_remove_ignored_words($display_query, 'array');
+}
 $highlighted_query = search_highlight_words($searched_words, $display_query);
 
 $body = elgg_view_title(elgg_echo('search:results', array("\"$highlighted_query\"")));
index ab000f6f6ad5709f352864d2fea872f3e5986633..2143a0d2480e3a71566e7c4ddec8b2af3fb15de2 100644 (file)
@@ -284,7 +284,7 @@ function search_tags_hook($hook, $type, $value, $params) {
                }
 
                $tags_str = implode('. ', $matched_tags_strs);
-               $tags_str = search_get_highlighted_relevant_substrings($tags_str, $params['query']);
+               $tags_str = search_get_highlighted_relevant_substrings($tags_str, $params['query'], 30, 300, true);
 
                $entity->setVolatileData('search_matched_title', $title_str);
                $entity->setVolatileData('search_matched_description', $desc_str);
index bb8531e9c3e2ff5f2f094f502e1debe158690025..d2d7ed3c22982b1c1d8134998d57a17e9b3cc3ba 100644 (file)
@@ -83,15 +83,18 @@ function search_page_handler($page) {
  * @param string $query
  * @param int $min_match_context = 30
  * @param int $max_length = 300
+ * @param bool $tag_match Search is for tags. Don't ignore words.
  * @return string
  */
-function search_get_highlighted_relevant_substrings($haystack, $query, $min_match_context = 30, $max_length = 300) {
+function search_get_highlighted_relevant_substrings($haystack, $query, $min_match_context = 30, $max_length = 300, $tag_match = false) {
 
        $haystack = strip_tags($haystack);
        $haystack_length = elgg_strlen($haystack);
        $haystack_lc = elgg_strtolower($haystack);
 
-       $words = search_remove_ignored_words($query, 'array');
+       if (!$tag_match) {
+               $words = search_remove_ignored_words($query, 'array');
+       }
 
        // if haystack < $max_length return the entire haystack w/formatting immediately
        if ($haystack_length <= $max_length) {