How to exclude fields form being indexed with Sitecore search (new method)

限于喜欢 提交于 2019-12-14 03:44:13

问题


How can I specify wich fields to index with lucene indexing with Sitecore (new method) ? For example i'd like to index only the fields 'title' and 'text'. There seems to be a IndexAllField parameter that can be set to False but how can I set wich fields needs to be indexed ?

I'm using Sitecore.Search.Crawlers.DatabaseCrawler.

Thank you


回答1:


Are you using the Advanced Database Crawler? If so, there are sections you can add to include specific fields by their GUIDs and exclude specific fields by their GUIDs. Below I've provided a snippet where the hint attribute of the <include> node defines whether the fields should be included or excluded

<master type="Sitecore.SharedSource.Search.Crawlers.AdvancedDatabaseCrawler,Sitecore.SharedSource.Search">
  <Database>master</Database>
  <Root>/sitecore/content</Root>
  <IndexAllFields>false</IndexAllFields>

  <include hint="list:IncludeField">
    <!-- some field you'd want to include -->
    <fieldId>{8CDC337E-A112-42FB-BBB4-4143751E123F}</fieldId>
  </include>

  <include hint="list:ExcludeField">
    <!-- __revision field -->
    <fieldId>{8CDC337E-A112-42FB-BBB4-4143751E123F}</fieldId>
    <!-- __context menu field -->
    <fieldId>{D3AE7222-425D-4B77-95D8-EE33AC2B6730}</fieldId>
    <!-- __security field -->
    <fieldId>{DEC8D2D5-E3CF-48B6-A653-8E69E2716641}</fieldId>
    <!-- __renderings field -->
    <fieldId>{F1A1FE9E-A60C-4DDB-A3A0-BB5B29FE732E}</fieldId>
  </include>

You can see a sample search config for the Advanced Database Crawler on SVN.




回答2:


If you are using the Standard Sitecore DatabaseCrawler I would suggest you create a custom crawler that inherits from the Sitecore Database crawler and then override the AddAllFieldsMethod. Then just configure your index to use your custom crawler

You can look at the source code for the Advanced Database Crawler for an example of how that can be done. Something like this: (NOTE THIS HAS NOT BEEN TESTED)

public class DatabaseCrawler : Sitecore.Search.Crawlers.DatabaseCrawler
{
    protected override void AddAllFields(Lucene.Net.Documents.Document document, Sitecore.Data.Items.Item item, bool versionSpecific)
    {
        if(IndexAllFields)
        {
            base.AddAllFields(document, item, versionSpecific);
        }
        else
        {
            var fieldsToIndex = new List<string>() {"title", "Text"};
            foreach (var field in fieldsToIndex)
            { 
                var scField = item.Fields[field];
                document.Add(new LuceneField(scField.Key, scField.Value, LuceneField.Store.NO, LuceneField.Index.UN_TOKENIZED));
            }
        }
    }
}


来源:https://stackoverflow.com/questions/7615382/how-to-exclude-fields-form-being-indexed-with-sitecore-search-new-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!