Skip to content

Commit

Permalink
Fix Elasticsearch Query API (#16426)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 12, 2024
1 parent be675b3 commit 93b9aa9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private static Dictionary<string, object> CreateElasticDocument(DocumentIndex do

public string GetFullIndexName(string indexName)
{
ArgumentException.ThrowIfNullOrEmpty(indexName, nameof(indexName));
ArgumentException.ThrowIfNullOrEmpty(indexName);

return GetIndexPrefix() + _separator + indexName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Nest;
using OrchardCore.Environment.Shell;

namespace OrchardCore.Search.Elasticsearch.Core.Services
{
public class ElasticQueryService : IElasticQueryService
{
private readonly string _indexPrefix;
private readonly IElasticClient _elasticClient;
private readonly ElasticIndexManager _elasticIndexManager;
private readonly ILogger _logger;

public ElasticQueryService(
IElasticClient elasticClient,
ShellSettings shellSettings,
ElasticIndexManager elasticIndexManager,
ILogger<ElasticQueryService> logger
)
{
_indexPrefix = shellSettings.Name.ToLowerInvariant() + "_";
_elasticClient = elasticClient;
_elasticIndexManager = elasticIndexManager;
_logger = logger;
}

public async Task<ElasticTopDocs> SearchAsync(string indexName, string query)
{
ArgumentException.ThrowIfNullOrEmpty(indexName);

var elasticTopDocs = new ElasticTopDocs();

if (_elasticClient == null)
Expand All @@ -40,7 +41,7 @@ public async Task<ElasticTopDocs> SearchAsync(string indexName, string query)
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(query));
var deserializedSearchRequest = _elasticClient.RequestResponseSerializer.Deserialize<SearchRequest>(stream);

var searchRequest = new SearchRequest(_indexPrefix + indexName)
var searchRequest = new SearchRequest(_elasticIndexManager.GetFullIndexName(indexName))
{
Query = deserializedSearchRequest.Query,
From = deserializedSearchRequest.From,
Expand Down

0 comments on commit 93b9aa9

Please sign in to comment.