cbrebel
cbrebel

Reputation: 85

Solr search query with special character not working in Sitecore

I have content on page like "financial rate is 3.75% and market....." . Now, if i entered search keyword as "3.75%" then result should display this page but it is not working. It is returning 0 result but it is working fine when i enter "3.75" as search keyword.

public SearchResults<SearchHelper> GetSearchData(string searchtext)
    {

        using (searchContext)

        {

            //Fetch all items which contains search query                

            var query = searchContext.GetQueryable<SearchHelper>().OrderByDescending(i => i.BoostingValue).Where(i => (i.PageSearchContent.Contains(searchtext) ));

            var result = query.GetResults();

            return result;
        }
    }

Can anybody help that how can i allow search with special character ?

Thanks

Upvotes: 0

Views: 515

Answers (1)

Oyeme
Oyeme

Reputation: 11225

You could use WordDelimiterFilterFactory filter to convert % to DIGITAL or ALPHA

For example:

# A customized type mapping for WordDelimiterFilterFactory
# the allowable types are: LOWER, UPPER, ALPHA, DIGIT, ALPHANUM, SUBWORD_DELIM
# 
# the default for any character without a mapping is always computed from 
# Unicode character properties

# Map the $, %, '.', and ',' characters to DIGIT 
# This might be useful for financial data.
% => DIGIT
( => ALPHA
) => ALPHA
. => DIGIT

An example of usage

<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"/>

Just create a new file called "wdfftypes.txt" in solr/coreName/conf/wdfftypes.txt

Upvotes: 1

Related Questions