Apache Solr facet search exclude space

拈花ヽ惹草 提交于 2019-12-13 03:47:00

问题


I am using Apache Solr and using following Query for search

http://Siteurl:8080/solr/metro/select?q=*:*&rows=0&wt=json&indent=true&facet=true&facet.field=Make

But as result let suppose I have 'Ford Fiesta' in make field. I am getting two results instead of one as shown below :

Ford => 21
Fiesta => 21

It is seprating field by space.

I want it like

Ford Fiesta => 21

Please let me know the valid method to do so.

Thanks


回答1:


The problem is very simple here. You are trying to facet on tokenized field (text). This means each token will be counted separately. I suggest you to add new field (in schema.xml file) which you will feed with the same data as field Make (eg. using copy field). This new field should be string or text with KeywordTokenizer.

Please look at the example below. I added there two types: string and text_not_tokenized. Then defined two fields Make_string and Make_nonTokenized. When you facet on each of them you should see "Ford Fiesta"

So you can just query

http://Siteurl:8080/solr/metro/select?q=*:*&rows=0&wt=json&indent=true&facet=true&facet.field=Make_string

or

http://Siteurl:8080/solr/metro/select?q=*:*&rows=0&wt=json&indent=true&facet=true&facet.field=Make_nonTokenized

.

...
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<fieldType name="text_not_tokenized" class="solr.TextField">
  <analyzer>
    <tokenizer class="solr.KeywordTokenizerFactory"/>
  </analyzer>
</fieldType>
...
<field name="Make_string" type="string">
<field name="Make_nonTokenized" type="text_not_tokenized">
....


来源:https://stackoverflow.com/questions/27316221/apache-solr-facet-search-exclude-space

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!