/// <summary> /// 自动补全列表(配合Completion类型的字段进行使用) /// </summary> /// <param name="option"></param> /// <returns></returns> public List <ESSuggesModel> Suggest(ESSuggestionOption option) { SearchRequest request = new SearchRequest(option.IndexName, option.TypeName); List <ESSuggesModel> model = new List <ESSuggesModel>(); request.Suggest = new SuggestContainer(); foreach (var suggest in option.Suggests) { request.Suggest.Add($"suggest_{suggest.SuggestKey}", new SuggestBucket() { Prefix = option.Prefix, Completion = new CompletionSuggester() { Field = suggest.SuggestKey, Size = suggest.Size, SkipDuplicates = suggest.Distinct }, }); } var result = _es.Search <T>(request); SuggestDictionary <T> suggestDic = result.Suggest; foreach (var item in suggestDic) { Suggest <T>[] val = item.Value as Suggest <T>[]; if (val != null && val.Count() > 0) { foreach (var opt in val[0].Options) { string currentTxt = opt.Text; if (option.IsHighLight) { currentTxt = BuildHightLightString(currentTxt, option.Prefix, option.PreTag, option.PostTag); } model.Add(new ESSuggesModel() { Text = currentTxt, FromKey = item.Key.Split('_')[1] }); } } } return(model); }
public async Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken) { iprot.IncrementRecursionDepth(); try { TField field; await iprot.ReadStructBeginAsync(cancellationToken); while (true) { field = await iprot.ReadFieldBeginAsync(cancellationToken); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.I64) { Revision = await iprot.ReadI64Async(cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 2: if (field.Type == TType.I64) { NewRevision = await iprot.ReadI64Async(cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 3: if (field.Type == TType.List) { { Dictionaries = new List <SuggestDictionary>(); TList _list233 = await iprot.ReadListBeginAsync(cancellationToken); for (int _i234 = 0; _i234 < _list233.Count; ++_i234) { SuggestDictionary _elem235; _elem235 = new SuggestDictionary(); await _elem235.ReadAsync(iprot, cancellationToken); Dictionaries.Add(_elem235); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 4: if (field.Type == TType.List) { { PreloadedDictionaries = new List <string>(); TList _list236 = await iprot.ReadListBeginAsync(cancellationToken); for (int _i237 = 0; _i237 < _list236.Count; ++_i237) { string _elem238; _elem238 = await iprot.ReadStringAsync(cancellationToken); PreloadedDictionaries.Add(_elem238); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; default: await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); break; } await iprot.ReadFieldEndAsync(cancellationToken); } await iprot.ReadStructEndAsync(cancellationToken); } finally { iprot.DecrementRecursionDepth(); } }
public void Read(TProtocol iprot) { iprot.IncrementRecursionDepth(); try { TField field; iprot.ReadStructBegin(); while (true) { field = iprot.ReadFieldBegin(); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.I64) { Revision = iprot.ReadI64(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 2: if (field.Type == TType.I64) { NewRevision = iprot.ReadI64(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 3: if (field.Type == TType.List) { { Dictionaries = new List <SuggestDictionary>(); TList _list233 = iprot.ReadListBegin(); for (int _i234 = 0; _i234 < _list233.Count; ++_i234) { SuggestDictionary _elem235; _elem235 = new SuggestDictionary(); _elem235.Read(iprot); Dictionaries.Add(_elem235); } iprot.ReadListEnd(); } } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 4: if (field.Type == TType.List) { { PreloadedDictionaries = new List <string>(); TList _list236 = iprot.ReadListBegin(); for (int _i237 = 0; _i237 < _list236.Count; ++_i237) { string _elem238; _elem238 = iprot.ReadString(); PreloadedDictionaries.Add(_elem238); } iprot.ReadListEnd(); } } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); } finally { iprot.DecrementRecursionDepth(); } }