Skip to content

Commit

Permalink
fix search bug
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jun 17, 2018
1 parent 51f87e1 commit 97f7b0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
27 changes: 13 additions & 14 deletions core/models/ETPostModel.class.php
Expand Up @@ -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."%");
Expand Down
16 changes: 8 additions & 8 deletions core/models/ETSearchModel.class.php
Expand Up @@ -397,21 +397,21 @@ 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%')";
if ( $key+1 != $count ){
$like .= " OR ";
}
}
if(preg_match('/[\x80-\xff]/i',$fulltextString))
{

$fulltextQuery = ET::SQL()
->select("DISTINCT conversationId")
Expand Down

0 comments on commit 97f7b0b

Please sign in to comment.