Simple processing of sphinx full-text search Php

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.