如何使用Sitecore.ContentSearch覆盖Sitecore中的AddAllFields()方法

时间:2016-12-02 09:34:41

标签: solr lucene sitecore

我们正在将Sitecore从6.6版升级到8.1版。每件事情都按预期进行,但在自定义Lucene搜索迁移中遇到问题需要迁移到Solr - 6.1.0。

实际上,我们实现了自定义搜索,如下面的代码和索引配置:

namespace BusinessModules
{   
    public class PeopleIndexer : Sitecore.Search.Crawlers.DatabaseCrawler
    {
        public class PeopleIndexer : Sitecore.Search.Crawlers.DatabaseCrawler
        {
            protected override void AddAllFields(Document document, Item item, bool versionSpecific)
            {
                //People

                //FirstName
                if (item.Fields["FirstName"] != null)
                {
                    string fName = item.Fields["FirstName"].GetValue(false).Trim().Replace("-", string.Empty);
                    if (!string.IsNullOrEmpty(fName))
                    {
                        document.Add(new Field("FirstName", fName.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
                    }
                }
                .........................
                .........................
                .........................          
            }
        }
    }
}
<index id="PeopleIndex" type="Sitecore.Search.Index, Sitecore.Kernel">
    <param desc="name">$(id)</param>
    <param desc="folder">__people</param>
    <Analyzer ref="search/analyzer"/>
    <locations hint="list:AddCrawler">
      <customSearch type="BusinessModules.PeopleIndexer,BusinessModules">
        <Database>web</Database>
        <Root>/sitecore/content/Global Content/People</Root>
        <Tags>people</Tags>
        <Boost>2.0</Boost>
        <IndexAllFields>false</IndexAllFields>
        <include hint="list:IncludeTemplate">
          <includeTemplate>{EB65BFA3-5122-43F4-A1B0-02F430F645CA}</includeTemplate>
          <!--Person-->
        </include>
        <fieldTypes hint="list:AddTextFieldType">
          <fieldType>single-line text</fieldType>
          <fieldType>multilist</fieldType>
          <fieldType>treelist</fieldType>
          <fieldType>treelistex</fieldType>
          <fieldType>checklist</fieldType>
        </fieldTypes>
        <fieldTypes hint="list:RemoveTextFieldType">
          <fieldType>multi-line text</fieldType>
          <fieldType>word document</fieldType>
          <fieldType>html</fieldType>
          <fieldType>rich text</fieldType>
          <fieldType>memo</fieldType>
        </fieldTypes>
      </customSearch>
    </locations>
</index>

有没有办法在Sitecore Solr中使用Sitecore.ContentSearch实现代码(或需要最小的更改)?

0 个答案:

没有答案