Skip to content

Commit

Permalink
add Chinese Word Segmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jun 17, 2018
1 parent 0698bb0 commit b8823ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
14 changes: 13 additions & 1 deletion core/models/ETPostModel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,21 @@ 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))
{
$sql->where("content LIKE :search");
$sql->where($like);
}
else
{
Expand Down
19 changes: 15 additions & 4 deletions core/models/ETSearchModel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,28 @@ 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){
$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")
->from("post")
->where("(title LIKE :fulltext) OR (content LIKE :fulltext)")
->where($like)
->where($idCondition)
->orderBy("conversationId DESC")
->bind(":fulltext", "%".$fulltextString."%")
->bind(":fulltextOrder", $fulltextString);
->orderBy("conversationId DESC");



Expand Down

0 comments on commit b8823ba

Please sign in to comment.