Skip to content

Commit

Permalink
Updated to fixed the Tridion Docs binary PDF issue on search module a…
Browse files Browse the repository at this point in the history
…nd also Tridion Sites opensearch updated to used PageModelTitle
  • Loading branch information
Velmurugan Arjunan committed Jan 29, 2024
1 parent 4f9ab28 commit 85d8690
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private SearchResultSet BuildResultSet(FacetedSearchResults facetedSearchResults
PublicationTitle = result.Node.Search.PublicationTitle,
Meta = result.Node.Search.Fields,
Highlighted = result.Node.Search.Highlighted,
ItemType = result.Node.Search.ItemType
ItemType = (result.Node.Search.ItemType == Sdl.Tridion.Api.Client.ItemType.Binary)? "binary":"Page"
};

searchResultSet.QueryResults.Add(searchResult);
Expand Down
49 changes: 19 additions & 30 deletions webapp-net/Search/Providers/OpenSearchProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ protected virtual SearchItem MapResult(SearchResult result, Type modelType, stri
SearchItem searchItem = (SearchItem)Activator.CreateInstance(modelType);
searchItem.MvcData = new MvcData(viewName);
searchItem.Id = result.Id;
//searchItem.Title = GetContentTitle(result.Id.Replace("_", ":"), result.PageTitle);
searchItem.Title = result.PageTitle;
searchItem.Title = GetPageModelTitle(result.Id.Replace("_", ":"), result.PageTitle);
searchItem.Url = result.Url;
searchItem.Summary = GetTrimmedContent(result.Highlighted.Contains(contentLanguageFilter) ? result.Highlighted[contentLanguageFilter].ToString() : result.Content);
searchItem.CustomFields = new Dictionary<string, object>();
Expand All @@ -93,7 +92,7 @@ public static string GetTrimmedContent(string content)

private string GetLanguage(string language) => string.IsNullOrEmpty(language) ? _defaultLanguage : CultureInfo.GetCultureInfo(language.Split('-')[0]).EnglishName.ToLower();

private string GetContentTitle(string pageUri, string pageTitle)
private string GetPageModelTitle(string pageUri, string pageTitle)
{
if (string.IsNullOrEmpty(pageUri)) { return string.Empty; }

Expand All @@ -106,36 +105,26 @@ private string GetContentTitle(string pageUri, string pageTitle)
{
return pageTitle;
}
HashSet<string> validRegionNames = new HashSet<string> { "Main" };
foreach (var regions in pageModel.Regions)

IDictionary coreResources = WebRequestContext.Localization.GetResources("core");

string separator = string.Empty;
if (coreResources.Contains("core.pageTitleSeparator"))
{
if (validRegionNames.Contains(regions.Name) && regions.Entities.Any())
{
foreach (var entity in regions.Entities)
{
if (entity != null)
{
Type entityType = entity.GetType();

// Check if the entity is of type Article using reflection
if (entityType.FullName == "Sdl.Web.Modules.Core.Models.Article")
{
PropertyInfo headlineProperty = entityType.GetProperty("Headline");
if (headlineProperty != null)
{
object headlineValue = headlineProperty.GetValue(entity);
if (headlineValue != null)
{
return headlineValue.ToString();
}
}
}
}
}
}
separator = coreResources["core.pageTitleSeparator"].ToString();
}

return pageTitle;
string suffix = string.Empty;
if (coreResources.Contains("core.pageTitlePostfix"))
{
suffix = coreResources["core.pageTitlePostfix"].ToString();
}

string replaceTitleSeparatorPostix = $"{separator}{suffix}";

string title = pageModel.Title.Replace(replaceTitleSeparatorPostix, "");

return title;
}

protected virtual NameValueCollection SetupParameters(SearchQuery searchQuery, Localization localization)
Expand Down

0 comments on commit 85d8690

Please sign in to comment.