-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support of Elasticsearch Token Filters #16843
Changes from all commits
6f0527b
b81ff24
6500770
478002d
0aaabb5
8ccbf7e
31e63c5
fa95b48
3f632a7
f8d82d3
4622246
0edcd4c
465d88b
808f8db
94a3d14
9fbfe86
4c30b21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Text.Json; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I like this code. It is cleaner. |
||
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; | ||
denispetrische marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ public class ElasticsearchOptions | |
public string IndexPrefix { get; set; } | ||
|
||
public Dictionary<string, JsonObject> Analyzers { get; } = []; | ||
|
||
public Dictionary<string, JsonObject> Filter { get; } = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should leave the name as "Filter", because it is how this section called in elasticsearch terminology. https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-custom-analyzer.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, ok, that's weird but I guess that we can live with it. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this was named Mappings because that's how ElasticSearch calls it in its terminology.
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, need to see what is the difference between GetIndexMappings and GetIndexInfo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you send me a screenshot of the resulting textfield in the Admin UI so that I can compare?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, here it is. The whole idea is to see that analyzers and filters were applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference now, is that shows not only "mappings" section but full index information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for IndexInfo then