2014-03-24 30 views
1

當我們試圖重建我們的Lucene(ContentSearch)指標,我們CrawlingLog充滿了這些例外:Sitecore的7 ContentSearch爬行失敗:「履帶:AddRecursive DoItemAdd失敗」

7052 15:08:21 WARN Crawler : AddRecursive DoItemAdd failed - {5A1E50E4-46B9-42D5-B743-1ED10D15D47E} 
Exception: System.AggregateException 
Message: One or more errors occurred. 
Source: mscorlib 
    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) 
    at System.Threading.Tasks.Task.Wait() 
    at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) 
    at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) 
    at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body) 
    at Sitecore.ContentSearch.AbstractDocumentBuilder`1.AddItemFields() 
    at Sitecore.ContentSearch.LuceneProvider.CrawlerLuceneIndexOperations.GetIndexData(IIndexable indexable, IProviderUpdateContext context) 
    at Sitecore.ContentSearch.LuceneProvider.CrawlerLuceneIndexOperations.BuildDataToIndex(IProviderUpdateContext context, IIndexable version) 
    at Sitecore.ContentSearch.LuceneProvider.CrawlerLuceneIndexOperations.Add(IIndexable indexable, IProviderUpdateContext context, ProviderIndexConfiguration indexConfiguration) 
    at Sitecore.ContentSearch.SitecoreItemCrawler.DoAdd(IProviderUpdateContext context, SitecoreIndexableItem indexable) 
    at Sitecore.ContentSearch.HierarchicalDataCrawler`1.CrawlItem(Tuple`3 tuple) 
Nested Exception 
Exception: System.ArgumentOutOfRangeException 
Message: Index and length must refer to a location within the string. 
Parameter name: length 
Source: mscorlib 
    at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) 
    at Sitecore.Data.ShortID.Encode(String guid) 
    at Sitecore.ContentSearch.FieldReaders.MultiListFieldReader.GetFieldValue(IIndexableDataField indexableField) 
    at Sitecore.ContentSearch.FieldReaders.FieldReaderMap.GetFieldValue(IIndexableDataField field) 
    at Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilder.AddField(IIndexableDataField field) 
    at System.Threading.Tasks.Parallel.<>c__DisplayClass32`2.<PartitionerForEachWorker>b__30() 
    at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) 
    at System.Threading.Tasks.Task.<>c__DisplayClass11.<ExecuteSelfReplicating>b__10(Object param0) 

這似乎所致預期字符串參數中的GUID的ShortID.Encode(string)方法在其周圍具有括號(「{」和「}」)。我們的一些多列表字段關係使用Guid.ToString()以編程方式關聯,其中不包括括號。不幸的是,這些值會導致ShortID.Encode()方法窒息。

回答

0
  1. 首先第一件事情:找到所有你叫MultiListField.Add(string),改變Guid.ToString()Guid.ToString("B")的地方。這將解決所有新關係的問題。
  2. 創建一個自定義FieldReader類來替換標準MultiListFieldReader(我們稱之爲我們的CustomMultiListFieldReader)。
  3. 將您的自定義類設置爲從Sitecore.ContentSearch.FieldReaders.FieldReader繼承。
  4. 反編譯Sitecore.ContentSearch.FieldReaders.MultiListFieldReader.GetFieldValue(IIndexableDataField)方法到您的自定義類中。
  5. if (ID.IsID(id))線之前,添加以下代碼:

    if (!str.StartsWith("{") && !str.EndsWith("}")) 
        id = String.Format("{{{0}}}", str); 
    
  6. 在您的索引配置(我們增加了我們的默認,Sitecore.ContentSearch.DefaultIndexConfiguration.config)改變fieldReaderType的多重表字段的自定義類型。 (這可以在你的配置在Sitecore的/ contentSearch /配置/ defaultIndexConfiguration/fieldReaders/mapFieldByTypeName/fieldReader被發現。)

全面披露:我沒有,因爲如果愛這個方法的MultiListFieldReader有史以來的默認實現改變了,我們會沒有這些改變。但是,這允許將項目包含在索引中,而無需重新格式化每個多列表字段中的所有GUID。