]> git.mxchange.org Git - friendica.git/blobdiff - mod/search.php
Speed optimisation by enabling the posibility of the MySQL fulltext engine
[friendica.git] / mod / search.php
index d467764b01a57049581ad9f051f9014ae9ab9988..ac51346963bbde408520a8b8168fb0206b04c2c1 100644 (file)
@@ -80,7 +80,7 @@ function search_content(&$a) {
 
        $o = '<div id="live-search"></div>' . "\r\n";
 
-       $o .= '<h3>' . t('Search This Site') . '</h3>';
+       $o .= '<h3>' . t('Search') . '</h3>';
 
        if(x($a->data,'search'))
                $search = notags(trim($a->data['search']));
@@ -96,14 +96,30 @@ function search_content(&$a) {
 
        $o .= search($search,'search-box','/search',((local_user()) ? true : false));
 
+
+       if(strpos($search,'#') === 0) {
+               $tag = true;
+               $search = substr($search,1);
+       }
+       if(strpos($search,'@') === 0) {
+               require_once('mod/dirfind.php');
+               return dirfind_content($a);
+       }
+
        if(! $search)
                return $o;
 
-       if($tag)
-               $sql_extra = sprintf(" AND `item`.`tag` REGEXP '%s' ",  dbesc('\\]' . preg_quote($search) . '\\['));
-       else
-               $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(preg_quote($search)));
-
+       if (get_config('system','use_fulltext_engine')) {
+               if($tag)
+                       $sql_extra = sprintf(" AND MATCH (`item`.`tag`) AGAINST ('".'"%s"'."' in boolean mode) ", '#'.preg_quote($search));
+               else
+                       $sql_extra = sprintf(" AND MATCH (`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) ", dbesc(preg_quote($search)));
+       } else {
+               if($tag)
+                       $sql_extra = sprintf(" AND `item`.`tag` REGEXP '%s' ",  dbesc('\\]' . preg_quote($search) . '\\['));
+               else
+                       $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(preg_quote($search)));
+       }