How to convert pinyin into Chinese characters or other solutions in the search box of php e-commerce website
迷茫
迷茫 2017-06-24 09:42:17
0
7
919

When using php to develop a website, where is the search box? When inputting, the user input method is not switched properly. There may be situations where the input is pinyin. So how to convert pinyin to Chinese characters and query the database to display the corresponding products! I originally wanted to use sphinx, but I had no choice but to install it for several days without success!

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(7)
三叔

This requires using a search engine, the database is too heavy

为情所困

This is word association, which cannot be achieved without a huge local vocabulary library. It is recommended to use a third-party API

伊谢尔伦

Use third-party search support elasticsearch, xunsearch, sphinx and other processing

巴扎黑

In fact, you can add a pinyin field to the product, which will make the search better

三叔

This is word association, which cannot be achieved without a huge local vocabulary library. It is recommended to use a third-party API

仅有的幸福
// PHP利用ICU扩展intl实现汉字转拼音
echo transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', '小米'); //xiao mi
// MySQL全文检索字段name_fts中同时包含关键字xiao mi的商店记录.
SELECT name FROM store 
WHERE MATCH(name_fts) 
AGAINST('+xiao +mi' IN BOOLEAN MODE) 
ORDER BY id DESC LIMIT 5;
漂亮男人

Pinyin to Chinese character conversion solution https://github.com/letiantian...
If there are not many products, you can also add an extra pinyin field

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template