Skip to content

Commit

Permalink
Merge pull request #201 from Epinova/Release/198-contentarea-language…
Browse files Browse the repository at this point in the history
…-bug

Release/198 contentarea language bug
  • Loading branch information
otanum authored Mar 13, 2023
2 parents 5547a82 + a7d79bb commit d5ab341
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Hosting;
using Castle.DynamicProxy;
using Epinova.ElasticSearch.Core.Contracts;
Expand Down Expand Up @@ -579,21 +580,19 @@ private static object GetIndexValue(IContentData content, PropertyInfo p, out bo
alreadyProcessedContent = new List<IContent>();
}

foreach(ContentAreaItem item in contentArea.FilteredItems)
foreach(var filteredItem in ListFilteredItems(content, contentArea))
{
IContent areaItemContent = item.GetContent();

if(Indexer.IsExcludedType(areaItemContent) || alreadyProcessedContent.Contains(areaItemContent))
if(Indexer.IsExcludedType(filteredItem) || alreadyProcessedContent.Contains(filteredItem))
{
continue;
}

Type areaItemType = GetContentType(areaItemContent);
Type areaItemType = GetContentType(filteredItem);
List<PropertyInfo> indexableProperties = areaItemType.GetIndexableProps(false);
alreadyProcessedContent.Add(areaItemContent);
alreadyProcessedContent.Add(filteredItem);
indexableProperties.ForEach(property =>
{
var indexValue = GetIndexValue(areaItemContent, property, alreadyProcessedContent: alreadyProcessedContent);
var indexValue = GetIndexValue(filteredItem, property, alreadyProcessedContent: alreadyProcessedContent);
indexText.Append(indexValue);
indexText.Append(" ");
});
Expand All @@ -605,7 +604,8 @@ private static object GetIndexValue(IContentData content, PropertyInfo p, out bo
if(value is XhtmlString xhtml)
{
isString = true;
var indexText = new StringBuilder(TextUtil.StripHtml(value.ToString()));
string decodedHtml = HttpUtility.HtmlDecode(TextUtil.StripHtml(value.ToString()));
var indexText = new StringBuilder(decodedHtml);

IPrincipal principal = HostingEnvironment.IsHosted
? PrincipalInfo.AnonymousPrincipal
Expand Down Expand Up @@ -662,6 +662,15 @@ private static object GetIndexValue(IContentData content, PropertyInfo p, out bo
Logger.Warning($"GetIndexValue failed for content with id '{(content as IContent)?.ContentLink}'", ex);
return null;
}

static IEnumerable<IContent> ListFilteredItems(IContentData content, ContentArea contentArea)
{
string languageBranch = content.Property["PageLanguageBranch"]?.Value as string;

return !string.IsNullOrWhiteSpace(languageBranch)
? ContentLoader.GetItems(contentArea.FilteredItems.Select(i => i.ContentLink), new CultureInfo(languageBranch))
: contentArea.FilteredItems.Select(i => i.GetContent());
}
}

private static bool IsValidFragment(ContentFragment fragment, out IContent fragmentContent)
Expand Down

0 comments on commit d5ab341

Please sign in to comment.