Browse Source

Check es is enabled.

pull/2901/head
maliming 7 years ago
parent
commit
3df7be2778
  1. 5
      modules/docs/app/VoloDocs.Web/VoloDocsWebModule.cs
  2. 7
      modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/DocsDomainErrorCodes.cs
  3. 22
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs
  4. 2
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json
  5. 2
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hans.json
  6. 1
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hant.json

5
modules/docs/app/VoloDocs.Web/VoloDocsWebModule.cs

@ -72,7 +72,10 @@ namespace VoloDocs.Web
options.RoutePrefix = null;
});
Configure<DocsElasticSearchOptions>(options => { options.Enable = true; });
Configure<DocsElasticSearchOptions>(options =>
{
options.Enable = true;
});
Configure<AbpDbConnectionOptions>(options =>
{

7
modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/DocsDomainErrorCodes.cs

@ -0,0 +1,7 @@
namespace Volo.Docs
{
public static class DocsDomainErrorCodes
{
public const string ElasticSearchNotEnabled = "Volo.Docs.Domain:010001";
}
}

22
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs

@ -19,16 +19,12 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
{
_clientProvider = clientProvider;
_options = options.Value;
if (!_options.Enable)
{
//TODO: localize message
throw new BusinessException("", "");
}
}
public async Task CreateIndexIfNeededAsync(CancellationToken cancellationToken = default)
{
CheckEsEnabled();
var client = _clientProvider.GetClient();
var existsResponse = await client.Indices.ExistsAsync(_options.IndexName, ct: cancellationToken);
@ -55,6 +51,8 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
public async Task AddOrUpdateAsync(Document document, CancellationToken cancellationToken = default)
{
CheckEsEnabled();
var client = _clientProvider.GetClient();
var existsResponse = await client.DocumentExistsAsync<EsDocument>(DocumentPath<EsDocument>.Id(document.Id),
@ -88,6 +86,8 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
public async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default)
{
CheckEsEnabled();
HandleError(await _clientProvider.GetClient()
.DeleteAsync(DocumentPath<Document>.Id(id), x => x.Index(_options.IndexName), cancellationToken));
}
@ -96,6 +96,8 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
string version, int? skipCount = null, int? maxResultCount = null,
CancellationToken cancellationToken = default)
{
CheckEsEnabled();
var request = new SearchRequest
{
Size = maxResultCount ?? 10,
@ -175,5 +177,13 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
throw response.ApiCall.OriginalException;
}
}
protected void CheckEsEnabled()
{
if (!_options.Enable)
{
throw new BusinessException(DocsDomainErrorCodes.ElasticSearchNotEnabled);
}
}
}
}

2
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json

@ -17,6 +17,8 @@
"NavigationDocumentNotFound": "This version does not have a navigation document!",
"DocumentNotFoundInSelectedLanguage": "Document in the language you wanted is not found. Document in the default language is shown.",
"FilterTopics": "Filter topics",
"FullSearch": "Search document",
"Volo.Docs.Domain:010001": "Elastic search is not enabled.",
"MultipleVersionDocumentInfo": "This document has multiple versions. Select the options best fit for you.",
"New": "New",
"Upd": "Upd",

2
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hans.json

@ -17,6 +17,8 @@
"NavigationDocumentNotFound": "这个版本没有导航文件!",
"DocumentNotFoundInSelectedLanguage": "本文档不适用于所选语言, 将以默认语言显示文档.",
"FilterTopics": "过滤主题",
"FullSearch": "搜索文档",
"Volo.Docs.Domain:010001": "Elastic search未启用.",
"New": "新文档",
"Upd": "更新",
"NewExplanation": "在最近两周内创建.",

1
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hant.json

@ -17,6 +17,7 @@
"NavigationDocumentNotFound": "這個版本沒有導覽文件!",
"DocumentNotFoundInSelectedLanguage": "本文件不適用於所選語系,將以預設語系顯示.",
"FilterTopics": "過濾主題",
"FullSearch": "搜索文件",
"New": "新文檔",
"Upd": "更新",
"NewExplanation": "在最近兩周內創建.",

Loading…
Cancel
Save