From 97f7b0b94147404170424b5283d5f9bb36371f83 Mon Sep 17 00:00:00 2001 From: skywalker512 Date: Sun, 17 Jun 2018 22:06:25 +0800 Subject: [PATCH] fix search bug --- core/models/ETPostModel.class.php | 27 +++++++++++++-------------- core/models/ETSearchModel.class.php | 16 ++++++++-------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/core/models/ETPostModel.class.php b/core/models/ETPostModel.class.php index df04e2f..4fe95a4 100644 --- a/core/models/ETPostModel.class.php +++ b/core/models/ETPostModel.class.php @@ -170,26 +170,25 @@ public function getSearchResultsCount($conversationId, $search) */ private function whereSearch(&$sql, $search) { - $fulltextString = ($s = spiltWords($search)) ? $s :$search; - $KeywordArray = explode(" ", $fulltextString); - $like = ''; - $count = count($KeywordArray); - foreach ($KeywordArray as $key => $value){ - $like .= "(content LIKE '%$value%')"; - if( ET::$session->user ) - $like .= " OR (content LIKE '%$value%')"; - if ( $key+1 != $count ){ - $like .= " OR "; - } - } if(preg_match('/[\x80-\xff]/i',$search)) { + $fulltextString = ($s = spiltWords($search)) ? $s :$search; + $KeywordArray = explode(" ", $fulltextString); + $like = ''; + $count = count($KeywordArray); + foreach ($KeywordArray as $key => $value){ + $like .= "(content LIKE '%$value%')"; + if( ET::$session->user ) + $like .= " OR (content LIKE '%$value%')"; + if ( $key+1 != $count ){ + $like .= " OR "; + } + } $sql->where($like); } else { - $sql->where("MATCH (content) AGAINST (:search IN BOOLEAN MODE)") - ->where("MATCH (title) AGAINST (:search IN BOOLEAN MODE)"); + $sql->where("MATCH (content) AGAINST (:search IN BOOLEAN MODE)"); } $sql->where("deleteMemberId IS NULL") ->bind(":search", "%".$search."%"); diff --git a/core/models/ETSearchModel.class.php b/core/models/ETSearchModel.class.php index 28ab37e..9828d40 100644 --- a/core/models/ETSearchModel.class.php +++ b/core/models/ETSearchModel.class.php @@ -397,12 +397,14 @@ public function getConversationIDs($channelIDs = array(), $searchString = "", $o // Run a query against the posts table to get matching conversation IDs. $fulltextString = implode(" ", $this->fulltext); - $fulltextString = ($s = spiltWords($fulltextString)) ? $s :$fulltextString; - $KeywordArray = explode(" ", $fulltextString); - $this->fulltext = $KeywordArray; - $like = ''; - $count = count($KeywordArray); - foreach ($KeywordArray as $key => $value){ + if(preg_match('/[\x80-\xff]/i',$fulltextString)) + { + $fulltextString = ($s = spiltWords($fulltextString)) ? $s :$fulltextString; + $KeywordArray = explode(" ", $fulltextString); + $this->fulltext = $KeywordArray; + $like = ''; + $count = count($KeywordArray); + foreach ($KeywordArray as $key => $value){ $like .= "(title LIKE '%$value%')"; if( ET::$session->user ) $like .= " OR (content LIKE '%$value%')"; @@ -410,8 +412,6 @@ public function getConversationIDs($channelIDs = array(), $searchString = "", $o $like .= " OR "; } } - if(preg_match('/[\x80-\xff]/i',$fulltextString)) - { $fulltextQuery = ET::SQL() ->select("DISTINCT conversationId")