How do I find documents containing numbers and dollar signs in Solr?
In Solr, I have a text containing $ 30 and $ 30.
I would like to search for $ 30 and find documents containing $ 30.
But if anyone is looking for 30, they should find both documents containing $ 30 and those containing $ 30.
Here is the field type I am using to index my textbox:
<!-- Just like text_en_splitting, but with the addition of reversed tokens for leading wildcard matches -->
<fieldType name="text_en_splitting_reversed" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<!-- Case insensitive stop word removal.
add enablePositionIncrements=true in both the index and query
analyzers to leave a 'gap' for more accurate phrase queries.
-->
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
enablePositionIncrements="true"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1" types="word-delim-types.txt" />
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
<filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"
maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
enablePositionIncrements="true"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1" types="word-delim-types.txt" />
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
</fieldType>
I defined word-delim-types.txt to contain:
$ => DIGIT % => DIGIT . => DIGIT
So when I search for $ 30, it correctly finds documents that contain "$ 30", but not those that only contain "30". It's good. But when I search for "30" it doesn't find documents containing "$ 30", only those containing "30".
Is there a way to do this?
source to share
I found a solution to my question. Instead of defining $% and. as DIGIT, now I define them as ALPHA, in my "types" file, which is passed as a WordDelimiterFilterFactory attribute.
$ => ALPHA % => ALPHA . => ALPHA
Due to the rest of my WordDelimiterFilterFactory settings, things crash and reset in a way that achieves the desired effect:
Searching for $ 30 only returns documents containing $ 30. Search 30 documents containing both 30 and 30 dollars.
source to share