mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.0 KiB
52 lines
2.0 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Squidex.Domain.Apps.Entities.Contents.Text;
|
|
using Squidex.Hosting;
|
|
using Squidex.Hosting.Configuration;
|
|
using Squidex.Infrastructure.Plugins;
|
|
|
|
namespace Squidex.Extensions.Text.ElasticSearch
|
|
{
|
|
public sealed class ElasticSearchTextPlugin : IPlugin
|
|
{
|
|
public void ConfigureServices(IServiceCollection services, IConfiguration config)
|
|
{
|
|
var fullTextType = config.GetValue<string>("fullText:type");
|
|
|
|
if (string.Equals(fullTextType, "elastic", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
var elasticConfiguration = config.GetValue<string>("fullText:elastic:configuration");
|
|
|
|
if (string.IsNullOrWhiteSpace(elasticConfiguration))
|
|
{
|
|
var error = new ConfigurationError("Value is required.", "fullText:elastic:configuration");
|
|
|
|
throw new ConfigurationException(error);
|
|
}
|
|
|
|
var indexName = config.GetValue<string>("fullText:elastic:indexName");
|
|
|
|
if (string.IsNullOrWhiteSpace(indexName))
|
|
{
|
|
indexName = "squidex-index";
|
|
}
|
|
|
|
services.AddSingleton(
|
|
c => new ElasticSearchTextIndex(elasticConfiguration, indexName));
|
|
|
|
services.AddSingleton<ITextIndex>(
|
|
c => c.GetRequiredService<ElasticSearchTextIndex>());
|
|
|
|
services.AddSingleton<IInitializable>(
|
|
c => c.GetRequiredService<ElasticSearchTextIndex>());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|