Sitecore solr按字符而不是单词进行搜索

时间:2018-08-28 04:52:24

标签: solr sitecore

我已经实现了solr搜索,其中包含页面内容的计算字段。但问题是,它基于单词而不是字符进行搜索,例如如果我搜索“这是我的帖子”,它将返回结果,但是当搜索“他的是我的帖子”时,它与记录不匹配。我认为是因为它将它们存储为单词并匹配,所以我尝试了Tokenzied和UnTokenized但问题仍然存在。 任何快速指南?

                                                                 

       </fieldNames>
     </fieldMap>
     <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
       <fields hint="raw:AddComputedIndexField">
         <field fieldName="renderings_content" returnType="text" >Sitecore.Feature.Search.Infrastructure.Fields.RenderingsContentComputedField, Sitecore.Feature.Search</field>
       </fields>
     </documentOptions>

   </defaultSolrIndexConfiguration>

我的solr查询:

?q =((_ fullpath:(/ sitecore / content / marko *)AND(((((-base_template_ids_sm:(ae3e2aaacb77453fad3eb15f9aa7a73b) )))AND(base_template_ids_sm:(79b74cfd7d3a4aa4b238f754a6ca52ef)OR base_template_ids_sm:(b815c3ed17d84e78815e2b34e52fef79)OR base_template_ids_sm:(ea18699f5c764f69ba11a1336b83016e)OR base_template_ids_sm:(9f08fd0633ed467ba5e6b6a7f48c3a7a)OR base_template_ids_sm:(cea1d388d04f4b46a9bcd5c251064186))))AND(title_t :( “* LSE迪拜*”)或search_description_t:( lse迪拜)或renderings_content_t :(“ * lse迪拜*”)OR(title_t :(“ * lse迪拜*”)OR description_t :(“ * lse迪拜*”)OR renderings_content_t: (“ * lse dubai *”))或(title_t :(“ * lse dubai *”)OR search_description_t:( lse dubai )OR renderings_content_t :(“ * lse dubai *”))OR(search_description_t :(( lse dubai )或event_title_t:( lse dubai )OR renderings_content_t :(“ * lse dubai *”))或(title_t :(“ * lse dub ai *“)或search_description_t:( lse迪拜)或renderings_content_t :(” * lse迪拜*“)))))&start = 0&rows = 2&fl = *,score&fq =(_ latestversion:(True)AND _language :(en))&fq = _indexname:(marko_web_index)

1 个答案:

答案 0 :(得分:0)

您正在寻找的是关于建议的搜索建议。是的,在Sitecore中有可能!

首先,您需要在Solr上配置Suggester组件。如果您将放弃该链接,则会看到可以配置的选项很多。在Improving the Search Experience with Solr Suggester中浏览可能对您有益。

那么您只需要在以下情况下使用

SitecoreIndexableItem rootItem = Context.Database.GetRootItem();            
ISearchIndex index = ContentSearchManager.GetIndex(rootItem); //of course you can resolve index in different way or just pick one you are interested in
using (var context = index.CreateSearchContext())
{
    SolrSuggestQuery query = model.Term;
    SolrSuggestHandlerQueryResults result;
    SuggestHandlerQueryOptions options = new SuggestHandlerQueryOptions
    {
        Parameters = new SuggestParameters
        {
            Count = 5
        }
    };

    using (queryTimer = new Timer())
    {
        result = context.Suggest(query, options);
    }

    return result.Suggestions["NAME_OF_YOUR_SUGGESTER"].Suggestions.Select(a => new Suggestion { Term = a.Term, Payload = a.Payload});
}
Suggestion此处使用的

new Suggestion { Term = a.Term, Payload = a.Payload}类是自定义类(Sitecore未提供)。您可以使用自己的一个。

重要!:建议搜索仅在Sitecore 9(及更高版本)中以及在使用Solr时可用。