ashwinbhy
ashwinbhy

Reputation: 600

Solr wildcard issue with '-' character

i am using solr and tokenizing a field as follows:

    <field name="Title" type="text_general" multiValued="false" indexed="true" stored="true">
   <analyzer>
   <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
   </analyzer>
   </field>

i append * at each search field to get the matching result: Title:app* for example app* will give me app,application and similar result

But if i search for the term with '-' in it the query fails to return anything. For example:

Title:child-play* Does not return any result but Title:child-play does !!

Can anyone point me what might be the issue.


after debug i got this : for Title:child-play

 "debug":{
    "rawquerystring":"Title:child-play",
    "querystring":"Title::child-play",
    "parsedquery":"Title::child Title::play",
    "parsedquery_toString":"Title::child Title::play",

for Title:child-play*

"debug":{
    "rawquerystring":"CompanyName:child-play*",
    "querystring":"CompanyName:child-play*",
    "parsedquery":"CompanyName:child-play*",
    "parsedquery_toString":"CompanyName:child-play*",

Upvotes: 0

Views: 82

Answers (1)

Oyeme
Oyeme

Reputation: 11225

I recommend you to use WordDelimiterFilterFactory

Just change type of field to "custom type", in my case it's 'text_general"

<field name="Title" type="text_general"/>

Then you need to create a new type

For example, my settings. You can customise it how you want.

<fieldType name="text_general" class="solr.TextField" omitNorms="false" positionIncrementGap="100" multiValued="true">
    <analyzer type="index">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.WordDelimiterFilterFactory" types="wdfftypes.txt" generateNumberParts="0" stemEnglishPossessive="0" splitOnCaseChange="1" preserveOriginal="1" catenateAll="1" catenateWords="1" catenateNumbers="1" generateWordParts="1" splitOnNumerics="1"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.WordDelimiterFilterFactory" types="wdfftypes.txt" generateNumberParts="1" stemEnglishPossessive="0" splitOnCaseChange="1" preserveOriginal="1" catenateAll="1" catenateWords="1" catenateNumbers="1" generateWordParts="1" splitOnNumerics="1"/>
    </analyzer>
  </fieldType>

Look at my screenshot. enter image description here

Please read more information here

https://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters

Arguments:

generateWordParts: (integer, default 1) If non-zero, splits words at delimiters.
 For example:"CamelCase", "hot-spot" -> "Camel", "Case", "hot", "spot"

 generateNumberParts: (integer, default 1) If non-zero, splits numeric strings at delimiters:"1947-32" ->"1947", "32"

splitOnCaseChange: (integer, default 1) If 0, words are not split on camel-case changes:"BugBlaster-XL" -> "BugBlaster", "XL". Example 1 below illustrates the default (non-zero) splitting behavior.

splitOnNumerics: (integer, default 1) If 0, don't split words on transitions from alpha to numeric:"FemBot3000" -> "Fem", "Bot3000"

catenateWords: (integer, default 0) If non-zero, maximal runs of word parts will be joined: "hot-spot-sensor's" -> "hotspotsensor"

catenateNumbers: (integer, default 0) If non-zero, maximal runs of number parts will be joined: 1947-32" -> "194732"

catenateAll: (0/1, default 0) If non-zero, runs of word and number parts will be joined: "Zap-Master-9000" -> "ZapMaster9000"

preserveOriginal: (integer, default 0) If non-zero, the original token is 

preserved: "Zap-Master-9000" -> "Zap-Master-9000", "Zap", "Master", "9000"

protected: (optional) The pathname of a file that contains a list of protected words that should be passed through without splitting.

stemEnglishPossessive: (integer, default 1) If 1, strips the possessive "'s" from each subword.

Upvotes: 2

Related Questions