Skip to content

Commit

Permalink
Fix the issue for 9.0.1, using roles an considering all search providers
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStupka committed Oct 30, 2018
1 parent 27ab937 commit 23c7e59
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultLuceneIndexConfiguration>
<defaultLuceneIndexConfiguration search:require="lucene">
<documentBuilderType>
Sitecore.Support.ContentSearch.LuceneProvider.LuceneDocumentBuilder, Sitecore.Support.96931
</documentBuilderType>
</defaultLuceneIndexConfiguration>
<defaultSolrIndexConfiguration search:require="solr">
<documentBuilderType>
Sitecore.Support.ContentSearch.SolrProvider.SolrDocumentBuilder, Sitecore.Support.96931
</documentBuilderType>
</defaultSolrIndexConfiguration>
<defaultCloudIndexConfiguration search:require="azure">
<documentBuilderType>
Sitecore.Support.ContentSearch.Azure.CloudSearchDocumentBuilder, Sitecore.Support.96931
</documentBuilderType>
</defaultCloudIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
namespace Sitecore.Support.ContentSearch.Azure
{
using System;
using System.Collections.Concurrent;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Diagnostics;
using Sitecore.Data.LanguageFallback;

public class CloudSearchDocumentBuilder : Sitecore.ContentSearch.Azure.CloudSearchDocumentBuilder
{
public CloudSearchDocumentBuilder(IIndexable indexable, IProviderUpdateContext context) : base(indexable, context)
{
}

protected override void AddComputedIndexFieldsInParallel()
{
ConcurrentQueue<Exception> exceptions = new ConcurrentQueue<Exception>();

//ensure that we preserve current item-level language fallback setting when entering new threads
var needEnterLanguageFallbackItemSwitcher = LanguageFallbackItemSwitcher.CurrentValue;

this.ParallelForeachProxy.ForEach(
this.Options.ComputedIndexFields,
this.ParallelOptions,
(computedIndexField, parallelLoopState) =>
{
object fieldValue;
try
{
using (new LanguageFallbackItemSwitcher(needEnterLanguageFallbackItemSwitcher))
{
//take field-level language fallback setting into accout (fix for issue #96931)
using (new LanguageFallbackFieldSwitcher(this.Index.EnableFieldLanguageFallback))
{
fieldValue = computedIndexField.ComputeFieldValue(this.Indexable);
}
}
}
catch (Exception ex)
{
CrawlingLog.Log.Warn(
string.Format("Could not compute value for ComputedIndexField: {0} for indexable: {1}",
computedIndexField.FieldName, this.Indexable.UniqueId), ex);
if (this.Settings.StopOnCrawlFieldError())
{
exceptions.Enqueue(ex);
parallelLoopState.Stop();
}
System.Diagnostics.Debug.WriteLine(ex);
return;
}
this.AddComputedIndexField(computedIndexField, fieldValue);
});

if (!exceptions.IsEmpty)
{
throw new AggregateException(exceptions);
}
}

protected override void AddComputedIndexFieldsInSequence()
{
foreach (var computedIndexField in this.Options.ComputedIndexFields)
{
object fieldValue;

try
{
//take field-level language fallback setting into accout (fix for issue #96931)
using (new LanguageFallbackFieldSwitcher(this.Index.EnableFieldLanguageFallback))
{
fieldValue = computedIndexField.ComputeFieldValue(this.Indexable);
}
}
catch (Exception ex)
{
CrawlingLog.Log.Warn(string.Format("Could not compute value for ComputedIndexField: {0} for indexable: {1}", computedIndexField.FieldName, this.Indexable.UniqueId), ex);
if (this.Settings.StopOnCrawlFieldError())
{
throw;
}

System.Diagnostics.Debug.WriteLine(ex);
continue;
}

this.AddComputedIndexField(computedIndexField, fieldValue);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,92 @@
{
using System;
using System.Collections.Concurrent;
using System.Reflection;
using System.Threading.Tasks;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.ComputedFields;
using Sitecore.ContentSearch.Diagnostics;
using Sitecore.Data.LanguageFallback;

public class LuceneDocumentBuilder : Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilder
{
private static readonly MethodInfo AddComputedIndexFieldMethodInfo;
static LuceneDocumentBuilder()
{
AddComputedIndexFieldMethodInfo = typeof(Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilder).GetMethod("AddComputedIndexField", BindingFlags.Instance | BindingFlags.NonPublic);
}
public LuceneDocumentBuilder(IIndexable indexable, IProviderUpdateContext context) : base(indexable, context)
{
}

protected override void AddComputedIndexFieldsInParallel()
{
ConcurrentQueue<Exception> exceptions = new ConcurrentQueue<Exception>();

//ensure that we preserve current item-level language fallback setting when entering new threads
var needEnterLanguageFallbackItemSwitcher = LanguageFallbackItemSwitcher.CurrentValue;
Parallel.ForEach<IComputedIndexField>(base.Options.ComputedIndexFields, base.ParallelOptions, delegate (IComputedIndexField computedIndexField, ParallelLoopState parallelLoopState)
{
object fieldValue;
try

this.ParallelForeachProxy.ForEach(
this.Options.ComputedIndexFields,
this.ParallelOptions,
(computedIndexField, parallelLoopState) =>
{
using (new LanguageFallbackItemSwitcher(needEnterLanguageFallbackItemSwitcher))
object fieldValue;
try
{
using (new LanguageFallbackFieldSwitcher(this.Index.EnableFieldLanguageFallback))
using (new LanguageFallbackItemSwitcher(needEnterLanguageFallbackItemSwitcher))
{
fieldValue = computedIndexField.ComputeFieldValue(this.Indexable);
//take field-level language fallback setting into accout (fix for issue #96931)
using (new LanguageFallbackFieldSwitcher(this.Index.EnableFieldLanguageFallback))
{
fieldValue = computedIndexField.ComputeFieldValue(this.Indexable);
}
}
}
}
catch (Exception ex)
{
CrawlingLog.Log.Warn(string.Format("Could not compute value for ComputedIndexField: {0} for indexable: {1}", computedIndexField.FieldName, this.Indexable.UniqueId), ex);
if (this.Settings.StopOnCrawlFieldError())
catch (Exception ex)
{
exceptions.Enqueue(ex);
parallelLoopState.Stop();
CrawlingLog.Log.Warn(
string.Format("Could not compute value for ComputedIndexField: {0} for indexable: {1}",
computedIndexField.FieldName, this.Indexable.UniqueId), ex);
if (this.Settings.StopOnCrawlFieldError())
{
exceptions.Enqueue(ex);
parallelLoopState.Stop();
}
System.Diagnostics.Debug.WriteLine(ex);
return;
}
return;
}
this.AddComputedIndexField(computedIndexField, fieldValue);
});
if (exceptions.Count > 0)
this.AddComputedIndexField(computedIndexField, fieldValue);
});

if (!exceptions.IsEmpty)
{
throw new AggregateException(exceptions);
}
}

private void AddComputedIndexField(IComputedIndexField computedIndexField, object fieldValue)
{
AddComputedIndexFieldMethodInfo.Invoke(this, new object[]
{
computedIndexField, fieldValue
});
}

protected override void AddComputedIndexFieldsInSequence()
{
foreach (IComputedIndexField current in base.Options.ComputedIndexFields)
foreach (var computedIndexField in this.Options.ComputedIndexFields)
{
object fieldValue;

try
{
//take field-level language fallback setting into accout (fix for issue #96931)
using (new LanguageFallbackFieldSwitcher(this.Index.EnableFieldLanguageFallback))
{
fieldValue = current.ComputeFieldValue(base.Indexable);
fieldValue = computedIndexField.ComputeFieldValue(this.Indexable);
}
}
catch (Exception exception)
catch (Exception ex)
{
CrawlingLog.Log.Warn(string.Format("Could not compute value for ComputedIndexField: {0} for indexable: {1}", current.FieldName, base.Indexable.UniqueId), exception);
if (base.Settings.StopOnCrawlFieldError())
CrawlingLog.Log.Warn(string.Format("Could not compute value for ComputedIndexField: {0} for indexable: {1}", computedIndexField.FieldName, this.Indexable.UniqueId), ex);
if (this.Settings.StopOnCrawlFieldError())
{
throw;
}

System.Diagnostics.Debug.WriteLine(ex);
continue;
}
this.AddComputedIndexField(current, fieldValue);

this.AddComputedIndexField(computedIndexField, fieldValue);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
namespace Sitecore.Support.ContentSearch.SolrProvider
{
using System;
using System.Collections.Concurrent;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Diagnostics;
using Sitecore.Data.LanguageFallback;

public class SolrDocumentBuilder : Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilder
{
public SolrDocumentBuilder(IIndexable indexable, IProviderUpdateContext context) : base(indexable, context)
{
}

protected override void AddComputedIndexFieldsInParallel()
{
ConcurrentQueue<Exception> exceptions = new ConcurrentQueue<Exception>();

//ensure that we preserve current item-level language fallback setting when entering new threads
var needEnterLanguageFallbackItemSwitcher = LanguageFallbackItemSwitcher.CurrentValue;

this.ParallelForeachProxy.ForEach(
this.Options.ComputedIndexFields,
this.ParallelOptions,
(computedIndexField, parallelLoopState) =>
{
object fieldValue;
try
{
using (new LanguageFallbackItemSwitcher(needEnterLanguageFallbackItemSwitcher))
{
//take field-level language fallback setting into accout (fix for issue #96931)
using (new LanguageFallbackFieldSwitcher(this.Index.EnableFieldLanguageFallback))
{
fieldValue = computedIndexField.ComputeFieldValue(this.Indexable);
}
}
}
catch (Exception ex)
{
CrawlingLog.Log.Warn(
string.Format("Could not compute value for ComputedIndexField: {0} for indexable: {1}",
computedIndexField.FieldName, this.Indexable.UniqueId), ex);
if (this.Settings.StopOnCrawlFieldError())
{
exceptions.Enqueue(ex);
parallelLoopState.Stop();
}
System.Diagnostics.Debug.WriteLine(ex);
return;
}
this.AddComputedIndexField(computedIndexField, fieldValue);
});

if (!exceptions.IsEmpty)
{
throw new AggregateException(exceptions);
}
}

protected override void AddComputedIndexFieldsInSequence()
{
foreach (var computedIndexField in this.Options.ComputedIndexFields)
{
object fieldValue;

try
{
//take field-level language fallback setting into accout (fix for issue #96931)
using (new LanguageFallbackFieldSwitcher(this.Index.EnableFieldLanguageFallback))
{
fieldValue = computedIndexField.ComputeFieldValue(this.Indexable);
}
}
catch (Exception ex)
{
CrawlingLog.Log.Warn(string.Format("Could not compute value for ComputedIndexField: {0} for indexable: {1}", computedIndexField.FieldName, this.Indexable.UniqueId), ex);
if (this.Settings.StopOnCrawlFieldError())
{
throw;
}

System.Diagnostics.Debug.WriteLine(ex);
continue;
}

this.AddComputedIndexField(computedIndexField, fieldValue);
}
}
}
}
11 changes: 11 additions & 0 deletions src/Sitecore.Support.96931/Sitecore.Support.96931.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<TargetFrameworkProfile />
<Use64BitIISExpress />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -48,10 +49,18 @@
<HintPath>..\packages\SC.Sitecore.ContentSearch.9.0.1\lib\Sitecore.ContentSearch.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.ContentSearch.Azure, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SC.Sitecore.ContentSearch.Azure.9.0.1\lib\Sitecore.ContentSearch.Azure.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.ContentSearch.LuceneProvider">
<HintPath>..\packages\SC.Sitecore.ContentSearch.LuceneProvider.9.0.1\lib\Sitecore.ContentSearch.LuceneProvider.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.ContentSearch.SolrProvider, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SC.Sitecore.ContentSearch.SolrProvider.9.0.1\lib\Sitecore.ContentSearch.SolrProvider.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.Kernel">
<HintPath>..\packages\SC.Sitecore.Kernel.9.0.1\lib\Sitecore.Kernel.dll</HintPath>
<Private>False</Private>
Expand All @@ -63,8 +72,10 @@
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContentSearch\Azure\CloudSearchDocumentBuilder.cs" />
<Compile Include="ContentSearch\LuceneProvider\LuceneDocumentBuilder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ContentSearch\SolrProvider\SolrDocumentBuilder.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="App_Config\Include\zzz\Sitecore.Support.96931.config" />
Expand Down
Loading

0 comments on commit 23c7e59

Please sign in to comment.