Pankaj Jarial
Pankaj Jarial

Reputation: 71

Apache Solr facet search exclude space

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

Upvotes: 0

Views: 899

Answers (1)

Paweł Róg
Paweł Róg

Reputation: 126

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">
....

Upvotes: 5

Related Questions