"SOLR" SOLR support for pinyin search and Pinyin first-letter search

Source: Internet
Author: User
Tags solr

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.

  • using Lucene to achieve

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.

  • SOLR implementation

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

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.