diff --git a/Directory.Packages.props b/Directory.Packages.props index 869058edc6f..fd026ab9466 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -24,6 +24,7 @@ + @@ -57,7 +58,6 @@ - @@ -129,7 +129,6 @@ └─ System.IO.Packaging (v8.0.0) --> - - - - - diff --git a/OrchardCore.sln b/OrchardCore.sln index 962062771b3..53230701949 100644 --- a/OrchardCore.sln +++ b/OrchardCore.sln @@ -413,8 +413,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Roles.Core", "s EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.AutoSetup", "src\OrchardCore.Modules\OrchardCore.AutoSetup\OrchardCore.AutoSetup.csproj", "{1E76C17C-099A-4E6D-BC26-E93CBA4D0BD6}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Search.Elasticsearch.Abstractions", "src\OrchardCore\OrchardCore.Search.Elasticsearch.Abstractions\OrchardCore.Search.Elasticsearch.Abstractions.csproj", "{E6A90BFD-AB5C-4AED-A5AB-799136AB1521}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Search.Elasticsearch.Core", "src\OrchardCore\OrchardCore.Search.Elasticsearch.Core\OrchardCore.Search.Elasticsearch.Core.csproj", "{848C919B-6829-4758-9E59-51F13D25ABBC}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Search.Elasticsearch", "src\OrchardCore.Modules\OrchardCore.Search.Elasticsearch\OrchardCore.Search.Elasticsearch.csproj", "{B6A54EA8-F285-436D-8257-6F6EDE4C3339}" @@ -529,9 +527,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Sms.Azure", "sr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.UrlRewriting", "src\OrchardCore.Modules\OrchardCore.UrlRewriting\OrchardCore.UrlRewriting.csproj", "{D0F8B342-BDA8-44CB-AA43-7A65C79636A2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.UrlRewriting.Abstractions", "src\OrchardCore\OrchardCore.UrlRewriting.Abstractions\OrchardCore.UrlRewriting.Abstractions.csproj", "{675C8A76-C64F-47EC-B4F5-06D4F2D9662A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.UrlRewriting.Abstractions", "src\OrchardCore\OrchardCore.UrlRewriting.Abstractions\OrchardCore.UrlRewriting.Abstractions.csproj", "{675C8A76-C64F-47EC-B4F5-06D4F2D9662A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.UrlRewriting.Core", "src\OrchardCore\OrchardCore.UrlRewriting.Core\OrchardCore.UrlRewriting.Core.csproj", "{7B18DD99-A7BB-4297-8679-D87289758756}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.UrlRewriting.Core", "src\OrchardCore\OrchardCore.UrlRewriting.Core\OrchardCore.UrlRewriting.Core.csproj", "{7B18DD99-A7BB-4297-8679-D87289758756}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -1223,10 +1221,6 @@ Global {1E76C17C-099A-4E6D-BC26-E93CBA4D0BD6}.Debug|Any CPU.Build.0 = Debug|Any CPU {1E76C17C-099A-4E6D-BC26-E93CBA4D0BD6}.Release|Any CPU.ActiveCfg = Release|Any CPU {1E76C17C-099A-4E6D-BC26-E93CBA4D0BD6}.Release|Any CPU.Build.0 = Release|Any CPU - {E6A90BFD-AB5C-4AED-A5AB-799136AB1521}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E6A90BFD-AB5C-4AED-A5AB-799136AB1521}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E6A90BFD-AB5C-4AED-A5AB-799136AB1521}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E6A90BFD-AB5C-4AED-A5AB-799136AB1521}.Release|Any CPU.Build.0 = Release|Any CPU {848C919B-6829-4758-9E59-51F13D25ABBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {848C919B-6829-4758-9E59-51F13D25ABBC}.Debug|Any CPU.Build.0 = Debug|Any CPU {848C919B-6829-4758-9E59-51F13D25ABBC}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -1603,7 +1597,6 @@ Global {1D0144D0-9E6D-441B-A393-B62F6DC8E97E} = {90030E85-0C4F-456F-B879-443E8A3F220D} {15E0499A-815D-4E98-B1E4-1C9D7B3D1461} = {F23AC6C2-DE44-4699-999D-3C478EF3D691} {1E76C17C-099A-4E6D-BC26-E93CBA4D0BD6} = {A066395F-6F73-45DC-B5A6-B4E306110DCE} - {E6A90BFD-AB5C-4AED-A5AB-799136AB1521} = {F23AC6C2-DE44-4699-999D-3C478EF3D691} {848C919B-6829-4758-9E59-51F13D25ABBC} = {F23AC6C2-DE44-4699-999D-3C478EF3D691} {B6A54EA8-F285-436D-8257-6F6EDE4C3339} = {90030E85-0C4F-456F-B879-443E8A3F220D} {F06E4E20-3675-4BA5-AD2D-4538FAB154D5} = {F23AC6C2-DE44-4699-999D-3C478EF3D691} diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs index bed76db348b..ea95680c672 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs @@ -41,17 +41,16 @@ public sealed class AdminController : Controller private readonly ILiquidTemplateManager _liquidTemplateManager; private readonly IContentDefinitionManager _contentDefinitionManager; private readonly IAuthorizationService _authorizationService; - private readonly IElasticQueryService _queryService; - private readonly ElasticIndexManager _elasticIndexManager; - private readonly ElasticIndexingService _elasticIndexingService; - private readonly ElasticIndexSettingsService _elasticIndexSettingsService; + private readonly ElasticsearchIndexManager _elasticIndexManager; + private readonly ElasticsearchIndexingService _elasticIndexingService; + private readonly ElasticsearchIndexSettingsService _elasticIndexSettingsService; private readonly JavaScriptEncoder _javaScriptEncoder; private readonly ElasticsearchOptions _elasticSearchOptions; private readonly INotifier _notifier; private readonly ILogger _logger; private readonly IOptions _templateOptions; - private readonly ElasticConnectionOptions _elasticConnectionOptions; - private readonly IShapeFactory _shapeFactory; + private readonly ElasticsearchQueryService _elasticQueryService; + private readonly ElasticsearchConnectionOptions _elasticConnectionOptions; private readonly ILocalizationService _localizationService; internal readonly IStringLocalizer S; @@ -63,17 +62,16 @@ public AdminController( ILiquidTemplateManager liquidTemplateManager, IContentDefinitionManager contentDefinitionManager, IAuthorizationService authorizationService, - IElasticQueryService queryService, - ElasticIndexManager elasticIndexManager, - ElasticIndexingService elasticIndexingService, - ElasticIndexSettingsService elasticIndexSettingsService, + ElasticsearchIndexManager elasticIndexManager, + ElasticsearchIndexingService elasticIndexingService, + ElasticsearchIndexSettingsService elasticIndexSettingsService, JavaScriptEncoder javaScriptEncoder, IOptions elasticSearchOptions, INotifier notifier, ILogger logger, IOptions templateOptions, - IOptions elasticConnectionOptions, - IShapeFactory shapeFactory, + IOptions elasticConnectionOptions, + ElasticsearchQueryService elasticQueryService, ILocalizationService localizationService, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer) @@ -83,7 +81,6 @@ public AdminController( _liquidTemplateManager = liquidTemplateManager; _contentDefinitionManager = contentDefinitionManager; _authorizationService = authorizationService; - _queryService = queryService; _elasticIndexManager = elasticIndexManager; _elasticIndexingService = elasticIndexingService; _elasticIndexSettingsService = elasticIndexSettingsService; @@ -92,21 +89,24 @@ public AdminController( _notifier = notifier; _logger = logger; _templateOptions = templateOptions; + _elasticQueryService = elasticQueryService; _elasticConnectionOptions = elasticConnectionOptions.Value; - _shapeFactory = shapeFactory; _localizationService = localizationService; S = stringLocalizer; H = htmlLocalizer; } - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + ContentOptions options, + PagerParameters pagerParameters, + [FromServices] IShapeFactory shapeFactory) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageElasticIndexes)) { return Forbid(); } - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return NotConfigured(); } @@ -137,7 +137,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, totalIndexes, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, totalIndexes, routeData); var model = new AdminIndexViewModel { @@ -153,7 +153,6 @@ public async Task Index(ContentOptions options, PagerParameters p new SelectListItem(S["Delete"], nameof(ContentsBulkAction.Remove)), ]; - return View(model); } @@ -162,7 +161,7 @@ public async Task Index(ContentOptions options, PagerParameters p public IActionResult IndexFilterPOST(AdminIndexViewModel model) => RedirectToAction(nameof(Index), new RouteValueDictionary { - { _optionsSearch, model.Options.Search } + { _optionsSearch, model.Options.Search }, }); public async Task Edit(string indexName = null) @@ -175,7 +174,7 @@ public async Task Edit(string indexName = null) return Forbid(); } - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return NotConfigured(); } @@ -214,7 +213,7 @@ public async Task EditPost(ElasticIndexSettingsViewModel model, st return Forbid(); } - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return BadRequest(); } @@ -314,7 +313,7 @@ public async Task Reset(string id) return Forbid(); } - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return BadRequest(); } @@ -340,7 +339,7 @@ public async Task Rebuild(string id) return Forbid(); } - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return BadRequest(); } @@ -378,7 +377,7 @@ public async Task Delete(ElasticIndexSettingsViewModel model) return Forbid(); } - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return BadRequest(); } @@ -412,7 +411,7 @@ public async Task ForceDelete(ElasticIndexSettingsViewModel model) return Forbid(); } - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return BadRequest(); } @@ -456,14 +455,14 @@ public async Task SyncSettings() return RedirectToAction(nameof(Index)); } - public async Task Query(string indexName, string query) + public Task Query(string indexName, string query) { - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { - return NotConfigured(); + return Task.FromResult(NotConfigured()); } - return await Query(new AdminQueryViewModel + return Query(new AdminQueryViewModel { IndexName = indexName, DecodedQuery = string.IsNullOrWhiteSpace(query) @@ -480,7 +479,7 @@ public async Task Query(AdminQueryViewModel model) return Forbid(); } - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return BadRequest(); } @@ -521,13 +520,13 @@ public async Task Query(AdminQueryViewModel model) try { - var elasticTopDocs = await _queryService.SearchAsync(model.IndexName, tokenizedContent); + var results = await _elasticQueryService.SearchAsync(model.IndexName, tokenizedContent); - if (elasticTopDocs != null) + if (results != null) { - model.Documents = elasticTopDocs.TopDocs.Where(x => x != null); - model.Fields = elasticTopDocs.Fields; - model.Count = elasticTopDocs.Count; + model.Documents = results.TopDocs; + model.Fields = results.Fields; + model.Count = results.Count; } } catch (Exception e) @@ -550,7 +549,7 @@ public async Task IndexPost(ContentOptions options, IEnumerable HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("sync-content-items-elasticsearch-" + indexName, async (scope) => { - var indexingService = scope.ServiceProvider.GetRequiredService(); + var indexingService = scope.ServiceProvider.GetRequiredService(); await indexingService.ProcessContentItemsAsync(indexName); }); } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/ElasticsearchApiController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/ElasticsearchApiController.cs index db37262efcf..db0e94abc23 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/ElasticsearchApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/ElasticsearchApiController.cs @@ -83,7 +83,7 @@ public async Task DocumentsPost(ElasticApiQueryViewModel queryMod private async Task ElasticQueryApiAsync(ElasticApiQueryViewModel queryModel, bool returnContentItems = false) { - var elasticQuery = await _queryManager.NewAsync(ElasticQuerySource.SourceName); + var elasticQuery = await _queryManager.NewAsync(ElasticsearchQuerySource.SourceName); elasticQuery.ReturnContentItems = returnContentItems; elasticQuery.Put(new ElasticsearchQueryMetadata diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ContentPickerFieldElasticEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ContentPickerFieldElasticEditorSettingsDriver.cs index 2911468ecab..3e044552caf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ContentPickerFieldElasticEditorSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ContentPickerFieldElasticEditorSettingsDriver.cs @@ -9,9 +9,9 @@ namespace OrchardCore.Search.Elasticsearch.Drivers; public sealed class ContentPickerFieldElasticEditorSettingsDriver : ContentPartFieldDefinitionDisplayDriver { - private readonly ElasticIndexSettingsService _elasticIndexSettingsService; + private readonly ElasticsearchIndexSettingsService _elasticIndexSettingsService; - public ContentPickerFieldElasticEditorSettingsDriver(ElasticIndexSettingsService elasticIndexSettingsService) + public ContentPickerFieldElasticEditorSettingsDriver(ElasticsearchIndexSettingsService elasticIndexSettingsService) { _elasticIndexSettingsService = elasticIndexSettingsService; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexDeploymentStepDriver.cs index 0dc815c631b..04bcb36ccdd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexDeploymentStepDriver.cs @@ -6,16 +6,16 @@ namespace OrchardCore.Search.Elasticsearch.Core.Deployment; -public sealed class ElasticIndexDeploymentStepDriver : DisplayDriver +public sealed class ElasticIndexDeploymentStepDriver : DisplayDriver { - private readonly ElasticIndexSettingsService _elasticIndexSettingsService; + private readonly ElasticsearchIndexSettingsService _elasticIndexSettingsService; - public ElasticIndexDeploymentStepDriver(ElasticIndexSettingsService elasticIndexSettingsService) + public ElasticIndexDeploymentStepDriver(ElasticsearchIndexSettingsService elasticIndexSettingsService) { _elasticIndexSettingsService = elasticIndexSettingsService; } - public override Task DisplayAsync(ElasticIndexDeploymentStep step, BuildDisplayContext context) + public override Task DisplayAsync(ElasticsearchIndexDeploymentStep step, BuildDisplayContext context) { return CombineAsync( @@ -24,7 +24,7 @@ public override Task DisplayAsync(ElasticIndexDeploymentStep ste ); } - public override IDisplayResult Edit(ElasticIndexDeploymentStep step, BuildEditorContext context) + public override IDisplayResult Edit(ElasticsearchIndexDeploymentStep step, BuildEditorContext context) { return Initialize("ElasticIndexDeploymentStep_Fields_Edit", async model => { @@ -34,7 +34,7 @@ public override IDisplayResult Edit(ElasticIndexDeploymentStep step, BuildEditor }).Location("Content"); } - public override async Task UpdateAsync(ElasticIndexDeploymentStep step, UpdateEditorContext context) + public override async Task UpdateAsync(ElasticsearchIndexDeploymentStep step, UpdateEditorContext context) { step.IndexNames = []; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexRebuildDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexRebuildDeploymentStepDriver.cs index 1e8ea4e7395..7803f95c505 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexRebuildDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexRebuildDeploymentStepDriver.cs @@ -6,16 +6,16 @@ namespace OrchardCore.Search.Elasticsearch.Core.Deployment; -public sealed class ElasticIndexRebuildDeploymentStepDriver : DisplayDriver +public sealed class ElasticIndexRebuildDeploymentStepDriver : DisplayDriver { - private readonly ElasticIndexSettingsService _elasticIndexSettingsService; + private readonly ElasticsearchIndexSettingsService _elasticIndexSettingsService; - public ElasticIndexRebuildDeploymentStepDriver(ElasticIndexSettingsService elasticIndexSettingsService) + public ElasticIndexRebuildDeploymentStepDriver(ElasticsearchIndexSettingsService elasticIndexSettingsService) { _elasticIndexSettingsService = elasticIndexSettingsService; } - public override Task DisplayAsync(ElasticIndexRebuildDeploymentStep step, BuildDisplayContext context) + public override Task DisplayAsync(ElasticsearchIndexRebuildDeploymentStep step, BuildDisplayContext context) { return CombineAsync( @@ -24,7 +24,7 @@ public override Task DisplayAsync(ElasticIndexRebuildDeploymentS ); } - public override IDisplayResult Edit(ElasticIndexRebuildDeploymentStep step, BuildEditorContext context) + public override IDisplayResult Edit(ElasticsearchIndexRebuildDeploymentStep step, BuildEditorContext context) { return Initialize("ElasticIndexRebuildDeploymentStep_Fields_Edit", async model => { @@ -34,7 +34,7 @@ public override IDisplayResult Edit(ElasticIndexRebuildDeploymentStep step, Buil }).Location("Content"); } - public override async Task UpdateAsync(ElasticIndexRebuildDeploymentStep rebuildIndexStep, UpdateEditorContext context) + public override async Task UpdateAsync(ElasticsearchIndexRebuildDeploymentStep rebuildIndexStep, UpdateEditorContext context) { rebuildIndexStep.Indices = []; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexResetDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexResetDeploymentStepDriver.cs index e43e1e7df87..d929943a332 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexResetDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticIndexResetDeploymentStepDriver.cs @@ -6,16 +6,16 @@ namespace OrchardCore.Search.Elasticsearch.Core.Deployment; -public sealed class ElasticIndexResetDeploymentStepDriver : DisplayDriver +public sealed class ElasticIndexResetDeploymentStepDriver : DisplayDriver { - private readonly ElasticIndexSettingsService _elasticIndexSettingsService; + private readonly ElasticsearchIndexSettingsService _elasticIndexSettingsService; - public ElasticIndexResetDeploymentStepDriver(ElasticIndexSettingsService elasticIndexSettingsService) + public ElasticIndexResetDeploymentStepDriver(ElasticsearchIndexSettingsService elasticIndexSettingsService) { _elasticIndexSettingsService = elasticIndexSettingsService; } - public override Task DisplayAsync(ElasticIndexResetDeploymentStep step, BuildDisplayContext context) + public override Task DisplayAsync(ElasticsearchIndexResetDeploymentStep step, BuildDisplayContext context) { return CombineAsync( @@ -24,7 +24,7 @@ public override Task DisplayAsync(ElasticIndexResetDeploymentSte ); } - public override IDisplayResult Edit(ElasticIndexResetDeploymentStep step, BuildEditorContext context) + public override IDisplayResult Edit(ElasticsearchIndexResetDeploymentStep step, BuildEditorContext context) { return Initialize("ElasticIndexResetDeploymentStep_Fields_Edit", async model => { @@ -34,7 +34,7 @@ public override IDisplayResult Edit(ElasticIndexResetDeploymentStep step, BuildE }).Location("Content"); } - public override async Task UpdateAsync(ElasticIndexResetDeploymentStep resetIndexStep, UpdateEditorContext context) + public override async Task UpdateAsync(ElasticsearchIndexResetDeploymentStep resetIndexStep, UpdateEditorContext context) { resetIndexStep.Indices = []; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticSettingsDisplayDriver.cs index 6ef78eec748..9c83d7fefdd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticSettingsDisplayDriver.cs @@ -1,11 +1,11 @@ using System.Text; using System.Text.Json; using System.Text.Json.Nodes; +using Elastic.Clients.Elasticsearch; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; -using Nest; using OrchardCore.DisplayManagement.Entities; using OrchardCore.DisplayManagement.Handlers; using OrchardCore.DisplayManagement.Views; @@ -21,11 +21,11 @@ public sealed class ElasticSettingsDisplayDriver : SiteDisplayDriver SearchConstants.SearchSettingsGroupId; public ElasticSettingsDisplayDriver( - ElasticIndexSettingsService elasticIndexSettingsService, + ElasticsearchIndexSettingsService elasticIndexSettingsService, IHttpContextAccessor httpContextAccessor, IAuthorizationService authorizationService, - IOptions elasticConnectionOptions, - IElasticClient elasticClient, + IOptions elasticConnectionOptions, + ElasticsearchClient elasticClient, IStringLocalizer stringLocalizer ) { @@ -57,7 +57,8 @@ public override IDisplayResult Edit(ISite site, ElasticSettings settings, BuildE model.SearchIndexes = (await _elasticIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName); model.DefaultQuery = settings.DefaultQuery; model.SearchType = settings.GetSearchType(); - model.SearchTypes = [ + model.SearchTypes = + [ new(S["Multi-Match Query (Default)"], string.Empty), new(S["Query String Query"], ElasticSettings.QueryStringSearchType), new(S["Custom Query"], ElasticSettings.CustomSearchType), @@ -68,7 +69,7 @@ public override IDisplayResult Edit(ISite site, ElasticSettings settings, BuildE public override async Task UpdateAsync(ISite site, ElasticSettings section, UpdateEditorContext context) { - if (!_elasticConnectionOptions.FileConfigurationExists()) + if (!_elasticConnectionOptions.ConfigurationExists()) { return null; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticQueryDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticsearchQueryDisplayDriver.cs similarity index 84% rename from src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticQueryDisplayDriver.cs rename to src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticsearchQueryDisplayDriver.cs index 6f9714ee6f9..ecb5d76c1d6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticQueryDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticsearchQueryDisplayDriver.cs @@ -10,15 +10,15 @@ namespace OrchardCore.Search.Elasticsearch.Drivers; -public sealed class ElasticQueryDisplayDriver : DisplayDriver +public sealed class ElasticsearchQueryDisplayDriver : DisplayDriver { - private readonly ElasticIndexSettingsService _elasticIndexSettingsService; + private readonly ElasticsearchIndexSettingsService _elasticIndexSettingsService; internal readonly IStringLocalizer S; - public ElasticQueryDisplayDriver( - IStringLocalizer stringLocalizer, - ElasticIndexSettingsService elasticIndexSettingsService) + public ElasticsearchQueryDisplayDriver( + IStringLocalizer stringLocalizer, + ElasticsearchIndexSettingsService elasticIndexSettingsService) { _elasticIndexSettingsService = elasticIndexSettingsService; S = stringLocalizer; @@ -26,7 +26,7 @@ public ElasticQueryDisplayDriver( public override IDisplayResult Display(Query query, BuildDisplayContext context) { - if (query.Source != ElasticQuerySource.SourceName) + if (query.Source != ElasticsearchQuerySource.SourceName) { return null; } @@ -39,7 +39,7 @@ public override IDisplayResult Display(Query query, BuildDisplayContext context) public override IDisplayResult Edit(Query query, BuildEditorContext context) { - if (query.Source != ElasticQuerySource.SourceName) + if (query.Source != ElasticsearchQuerySource.SourceName) { return null; } @@ -63,7 +63,7 @@ public override IDisplayResult Edit(Query query, BuildEditorContext context) public override async Task UpdateAsync(Query query, UpdateEditorContext context) { - if (query.Source != ElasticQuerySource.SourceName) + if (query.Source != ElasticsearchQuerySource.SourceName) { return null; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/ElasticQueryFieldTypeProvider.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/ElasticsearchQueryFieldTypeProvider.cs similarity index 96% rename from src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/ElasticQueryFieldTypeProvider.cs rename to src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/ElasticsearchQueryFieldTypeProvider.cs index 69c3af6a794..adf942c4526 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/ElasticQueryFieldTypeProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/ElasticsearchQueryFieldTypeProvider.cs @@ -17,17 +17,17 @@ namespace OrchardCore.Search.Elasticsearch.GraphQL.Queries; -public sealed class ElasticQueryFieldTypeProvider : ISchemaBuilder +public sealed class ElasticsearchQueryFieldTypeProvider : ISchemaBuilder { private readonly IHttpContextAccessor _httpContextAccessor; private readonly ILogger _logger; internal readonly IStringLocalizer S; - public ElasticQueryFieldTypeProvider( + public ElasticsearchQueryFieldTypeProvider( IHttpContextAccessor httpContextAccessor, - IStringLocalizer stringLocalizer, - ILogger logger) + IStringLocalizer stringLocalizer, + ILogger logger) { _httpContextAccessor = httpContextAccessor; S = stringLocalizer; @@ -45,7 +45,7 @@ public async Task BuildAsync(ISchema schema) { var queryManager = _httpContextAccessor.HttpContext.RequestServices.GetService(); - var queries = await queryManager.ListQueriesBySourceAsync(ElasticQuerySource.SourceName); + var queries = await queryManager.ListQueriesBySourceAsync(ElasticsearchQuerySource.SourceName); foreach (var query in queries) { diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/Startup.cs index e64c0c5acf7..ffac91a376d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/GraphQL/Startup.cs @@ -13,6 +13,6 @@ public sealed class Startup : StartupBase { public override void ConfigureServices(IServiceCollection services) { - services.AddSingleton(); + services.AddSingleton(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs index 8e3f0e57dc3..64be928fd66 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs @@ -9,9 +9,14 @@ namespace OrchardCore.Search.Lucene.Handler; -public class ElasticsearchAuthorizationHandler(IServiceProvider serviceProvider) : AuthorizationHandler +public sealed class ElasticsearchAuthorizationHandler : AuthorizationHandler { - private readonly IServiceProvider _serviceProvider = serviceProvider; + private readonly IServiceProvider _serviceProvider; + + public ElasticsearchAuthorizationHandler(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } private IAuthorizationService _authorizationService; private ISiteService _siteService; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Migrations/ElasticsearchQueryMigrations.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Migrations/ElasticsearchQueryMigrations.cs index a4d94ac5a50..464139b70ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Migrations/ElasticsearchQueryMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Migrations/ElasticsearchQueryMigrations.cs @@ -9,7 +9,7 @@ public sealed class ElasticsearchQueryMigrations : DataMigration [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static")] public int Create() { - QueriesDocumentMigrationHelper.Migrate(ElasticQuerySource.SourceName); + QueriesDocumentMigrationHelper.Migrate(ElasticsearchQuerySource.SourceName); return 1; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/OrchardCore.Search.Elasticsearch.csproj b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/OrchardCore.Search.Elasticsearch.csproj index 3f212daa56e..eb6523fa4d3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/OrchardCore.Search.Elasticsearch.csproj +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/OrchardCore.Search.Elasticsearch.csproj @@ -15,6 +15,10 @@ + + + + @@ -26,8 +30,4 @@ - - - - diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Permissions.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/PermissionProvider.cs similarity index 61% rename from src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Permissions.cs rename to src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/PermissionProvider.cs index f1470ee9431..3509176e4b7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Permissions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/PermissionProvider.cs @@ -1,17 +1,13 @@ -using OrchardCore.Search.Elasticsearch.Core.Services; +using OrchardCore.Search.Elasticsearch.Core.Services; using OrchardCore.Security.Permissions; namespace OrchardCore.Search.Elasticsearch; -public sealed class Permissions : IPermissionProvider +public sealed class PermissionProvider : IPermissionProvider { - public static readonly Permission ManageElasticIndexes = new("ManageElasticIndexes", "Manage Elasticsearch Indexes"); + private readonly ElasticsearchIndexSettingsService _elasticIndexSettingsService; - public static readonly Permission QueryElasticApi = new("QueryElasticsearchApi", "Query Elasticsearch Api", [ManageElasticIndexes]); - - private readonly ElasticIndexSettingsService _elasticIndexSettingsService; - - public Permissions(ElasticIndexSettingsService elasticIndexSettingsService) + public PermissionProvider(ElasticsearchIndexSettingsService elasticIndexSettingsService) { _elasticIndexSettingsService = elasticIndexSettingsService; } @@ -20,8 +16,8 @@ public async Task> GetPermissionsAsync() { var permissions = new List() { - ManageElasticIndexes, - QueryElasticApi, + Permissions.ManageElasticIndexes, + Permissions.QueryElasticApi, }; var elasticIndexSettings = await _elasticIndexSettingsService.GetSettingsAsync(); @@ -41,7 +37,7 @@ public IEnumerable GetDefaultStereotypes() => Name = OrchardCoreConstants.Roles.Administrator, Permissions = [ - ManageElasticIndexes, + Permissions.ManageElasticIndexes, ], }, new PermissionStereotype @@ -49,7 +45,7 @@ public IEnumerable GetDefaultStereotypes() => Name = OrchardCoreConstants.Roles.Editor, Permissions = [ - QueryElasticApi, + Permissions.QueryElasticApi, ], }, ]; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs index 339a1b62264..cae2c730204 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using Nest; using OrchardCore.BackgroundTasks; using OrchardCore.ContentManagement; using OrchardCore.ContentTypes.Editors; @@ -38,28 +37,27 @@ public Startup(IShellConfiguration shellConfiguration) public override void ConfigureServices(IServiceCollection services) { - services.AddTransient, ElasticConnectionOptionsConfigurations>(); - - services.AddSingleton((sp) => + services.AddTransient, ElasticsearchConnectionOptionsConfigurations>(); + services.AddSingleton((sp) => { - var options = sp.GetRequiredService>().Value; + var options = sp.GetRequiredService>().Value; - return new ElasticClient(options.GetConnectionSettings() ?? new ConnectionSettings()); + return ElasticsearchClientFactory.Create(options); }); services.Configure(options => { - var configuration = _shellConfiguration.GetSection(ElasticConnectionOptionsConfigurations.ConfigSectionName); + var configuration = _shellConfiguration.GetSection(ElasticsearchConnectionOptionsConfigurations.ConfigSectionName); options.AddIndexPrefix(configuration); options.AddTokenFilters(configuration); options.AddAnalyzers(configuration); }); - services.AddElasticServices(); - services.AddPermissionProvider(); + services.AddElasticsearchServices(); + services.AddPermissionProvider(); services.AddNavigationProvider(); - services.AddDisplayDriver(); + services.AddDisplayDriver(); services.AddDataMigration(); services.AddScoped(); } @@ -81,10 +79,10 @@ public sealed class DeploymentStartup : StartupBase { public override void ConfigureServices(IServiceCollection services) { - services.AddDeployment(); + services.AddDeployment(); services.AddDeployment(); - services.AddDeployment(); - services.AddDeployment(); + services.AddDeployment(); + services.AddDeployment(); } } @@ -102,7 +100,7 @@ public sealed class ElasticContentPickerStartup : StartupBase { public override void ConfigureServices(IServiceCollection services) { - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddShapeAttributes(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/AdminQueryViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/AdminQueryViewModel.cs index a3602c4664a..64206ac447b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/AdminQueryViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/AdminQueryViewModel.cs @@ -18,8 +18,8 @@ public class AdminQueryViewModel public TimeSpan Elapsed { get; set; } = TimeSpan.Zero; [BindNever] - public IEnumerable> Documents { get; set; } = []; + public IEnumerable Documents { get; set; } = []; [BindNever] - public IEnumerable> Fields { get; set; } = []; + public IEnumerable Fields { get; set; } = []; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/QueryIndexViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/QueryIndexViewModel.cs index 128cd4a1e9e..6ae07bb1ac0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/QueryIndexViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/ViewModels/QueryIndexViewModel.cs @@ -5,6 +5,7 @@ namespace OrchardCore.Search.Elasticsearch.ViewModels; public class QueryIndexViewModel { public string Query { get; set; } + public string IndexName { get; set; } [BindNever] diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Query.cshtml b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Query.cshtml index 1313f8ad119..1e75d4fcae2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Query.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Views/Admin/Query.cshtml @@ -1,5 +1,7 @@ @model OrchardCore.Search.Elasticsearch.ViewModels.AdminQueryViewModel @using OrchardCore.ContentManagement +@using System.Text.Json +@using Json.Path @inject IContentManager ContentManager @{ @@ -9,6 +11,8 @@ } }")); + var hasFields = Model.Fields?.Any() == true; + var hasDocuments = Model.Documents?.Any() == true; } @@ -54,15 +58,17 @@

@T["Found {0} result(s) in {1} ms", Model.Count.ToString(), Model.Elapsed.TotalMilliseconds.ToString()]

} -@if (Model.Documents.Any() || Model.Fields.Any()) + +@if (hasDocuments || hasFields) { } -@if (Model.Documents.Any()) + +@if (hasDocuments) { - var fieldNames = Model.Documents.SelectMany(d => d.Keys.Distinct()).Distinct().ToList(); + var fieldNames = Model.Documents.SelectMany(d => JsonSerializer.Deserialize>(d.Value).Keys).Distinct().ToArray();

@T["The results displayed in this table are coming from the _source data."]

@@ -86,9 +92,16 @@ { @(row++) - @foreach (var name in fieldNames) + @foreach (var fieldName in fieldNames) { - @(document.GetValueOrDefault(name)?.ToString() ?? string.Empty) + @if (document.Value.TryGetPropertyValue(fieldName, out var value)) + { + @value + } + else + { + + } } } @@ -96,10 +109,10 @@
} -@if (Model.Fields.Any()) + +@if (hasFields) { - var fields = Model.Fields.SelectMany(d => d.Distinct()).ToList(); - var fieldNames = fields.OrderBy(x => x.Key).Select(d => d.Key).Distinct().ToList(); + var fieldNames = Model.Fields.SelectMany(d => JsonSerializer.Deserialize>(d.Value).Keys).Distinct().ToArray();

@T["The results displayed in this table are coming from the field(s) data."]

@@ -119,27 +132,30 @@ @{ int row = 1; } - @foreach (var hit in Model.Fields) + @foreach (var field in Model.Fields) { @(row++) - - @for (int i = 0; i < fieldNames.Count; i++) + @foreach (var fieldName in fieldNames) { - var hitValues = (string[])hit.FirstOrDefault(x => x.Key == fieldNames[i]).Value; - - if (hitValues != null) + @if (field.Value.TryGetPropertyValue(fieldName, out var value)) { - var value = hitValues.First(); - var item = !string.IsNullOrEmpty(value) ? value : "NULL"; - - - @item - + @if (value.TryGetValue(out var terms)) + { + @string.Join(" ||| ", terms) + } + else if (value.TryGetValue(out var term)) + { + @term + } + else + { + @T["NULL"] + } } else { - NULL + @T["NULL"] } } @@ -148,8 +164,9 @@
} +