-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of Elasticsearch Token Filters (#16843)
Co-authored-by: Hisham Bin Ateya <[email protected]>
- Loading branch information
1 parent
a7620c6
commit 99c8b77
Showing
8 changed files
with
563 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ore.Modules/OrchardCore.Search.Elasticsearch/Extensions/ElasticsearchOptionsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Microsoft.Extensions.Configuration; | ||
using OrchardCore.Environment.Shell.Configuration; | ||
|
||
namespace OrchardCore.Search.Elasticsearch; | ||
|
||
internal static class ElasticsearchOptionsExtensions | ||
{ | ||
internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions options, IConfigurationSection configuration) | ||
{ | ||
var jsonNode = configuration.GetSection(nameof(options.Analyzers)).AsJsonNode(); | ||
var jsonElement = JsonSerializer.Deserialize<JsonElement>(jsonNode); | ||
|
||
var analyzersObject = JsonObject.Create(jsonElement, new JsonNodeOptions() | ||
{ | ||
PropertyNameCaseInsensitive = true, | ||
}); | ||
|
||
if (analyzersObject is not null) | ||
{ | ||
if (jsonNode is JsonObject jAnalyzers) | ||
{ | ||
foreach (var analyzer in jAnalyzers) | ||
{ | ||
if (analyzer.Value is not JsonObject jAnalyzer) | ||
{ | ||
continue; | ||
} | ||
|
||
options.Analyzers.Add(analyzer.Key, jAnalyzer); | ||
} | ||
} | ||
} | ||
|
||
if (options.Analyzers.Count == 0) | ||
{ | ||
// When no analyzers are configured, we'll define a default analyzer. | ||
options.Analyzers.Add(ElasticsearchConstants.DefaultAnalyzer, new JsonObject | ||
{ | ||
["type"] = ElasticsearchConstants.DefaultAnalyzer, | ||
}); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
internal static ElasticsearchOptions AddFilter(this ElasticsearchOptions options, IConfigurationSection configuration) | ||
{ | ||
var jsonNode = configuration.GetSection(nameof(options.Filter)).AsJsonNode(); | ||
var jsonElement = JsonSerializer.Deserialize<JsonElement>(jsonNode); | ||
|
||
var filterObject = JsonObject.Create(jsonElement, new JsonNodeOptions() | ||
{ | ||
PropertyNameCaseInsensitive = true, | ||
}); | ||
|
||
if (filterObject is not null) | ||
{ | ||
if (jsonNode is JsonObject jFilters) | ||
{ | ||
foreach (var filter in jFilters) | ||
{ | ||
if (filter.Value is not JsonObject jFilter) | ||
{ | ||
continue; | ||
} | ||
|
||
options.Filter.Add(filter.Key, jFilter); | ||
} | ||
} | ||
} | ||
|
||
return options; | ||
} | ||
|
||
internal static ElasticsearchOptions AddIndexPrefix(this ElasticsearchOptions options, IConfigurationSection configuration) | ||
{ | ||
options.IndexPrefix = configuration.GetValue<string>(nameof(options.IndexPrefix)); | ||
|
||
return options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ticsearch/ViewModels/MappingsViewModel.cs → ...icsearch/ViewModels/IndexInfoViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
namespace OrchardCore.Search.Elasticsearch.ViewModels; | ||
|
||
public class MappingsViewModel | ||
public class IndexInfoViewModel | ||
{ | ||
public string IndexName { get; set; } | ||
public string Mappings { get; set; } | ||
public string IndexInfo { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.