Merge pull request #5136 from abpframework/maliming/search-patch

Normalize projectId field.
pull/5140/head
liangshiwei 4 years ago committed by GitHub
commit 70472563dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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<Document>.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<List<EsDocument>> SearchAsync(string context, Guid projectId, string languageCode,
public virtual async Task<List<EsDocument>> 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();
}
}
}

@ -10,9 +10,9 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
Highlight = new List<string>();
}
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<string> Highlight { get; set; }
}
}
}

Loading…
Cancel
Save