So, I use sunspot in my rails project, and I index song titles. I want to do it when I search for a specific term (for example, “lose myself”) at the top of the list of results to display entries that contain an exact match for the query (with spaces and all).
To do this, I decided to define a new one fieldTypein schema.xmlusing KeywordTokenizerFactoryhow it is (I planned to use it together with a regular text field with StandardTokenizer, use both of them and increase the results obtained using the field KeywordTokenized):
<fieldType name="text_exact" class="solr.TextField" omitNorms="false">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.TrimFilterFactory"/>
</analyzer>
</fieldType>
and adding a dynamic field like this (not sure if it should be ambiguous for this purpose, maybe someone can enlighten me too):
<dynamicField name="*_exact" stored="false" type="text_exact" multiValued="true" indexed="true"/>
Now, in my file song.rb, I have this in the configuration searchable:
text :song_name do
self.name
end
text :song_name_exact, as: :song_name_exact do
self.name
end
The problem is that when I try to search using a field song_name_exact, I get no results if my query contains spaces (so if I have a song called fooand I search fooit will find it, but if I have one called foo barand search foo bar, search query does not return any results.
So, first of all, I would ask if my approach to this is the right one, and why does not the search in the field with the tokenizer keyword work?