Skip to content

Commit

Permalink
Merge pull request #156 from Epinova/Release/version11_7_4
Browse files Browse the repository at this point in the history
Release/version11 7 4
  • Loading branch information
otanum authored Jun 8, 2022
2 parents 975972e + d09d6fe commit 08e0b96
Show file tree
Hide file tree
Showing 115 changed files with 4,809 additions and 4,651 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 11.7.3.{build}
version: 11.7.4.{build}
skip_tags: true
image: Visual Studio 2019
configuration: Release
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Explanation of the different options:
## What will be indexed?

The module tries to follow the same conventions as Episerver, meaning that all properties of type `string` and `XhtmlString` will be indexed unless explicitly decorated with `[Searchable(false)]`.
Additional properties can be indexed by decorating them with [Searchable] or with the conventions above.
Additional properties can be indexed by decorating them with `[Searchable]` or with the conventions above. Decorate `ContentArea` with `[Searchable]` to index contents.

 

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections.Generic;
using EPiServer.Commerce.Catalog.ContentTypes;

namespace Epinova.ElasticSearch.Core.EPiServer
namespace Epinova.ElasticSearch.Core.EPiServer.Commerce
{
public sealed class CatalogSearchHit<T>
where T : EntryContentBase
public sealed class CatalogSearchHit<T> where T : EntryContentBase
{
public CatalogSearchHit(T content, Dictionary<string, object> custom, double queryScore, string highlight)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Web.Mvc;
using Epinova.ElasticSearch.Core.Contracts;
using Epinova.ElasticSearch.Core.EPiServer.Contracts;
Expand All @@ -18,17 +19,7 @@ public class ElasticAdminCommerceController : ElasticAdminController
private readonly IElasticSearchSettings _settings;
private readonly ReferenceConverter _referenceConverter;

public ElasticAdminCommerceController(
IContentIndexService contentIndexService,
ILanguageBranchRepository languageBranchRepository,
ICoreIndexer coreIndexer,
IElasticSearchSettings settings,
IHttpClientHelper httpClientHelper,
IServerInfoService serverInfoService,
IScheduledJobRepository scheduledJobRepository,
IScheduledJobExecutor scheduledJobExecutor,
ReferenceConverter referenceConverter)
: base(contentIndexService, languageBranchRepository, coreIndexer, settings, httpClientHelper, serverInfoService, scheduledJobRepository, scheduledJobExecutor)
public ElasticAdminCommerceController(IContentIndexService contentIndexService, ILanguageBranchRepository languageBranchRepository, ICoreIndexer coreIndexer, IElasticSearchSettings settings, IHttpClientHelper httpClientHelper, IServerInfoService serverInfoService, IScheduledJobRepository scheduledJobRepository, IScheduledJobExecutor scheduledJobExecutor, ReferenceConverter referenceConverter) : base(contentIndexService, languageBranchRepository, coreIndexer, settings, httpClientHelper, serverInfoService, scheduledJobRepository, scheduledJobExecutor)
{
_settings = settings;
_referenceConverter = referenceConverter;
Expand All @@ -45,7 +36,7 @@ public override ActionResult AddNewIndex()

foreach(var lang in Languages)
{
string commerceIndexName = _settings.GetCommerceIndexName(lang.Key);
string commerceIndexName = _settings.GetCommerceIndexName(new CultureInfo(lang.Key));
CreateIndex(typeof(IndexItem), commerceIndexName);
}

Expand All @@ -59,7 +50,7 @@ public override ActionResult AddNewIndexWithMappings()

foreach(KeyValuePair<string, string> lang in Languages)
{
var commerceIndexName = _settings.GetCommerceIndexName(lang.Key);
var commerceIndexName = _settings.GetCommerceIndexName(new CultureInfo(lang.Key));
CreateIndex(indexType, commerceIndexName);

ContentReference commerceRoot = _referenceConverter.GetRootLink();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Globalization;
using System.Web.Mvc;
using Epinova.ElasticSearch.Core.Contracts;
using Epinova.ElasticSearch.Core.EPiServer.Controllers;
Expand Down Expand Up @@ -31,7 +32,7 @@ public override ActionResult Index()
TypeName = GetTypeName(),
};

bool commerceSelected = _settings.GetCommerceIndexName(CurrentLanguage).Equals(CurrentIndex);
bool commerceSelected = _settings.GetCommerceIndexName(new CultureInfo(CurrentLanguage)).Equals(CurrentIndex);

if(commerceSelected)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,19 @@
<Reference Include="System.Net" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Security" />
<Reference Include="System.Security.AccessControl, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.AccessControl.4.4.0\lib\net461\System.Security.AccessControl.dll</HintPath>
<Reference Include="System.Security.AccessControl, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Cryptography.Xml.4.4.0\lib\net461\System.Security.Cryptography.Xml.dll</HintPath>
<Reference Include="System.Security.Cryptography.Xml, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Cryptography.Xml.4.7.0\lib\net461\System.Security.Cryptography.Xml.dll</HintPath>
</Reference>
<Reference Include="System.Security.Permissions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Permissions.4.4.0\lib\net461\System.Security.Permissions.dll</HintPath>
<Reference Include="System.Security.Permissions, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Permissions.4.7.0\lib\net461\System.Security.Permissions.dll</HintPath>
</Reference>
<Reference Include="System.Security.Principal.Windows, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Principal.Windows.4.4.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
<Reference Include="System.Security.Principal.Windows, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
</Reference>
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Threading.AccessControl, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.AccessControl.4.4.0\lib\net461\System.Threading.AccessControl.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -221,6 +222,7 @@
<HintPath>..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="CatalogSearchHit.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Epinova.ElasticSearch.Core.Contracts;
using Epinova.ElasticSearch.Core.EPiServer.Extensions;
using Epinova.ElasticSearch.Core.EPiServer.Providers;
using Epinova.ElasticSearch.Core.Models;
using Epinova.ElasticSearch.Core.Settings;
using Epinova.ElasticSearch.Core.Utilities;
using EPiServer.Commerce.Catalog.ContentTypes;
using EPiServer.ServiceLocation;

namespace Epinova.ElasticSearch.Core.EPiServer.Commerce.Extensions
{
public static class CatalogExtensions
{
private static readonly ITrackingRepository TrackingRepository = ServiceLocator.Current.GetInstance<ITrackingRepository>();
private static readonly IElasticSearchSettings ElasticSearchSettings = ServiceLocator.Current.GetInstance<IElasticSearchSettings>();
private static readonly ITrackingRepository _trackingRepository = ServiceLocator.Current.GetInstance<ITrackingRepository>();
private static readonly IElasticSearchSettings _elasticSearchSettings = ServiceLocator.Current.GetInstance<IElasticSearchSettings>();

private static string GetIndexName(CultureInfo searchLanguage)
=> $"{ElasticSearchSettings.Index}-{Constants.CommerceProviderName}-{Language.GetLanguageCode(searchLanguage)}";

public static CatalogSearchResult<T> GetCatalogResults<T>(this IElasticSearchService<T> service)
where T : EntryContentBase
public static CatalogSearchResult<T> GetCatalogResults<T>(this IElasticSearchService<T> service) where T : EntryContentBase
{
service.UseIndex(GetIndexName(service.SearchLanguage));
service.UseIndex(_elasticSearchSettings.GetCommerceIndexName(service.SearchLanguage));

SearchResult results = service.GetResults();
return GetCatalogSearchResult(service, results);
}

public static async Task<CatalogSearchResult<T>> GetCatalogResultsAsync<T>(this IElasticSearchService<T> service)
where T : EntryContentBase
public static async Task<CatalogSearchResult<T>> GetCatalogResultsAsync<T>(this IElasticSearchService<T> service) where T : EntryContentBase
{
service.UseIndex(GetIndexName(service.SearchLanguage));
service.UseIndex(_elasticSearchSettings.GetCommerceIndexName(service.SearchLanguage));

SearchResult results = await service.GetResultsAsync();
return GetCatalogSearchResult(service, results);
Expand All @@ -54,14 +47,8 @@ private static CatalogSearchResult<T> GetCatalogSearchResult<T>(IElasticSearchSe
}
}

if(service.TrackSearch)
{
TrackingRepository.AddSearch(
Language.GetLanguageCode(service.SearchLanguage),
service.SearchText,
results.TotalHits == 0,
service.IndexName);
}
if(service.TrackSearch)
_trackingRepository.AddSearch(service, results.TotalHits == 0);

return new CatalogSearchResult<T>(results, hits);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Epinova AS")]
[assembly: AssemblyProduct("Epinova.ElasticSearch.Core.EPiServer.Commerce")]
[assembly: AssemblyCopyright("Copyright © 2020 - Epinova AS")]
[assembly: AssemblyCopyright("Copyright© 2022 - Epinova AS")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("f5a0a67a-4a0f-4a91-b54d-b3fcb1410765")]
[assembly: AssemblyVersion("11.7.3.0")]
[assembly: AssemblyFileVersion("11.7.3.0")]
[assembly: AssemblyInformationalVersion("11.7.3.0")]
[assembly: AssemblyVersion("11.7.4.0")]
[assembly: AssemblyFileVersion("11.7.4.0")]
[assembly: AssemblyInformationalVersion("11.7.4.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public CampaignSearchProvider() : base("campaigns")
ForceRootLookup = true;
}

protected override string GetSearchRoot()
=> RootService.Service.Get("SysCampaignRoot").ID.ToString();
protected override string GetSearchRoot() => RootService.Service.Get("SysCampaignRoot").ID.ToString();

protected override string[] GetProviderKeys()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Epinova.ElasticSearch.Core.EPiServer.Providers;
using Epinova.ElasticSearch.Core.Utilities;
using EPiServer.Core;
using EPiServer.Core.Internal;
using EPiServer.DataAbstraction;
Expand All @@ -22,12 +21,9 @@ public ProductSearchProvider() : base("product")
IconClass = ProviderConstants.CommerceCatalogIconCssClass;
AreaName = ProviderConstants.CommerceCatalogArea;
ForceRootLookup = true;
IndexName = GetIndexName();
IndexName = _elasticSearchSettings.GetCommerceIndexName(SearchLanguage);
}

private string GetIndexName()
=> $"{_elasticSearchSettings.Index}-{Constants.CommerceProviderName}-{Language.GetRequestLanguageCode()}";

protected override string GetSearchRoot() => ReferenceConverter.Service.GetRootLink().ID.ToString();

protected override string[] GetProviderKeys()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<package id="System.ComponentModel.Annotations" version="4.4.0" targetFramework="net461" />
<package id="System.Data.SqlClient" version="4.4.0" targetFramework="net461" />
<package id="System.Reflection.Emit" version="4.3.0" targetFramework="net461" />
<package id="System.Security.AccessControl" version="4.4.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Xml" version="4.4.0" targetFramework="net461" />
<package id="System.Security.Permissions" version="4.4.0" targetFramework="net461" />
<package id="System.Security.Principal.Windows" version="4.4.0" targetFramework="net461" />
<package id="System.Security.AccessControl" version="4.7.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Xml" version="4.7.0" targetFramework="net461" />
<package id="System.Security.Permissions" version="4.7.0" targetFramework="net461" />
<package id="System.Security.Principal.Windows" version="4.7.0" targetFramework="net461" />
<package id="System.Threading.AccessControl" version="4.4.0" targetFramework="net461" />
</packages>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Epinova.ElasticSearch.Core.EPiServer.Enums;
using Epinova.ElasticSearch.Core.Models.Bulk;
using EPiServer.Core;
Expand All @@ -8,12 +9,12 @@ namespace Epinova.ElasticSearch.Core.EPiServer.Contracts
{
public interface IIndexer
{
BulkBatchResult BulkUpdate(IEnumerable<IContent> contents, Action<string> logger, string indexName = null);
BulkBatchResult BulkUpdate(IEnumerable<IContent> contents, Action<string> logger, string index);
void Delete(ContentReference contentLink);
void Delete(IContent content, string indexName = null);
IndexingStatus UpdateStructure(IContent root, string indexName = null);
IndexingStatus Update(IContent content, string indexName = null);
string GetLanguage(IContent content);
CultureInfo GetLanguage(IContent content);
bool SkipIndexing(IContent content);
bool ShouldHideFromSearch(IContent content);
bool IsExcludedType(IContent content);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using Epinova.ElasticSearch.Core.Contracts;
using Epinova.ElasticSearch.Core.Models;
using Epinova.ElasticSearch.Core.Models.Admin;
using Epinova.ElasticSearch.Core.Settings;
using Epinova.ElasticSearch.Core.Settings.Configuration;
Expand Down Expand Up @@ -49,8 +51,11 @@ protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
CurrentLanguage = Request?.QueryString[LanguageParam] ?? Languages.First().Key;
CurrentIndex = Request?.QueryString[IndexParam] ?? Indices.FirstOrDefault(i => i.Index.EndsWith($"-{CurrentLanguage}"))?.Index;
CurrentIndexDisplayName = Indices.FirstOrDefault(i => i.Index == CurrentIndex)?.DisplayName;
var language = new CultureInfo(CurrentLanguage);

CurrentIndex = Request?.QueryString[IndexParam] ?? _settings.GetDefaultIndexName(language);

CurrentIndexDisplayName = Indices.FirstOrDefault(i => i.Index.Equals(_settings.GetCustomIndexName(CurrentIndex, language), StringComparison.OrdinalIgnoreCase))?.DisplayName;
}

protected override void OnResultExecuting(ResultExecutingContext filterContext)
Expand All @@ -71,33 +76,36 @@ protected override void OnResultExecuting(ResultExecutingContext filterContext)
}
}

protected string SwapLanguage(string indexName, string newLanguage)
protected string SwapLanguage(string indexName, CultureInfo newLanguage)
{
if(String.IsNullOrEmpty(indexName))
{
return null;
}

var lang = indexName.ToLower().Split('-').Last();
var nameWithoutLanguage = indexName.Substring(0, indexName.Length - lang.Length - 1);
return $"{nameWithoutLanguage}-{newLanguage}";
return _settings.GetCustomIndexName(_settings.GetIndexNameWithoutLanguage(indexName), newLanguage);
}

protected List<IndexInformation> Indices { get; }

protected Dictionary<string, string> UniqueIndices =>
Indices.Select(i =>
{
var lang = i.Index.ToLower().Split('-').Last();
var nameWithoutLanguage = i.Index.Substring(0, i.Index.Length - lang.Length - 1);
return new
{
Index = nameWithoutLanguage,
i.DisplayName
};
})
.Distinct()
.ToDictionary(x => x.Index, x => x.DisplayName);
string lang = _settings.GetLanguageFromIndexName(i.Index);

return string.IsNullOrWhiteSpace(CurrentLanguage) ||
CurrentLanguage.Equals(lang, StringComparison.OrdinalIgnoreCase)
? new {i.Index, i.DisplayName}
: null;
})
.Where(i => i != null)
.Distinct()
.ToDictionary(x => x.Index, x => x.DisplayName);

protected Dictionary<string, string> UniqueIndicesNoLanguage =>
UniqueIndices.Select(i => new { Index = _settings.GetIndexNameWithoutLanguage(i.Key), DisplayName = i.Value })
.Distinct()
.ToDictionary(x => x.Index, x => x.DisplayName);

protected Dictionary<string, string> Languages { get; }

Expand All @@ -111,7 +119,7 @@ protected override void Initialize(RequestContext requestContext)

private List<IndexInformation> GetIndices()
{
var indexHelper = new Admin.Index(_serverInfoService, _settings, _httpClientHelper, "GetIndices-NA");
var indexHelper = new Admin.Index(_serverInfoService, _settings, _httpClientHelper, name: null);

var indices = indexHelper.GetIndices().ToList();

Expand All @@ -123,9 +131,17 @@ private List<IndexInformation> GetIndices()
.OrderByDescending(i => i.Name.Length)
.FirstOrDefault(i => indexInfo.Index.StartsWith(i.Name, StringComparison.InvariantCultureIgnoreCase));

indexInfo.Type = String.IsNullOrWhiteSpace(parsed?.Type)
? "[default]"
: Type.GetType(parsed.Type)?.Name;
if(String.IsNullOrWhiteSpace(parsed?.Type))
{
indexInfo.TypeName = "[default]";
indexInfo.Type = typeof(IndexItem);
}
else
{
Type type = Type.GetType(parsed.Type);
indexInfo.TypeName = type?.FullName;
indexInfo.Type = type;
}

if(parsed?.Default ?? false)
{
Expand Down
Loading

0 comments on commit 08e0b96

Please sign in to comment.