Question about how to aggregate the query of Solr Chinese fields and how to perform field segmentation, solr Word Segmentation

Source: Internet
Author: User
Tags solr

Question about how to aggregate the query of Solr Chinese fields and how to perform field segmentation, solr Word Segmentation

Problem description:

Question 1:

For example, there is a field named name in the data that stores the user name. If the fieldType used by the name field is configured with English word segmentation, the query results for this field will be incorrect. For example, if you query "Zhang San", data such as "Zhang", "San ge", and "Zhang Yi San" will be found, all data containing "Zhang" or "3" will be identified. That is, if you have configured an English word segmentation, the Chinese will be segmented by words by default, and a word is matched.

Question 2:

When you perform an aggregation query on a Chinese field of fieldType with Word Segmentation configured, the query is performed according to the word segmentation method, instead of a field being aggregated as a whole. For example, if the field content is "Chinese people" and English Word Segmentation is configured. If Chinese Word Segmentation is not configured, word segmentation is performed, will be aggregated by "medium", "China", "people", and "people", configured with Chinese word segmentation, it is possible that "China" and "people" will be aggregated, and the result we want is that the entire field will be aggregated, so this does not meet our requirements.

Solution:

These two problems are actually a problem. There are two ways to solve this problem:

(1) For Chinese fields, fieldType defined by solr with no English Word Segmentation configured, such as string, should not be fieldType defined by text_general for English word segmentation, in this way, the Chinese character is regarded as a field as a whole. The query is not disordered, and Wildcards are also available.

(2) query the fields that we want to include Chinese characters or that will be aggregated. We need to use a custom fieldType and reference it, as shown in the following example:

<Field name = "name" type = "text_not" store = true index = true/>

<FieldType name = "text_not" class = "solr. TextField" omitNorms = "true"/>

The name in fieldType is the name of fieldType that is customized for field reference. The class attribute is not clear yet. fieldType defined by solr is written in this way. omitNorms indicates whether the field needs word segmentation, if true is not required, it is required by default. Therefore, the attribute of omitNorms cannot be explicitly defined as true for fields without word segmentation, but it is recommended that you define the field by yourself so that the schema can be defined. xml is more explicit for easy reading.


Top
0
Step on
0
View comments

Related Article

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.