public DocumentStorage( IElasticClient elasticClient, IOptions <DocumentStorageOptions> options, IContentStorage contentStorage, ITextHighlighter textHighlighter) { this.elasticClient = elasticClient ?? throw new ArgumentNullException(nameof(elasticClient)); this.contentStorage = contentStorage ?? throw new ArgumentNullException(nameof(contentStorage)); this.textHighlighter = textHighlighter ?? throw new ArgumentNullException(nameof(textHighlighter)); this.options = options?.Value ?? throw new ArgumentNullException(nameof(options)); }
/// <summary> /// Выполнение запроса /// </summary> /// <param name="query">Запрос</param> /// <param name="options">Параметры запроса</param> /// <returns>Результирующий <see cref="XElement"/></returns> public XElement ExecuteQuery(string query, DocumentStorageOptions options = null) { if (null == _bSharpContext) { return(null); } XElement result; string ns = null; if (options != null) { if (!string.IsNullOrWhiteSpace(options.Collection)) { ns = options.Collection; } } var selected = _bSharpContext.ResolveAll(query, ns).ToArray(); if (selected.Length == 0) { if (WrapAlways) { result = new XElement(WrapperName); result.SetAttributeValue(IsEmptyResultAttribute, true); } else { result = null; } } else if (selected.Length == 1) { if (WrapAlways) { result = new XElement(WrapperName); result.Add(selected[0].Compiled); } else { result = selected[0].Compiled; } } else { result = new XElement(WrapperName); result.SetAttributeValue(IsComplexResultAttribute, true); foreach (var bSharpClass in selected) { result.Add(bSharpClass.Compiled); } } return(result); }
private static void InitIndex(IElasticClient elasticClient, DocumentStorageOptions options) { if (!elasticClient.Indices.Exists(options.IndexName).Exists) { var response = elasticClient.Indices.Create( options.IndexName, cid => cid .Settings(isd => isd .Setting("index.highlight.max_analyzed_offset", options.MaxAnalyzedOffsetForHighlighting))); if (!response.IsValid) { throw new InvalidOperationException("Unable to create index", response.OriginalException); } } }