Q: for pinyin and Pinyin first letter support, when you search for goods, if you want to enter the pinyin and pinyin first letter to give the product information, how to do?
There are 2 ways to implement them, but they are in fact corresponding.
1. Build an index, more than one index field, that is, pinyin and pinyin first letter of the 2 fields. A field that is merged.
(Pinyin and pinyin initials can be obtained by Pinyin4j.jar. Convert the fields you want to search for pinyin. )
2. To determine whether the input parameters are pinyin, (you can convert the value of the descendants to Utf-8 form, if the converted string length is greater than the length of the original string, then it is not pinyin.) Otherwise, the pinyin query)
3. Query the phonetic index field, as in the Chinese query. Refer to Chinese query.
1.SOLR implementation, can not be indexed with SOLR's own features, that does not put the pinyin and Pinyin first letter this field into the index file.
2. To place pinyin in the index file library, you need to fetch the data from the database, convert the data to pinyin, and then put the Ruby into the index library.
(When automatically indexed, it is a query to the database through the Db-config.xml file.) Therefore, you cannot convert a phonetic translation of the fields that are being queried. )。 The above functions are implemented with SOLRJ. SOLRJ provides some extensions to SOLR.
3. Query the Pinyin field, as in Chinese query.
The above ideas, after Baidu Search, turn from others. Also for practice, after practice, to summarize.
"SOLR" SOLR support for pinyin search and Pinyin first-letter search