【问题标题】:Solr search query with special character not working in Sitecore具有特殊字符的 Solr 搜索查询在 Sitecore 中不起作用
【发布时间】:2016-12-06 12:49:16
【问题描述】:

我的页面上有“财务利率为 3.75% 和市场.....”之类的内容。现在,如果我将搜索关键字输入为“3.75%”,那么结果应该会显示此页面,但它不起作用。它返回 0 结果,但当我输入“3.75”作为搜索关键字时它工作正常。

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;
        }
    }

谁能帮助我如何允许使用特殊字符进行搜索?

谢谢

【问题讨论】:

    标签: solr sitecore sitecore-mvc sitecore8.2


    【解决方案1】:

    您可以使用 WordDelimiterFilterFactory 过滤器将 % 转换为 DIGITALALPHA

    例如:

    # 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
    

    使用示例

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

    只需在 solr/coreName/conf/wdfftypes.txt 中创建一个名为“wdfftypes.txt”的新文件

    【讨论】:

    • 感谢您的回复。我已经应用了你给出的建议,但它不起作用。我做了上述所有更改,然后在 Sitecore 中为 Master 和 Web 重建索引。我在索引和查询分析器中修改了过滤器。
    • @ChirayuBrahmbhatt 你能告诉我分析说什么吗?详细输出应该为您指明正确的方向以查看“char”类型。
    • 我可以看到 %.. type:Word
    猜你喜欢
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 2018-12-15
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多