diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs index b525aa65d9..8e0a51324a 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs @@ -26,7 +26,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic _options = options.Value; } - public async Task CreateIndexIfNeededAsync(CancellationToken cancellationToken = default) + public virtual async Task CreateIndexIfNeededAsync(CancellationToken cancellationToken = default) { ValidateElasticSearchEnabled(); @@ -54,7 +54,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic } } - public async Task AddOrUpdateAsync(Document document, CancellationToken cancellationToken = default) + public virtual async Task AddOrUpdateAsync(Document document, CancellationToken cancellationToken = default) { ValidateElasticSearchEnabled(); @@ -67,13 +67,13 @@ namespace Volo.Docs.Documents.FullSearch.Elastic var esDocument = new EsDocument { - Id = document.Id, - ProjectId = document.ProjectId, + Id = NormalizeField(document.Id), + ProjectId = NormalizeField(document.ProjectId), Name = document.Name, FileName = document.FileName, Content = document.Content, - LanguageCode = ConvertLanguageCode(document.LanguageCode), - Version = ConvertVersion(document.Version) + LanguageCode = NormalizeField(document.LanguageCode), + Version = NormalizeField(document.Version) }; if (!existsResponse.Exists) @@ -89,7 +89,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic } - public async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default) + public virtual async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default) { ValidateElasticSearchEnabled(); @@ -97,7 +97,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic .DeleteAsync(DocumentPath.Id(id), x => x.Index(_options.IndexName), cancellationToken)); } - public async Task DeleteAllAsync(CancellationToken cancellationToken = default) + public virtual async Task DeleteAllAsync(CancellationToken cancellationToken = default) { ValidateElasticSearchEnabled(); @@ -110,7 +110,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic .DeleteByQueryAsync(request, cancellationToken)); } - public async Task DeleteAllByProjectIdAsync(Guid projectId, CancellationToken cancellationToken = default) + public virtual async Task DeleteAllByProjectIdAsync(Guid projectId, CancellationToken cancellationToken = default) { ValidateElasticSearchEnabled(); @@ -127,7 +127,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic new TermQuery { Field = "projectId", - Value = projectId + Value = NormalizeField(projectId) } } } @@ -139,7 +139,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic .DeleteByQueryAsync(request, cancellationToken)); } - public async Task> SearchAsync(string context, Guid projectId, string languageCode, + public virtual async Task> SearchAsync(string context, Guid projectId, string languageCode, string version, int? skipCount = null, int? maxResultCount = null, CancellationToken cancellationToken = default) { @@ -168,17 +168,17 @@ namespace Volo.Docs.Documents.FullSearch.Elastic new TermQuery { Field = "projectId", - Value = projectId + Value = NormalizeField(projectId) }, new TermQuery { Field = "version", - Value = ConvertVersion(version) + Value = NormalizeField(version) }, new TermQuery { Field = "languageCode", - Value = ConvertLanguageCode(languageCode) + Value = NormalizeField(languageCode) } } } @@ -216,7 +216,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic return docs; } - protected void HandleError(IElasticsearchResponse response) + protected virtual void HandleError(IElasticsearchResponse response) { if (!response.ApiCall.Success) { @@ -225,7 +225,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic } } - protected void ValidateElasticSearchEnabled() + protected virtual void ValidateElasticSearchEnabled() { if (!_options.Enable) { @@ -233,14 +233,14 @@ namespace Volo.Docs.Documents.FullSearch.Elastic } } - protected string ConvertLanguageCode(string languageCode) + protected virtual string NormalizeField(Guid field) { - return languageCode.Replace("-", "").ToLower(); + return NormalizeField(field.ToString("N")); } - protected string ConvertVersion(string version) + protected virtual string NormalizeField(string field) { - return version.Replace("-", "").ToLower(); + return field.Replace("-", "").ToLower(); } } } diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/EsDocument.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/EsDocument.cs index df78744361..be930d0ee1 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/EsDocument.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/EsDocument.cs @@ -10,9 +10,9 @@ namespace Volo.Docs.Documents.FullSearch.Elastic Highlight = new List(); } - public Guid Id { get; set; } + public string Id { get; set; } - public Guid ProjectId { get; set; } + public string ProjectId { get; set; } public string Name { get; set; } @@ -26,4 +26,4 @@ namespace Volo.Docs.Documents.FullSearch.Elastic public List Highlight { get; set; } } -} \ No newline at end of file +}