Reputation: 113
I'm using apache-solr-3.4.0. I'm able to search using a single word, but couldn't search using more than one word. For example: jobTitle:tester
produce the results, but jobTitle:java developer
doesn't return any result.
In my schema.xml I added like the below code for Text field type:
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize= "5"/>
<filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="5"/>
<filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
<filter class="solr.SynonymFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
Upvotes: 1
Views: 869
Reputation: 9500
You have several options, sorted by ease of use
(
and )
around parts of the query that shall go to one field to group them, e.g. jobTitle:(java developer)
. Do not simply put quotes "
around them, this executes as phrase query that is something different.{!df=jobTitle}java developer
. This will make all parts of your query go to that field.Background
Imagine that Solr splits your search query in parts at each blank (in reality it is not that simple, but good enough for a start). Each part is treated against either an assigned field or the default field. Taken from Solr's manual
The field is only valid for the term that it directly precedes, so the query title:Do it right will find only "Do" in the title field. It will find "it" and "right" in the default field (in this case the text field).
Upvotes: 1
Reputation: 8658
Solr has also an NGramFilterFactory
. N-gram filter. Try not use the ngram tokenizer. I would suggest to use the "WhitespaceTokenizer
" and then apply ngram filters.
<filter class="solr.NGramFilterFactory" minGramSize="2" maxGramSize="3" />
your field type should be something like this :
<fieldType name="text_custom" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.NGramFilterFactory" minGramSize="2" maxGramSize="10" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
Upvotes: 0