Sphinx full-text search Php simple processing the first attempt to use sphinx for full-text search may not be very correct. You can come up with different ideas.
The current version of sphinx does not know that the support does not support Chinese characters. I asked all the friends in the group that it does not support it. all of them use the following methods.
1. Article processing.
Assume that the article table is article_main.
Id
|
Title
|
Summary
|
Content
|
Time
|
1
|
Test title
|
Test Summary
|
Test Content
|
123123123
|
Since sphsf-does not support Chinese (is it true? In this case, right)
Create a new table article_unicode
Id
|
Article_id
|
Title
|
Summary
|
Content
|
Time
|
1
|
1
|
23243 23123 12213
|
12312 12312 12345
|
12312 12312 12345 |
123123123
|
The structure of the new table is the same as that of article_main, but the unicode code of Chinese UTF-8 is stored.
In this way, when adding an article, we also process the input title, abstract, and content into UTF-8 unicode code, and then save it to the article_unicode table.
Use the article_unicode table as the source when configuring sphunicode (see http://my.oschina.net/ptk/blog/495435)
2. the classes used to process UTF-8 unicode are as follows:
http://git.oschina.net/ctk/laravel5_backend/blob/master/app/Libraries/Spliter.php
The call method is as follows:
$ TitleSplited = $ spliterObject-> utf8Split ($ data ['title']); // Article title $ index ['title'] = $ titleSplited ['word']; // the resulting value is the UTF-8 unicode code of the article title.
Then save it to the table.
3. when searching, we first convert the search term to a unicode code, and then use this code for sphinx search.
$ Object = new \ stdClass (); $ object-> keyword = Request: input ('keyword'); $ searchProcess = new Process (); // here the keyword is actually converted to unicode, and I encapsulated it. $ KeywordUnicode = $ searchProcess-> prepareKeyword ($ object-> keyword); // search and process data through sphinx, and finally obtain the document id, that is, in the article_unicode table, article_id $ object-> sphinxResult_ArticleIds = $ searchProcess-> sphinxSearch ($ keywordUnicode); // you can use article_id to perform regular queries. $ ArticleList = (new SearchModel ()-> activeArticleInfoBySearch ($ object );
In this way, you can.