ColdFusion Solr Search - LIKE% string% equivalent in SQL

How to perform a SOLR search with the same logic for the next SQL search query?

SELECT * FROM user where email LIKE '%ben%'" 

I tried the following:

 <cfscript> mysearch = new com.adobe.coldfusion.search(); searchResult = mysearch.search(collection="mycollection", criteria='ben*'); </cfscript> 
  • criteria='ben*' matches " raw_ben@yahoo.com " and " ben@yahoo.com ", but does not return the string "ro ben ro ben .

  • criteria='ben~' matches " raw_ben@yahoo.com " and " ben@yahoo.com ", but does not return the string "ro ben ro ben .

The same applies to all fuzzy searches, wild search attempts.

+5
source share
1 answer

you need to change the fieldType for your field that can generate tokens using solr.EdgeNGramFilterFactory With which you can create currents, for example. abhijit will generate abh, abhi, abhij, abhiji, abhijit and therefore will match all of these combinations for your request.

with the second EdgeNGramFilterFactory, it will generate jit, ijit, hijit, bhijit, abhijit, iji, hiji, bhiji tokens, etc. and so on...

try entering the field type below

 <fieldType name="text_reference" class="solr.TextField" sortMissingLast="true" omitNorms="true" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="50" side="front"/> <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="50" side="back"/> </analyzer> <analyzer type="query"> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType> 
+3
source

All Articles