Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by mi@mgsh.com.cn

An Attempt of Chinese Word Segmentation and Intelligent Search in Websites

Participle needs

The default WP does not have a word segmentation function. It is difficult to find your own results when searching. Unless the search user uses spaces, the website will not automatically segment words, because the website only supports manual space segmentation.
For example, if you search for "baoding seo company", the results are as follows
Baoding SEO Company - Search Results
If you search for "baoding seo company", the content is brilliant:
baoding-seo-company-search results
However, ordinary users are used to automatic word segmentation by search engines. Therefore, if the website cannot automatically segment words, the user performance will be poor.

word segmentation scheme

Method XNUMX. Prompt the user to separate with spaces when searching, which is a bit silly.
Method XNUMX, the solution is to segment the user's query string, then separate it with spaces, and finally send it to the database for query.

Chinese word segmentation function

Put the word segmentation function sea_seg() into function.php

/** * Segmentation * @param $s original sentence * @return string result of segmentation separated by spaces * @author hankcs */ function sae_seg($s) { $seg = new SaeSegment(); $ret = $seg- >segment($s);//$s is the original query string if ($ret) { $phrase = ''; foreach ($ret as $word) { $phrase .= $word['word'] . ' ' ; } $phrase = substr($phrase, 0, strlen($phrase) - 1); } return $phrase; }

Improve search function

Implement word segmentation of search sentences through the topic search.php, and initiate a new search through js redirection:

if(!isset($_GET['seg'])) { $ret = sae_seg($request_vars['s']); if ($ret) { ?>
            ");
            -->
        

Let's try it out:
The result is an error. The reason is that the theme of this site is too complicated to use external solutions directly. I will think of other ways to update it later.
If you are using a domestic theme, you may wish to modify it.

final solution

usedTemplate Rabbitdeveloped pluginErphp Search, you can directly search for the test using the effect.
Finally solved, plugin address: https://qie.me/wordpress/erphp-search
This site supports original only property rights, please buy genuine.Contact the original author, please specify米国生活SEO recommended, maybe there are Easter eggs.
By the way, this plug-in also integrates Baidu's NLP function (interface application address: application address https://console.bce.baidu.com/ai/?fromai=1#/ai/nlp/overview/index), for Template Rabbit And Baidu to express support and thanks.

Back to Top