开发者

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

开发者 https://www.devze.com 2023-04-10 00:22 出处:网络
How can I specify which fields to index with lucene indexing with Sitecore (new method)? For example I\'d like to in开发者_开发百科dex only the fields \'title\' and \'text\'. There seems to be a Index

How can I specify which fields to index with lucene indexing with Sitecore (new method)?

For example I'd like to in开发者_开发百科dex only the fields 'title' and 'text'. There seems to be a IndexAllField parameter that can be set to False but how can I set which fields needs to be indexed?

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


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号