Skip to content

Commit

Permalink
Register Search Member Access Strategy in the search module not the s…
Browse files Browse the repository at this point in the history
…earch providers (OrchardCMS#15035)
  • Loading branch information
MikeAlhayek authored and urbanit committed Mar 18, 2024
1 parent 3dd5da5 commit dc3b5f5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using Elasticsearch.Net;
using Fluid;
using GraphQL;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -33,7 +32,6 @@
using OrchardCore.Search.Elasticsearch.Drivers;
using OrchardCore.Search.Elasticsearch.Services;
using OrchardCore.Search.Lucene.Handler;
using OrchardCore.Search.ViewModels;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;

Expand Down Expand Up @@ -105,13 +103,6 @@ public override void ConfigureServices(IServiceCollection services)
}
});

services.Configure<TemplateOptions>(o =>
{
o.MemberAccessStrategy.Register<SearchIndexViewModel>();
o.MemberAccessStrategy.Register<SearchFormViewModel>();
o.MemberAccessStrategy.Register<SearchResultsViewModel>();
});

services.AddElasticServices();
services.AddScoped<IPermissionProvider, Permissions>();
services.AddScoped<INavigationProvider, AdminMenu>();
Expand Down
11 changes: 1 addition & 10 deletions src/OrchardCore.Modules/OrchardCore.Search.Lucene/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Fluid;
using Lucene.Net.Analysis.Standard;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -30,7 +29,6 @@
using OrchardCore.Search.Lucene.Recipes;
using OrchardCore.Search.Lucene.Services;
using OrchardCore.Search.Lucene.Settings;
using OrchardCore.Search.ViewModels;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;

Expand All @@ -47,13 +45,6 @@ public Startup(IOptions<AdminOptions> adminOptions)

public override void ConfigureServices(IServiceCollection services)
{
services.Configure<TemplateOptions>(o =>
{
o.MemberAccessStrategy.Register<SearchIndexViewModel>();
o.MemberAccessStrategy.Register<SearchFormViewModel>();
o.MemberAccessStrategy.Register<SearchResultsViewModel>();
});

services.AddDataMigration<Migrations>();
services.AddSingleton<LuceneIndexingState>();
services.AddSingleton<LuceneIndexSettingsService>();
Expand All @@ -74,7 +65,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IContentHandler, LuceneIndexingContentHandler>();
services.AddLuceneQueries();

// LuceneQuerySource is registered for both the Queries module and local usage
// LuceneQuerySource is registered for both the Queries module and local usage.
services.AddScoped<IQuerySource, LuceneQuerySource>();
services.AddScoped<LuceneQuerySource>();
services.AddRecipeExecutionStep<LuceneIndexStep>();
Expand Down
16 changes: 16 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Search/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Fluid;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -16,6 +17,7 @@
using OrchardCore.Search.Drivers;
using OrchardCore.Search.Migrations;
using OrchardCore.Search.Models;
using OrchardCore.Search.ViewModels;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;

Expand Down Expand Up @@ -60,4 +62,18 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IDisplayDriver<DeploymentStep>, SearchSettingsDeploymentStepDriver>();
}
}

[RequireFeatures("OrchardCore.Liquid")]
public class LiquidStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.Configure<TemplateOptions>(o =>
{
o.MemberAccessStrategy.Register<SearchIndexViewModel>();
o.MemberAccessStrategy.Register<SearchFormViewModel>();
o.MemberAccessStrategy.Register<SearchResultsViewModel>();
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
}
else
{
<div class="alert alert-warning">@T["You need to enable at least one search provider (Lucene, Elasticsearch)."]</div>
<div class="alert alert-warning">@T["You need to enable at least one search provider (Lucene, Elasticsearch, or Azure AI Search)."]</div>
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@
using OrchardCore.Search.Elasticsearch.Core.Recipes;
using OrchardCore.Search.Elasticsearch.Core.Services;

namespace OrchardCore.Search.Elasticsearch
namespace OrchardCore.Search.Elasticsearch;

public static class ServiceCollectionExtensions
{
public static class ServiceCollectionExtensions
/// <summary>
/// Adds Elastic services.
/// </summary>
public static IServiceCollection AddElasticServices(this IServiceCollection services)
{
/// <summary>
/// Adds Elastic services.
/// </summary>
public static IServiceCollection AddElasticServices(this IServiceCollection services)
{
services.AddSingleton<ElasticIndexSettingsService>();
services.AddSingleton<ElasticIndexManager>();
services.AddScoped<ElasticIndexingService>();
services.AddScoped<IModularTenantEvents, ElasticIndexInitializerService>();
services.AddScoped<IElasticSearchQueryService, ElasticSearchQueryService>();
services.AddScoped<IElasticQueryService, ElasticQueryService>();
services.AddScoped<IContentHandler, ElasticIndexingContentHandler>();
services.AddSingleton<ElasticIndexSettingsService>();
services.AddSingleton<ElasticIndexManager>();
services.AddScoped<ElasticIndexingService>();
services.AddScoped<IModularTenantEvents, ElasticIndexInitializerService>();
services.AddScoped<IElasticSearchQueryService, ElasticSearchQueryService>();
services.AddScoped<IElasticQueryService, ElasticQueryService>();
services.AddScoped<IContentHandler, ElasticIndexingContentHandler>();

// ElasticQuerySource is registered for both the Queries module and local usage
services.AddScoped<IQuerySource, ElasticQuerySource>();
services.AddScoped<ElasticQuerySource>();
services.AddRecipeExecutionStep<ElasticIndexStep>();
services.AddRecipeExecutionStep<ElasticSettingsStep>();
services.AddRecipeExecutionStep<ElasticIndexRebuildStep>();
services.AddRecipeExecutionStep<ElasticIndexResetStep>();
// ElasticQuerySource is registered for both the Queries module and local usage.
services.AddScoped<IQuerySource, ElasticQuerySource>();
services.AddScoped<ElasticQuerySource>();
services.AddRecipeExecutionStep<ElasticIndexStep>();
services.AddRecipeExecutionStep<ElasticSettingsStep>();
services.AddRecipeExecutionStep<ElasticIndexRebuildStep>();
services.AddRecipeExecutionStep<ElasticIndexResetStep>();

return services;
}
return services;
}
}

0 comments on commit dc3b5f5

Please sign in to comment.