public async Task <ResultContract <object> > GetTagsByCondition([FromBody] ThemeSearchContract contract) { var result = new ResultContract <object>() { Code = 0, Msg = "查询成功" }; try { result = logic.GetTagsByCondition(contract); } catch (Exception e) { LogHelper.logError("条件查询ES失败:" + e.ToString()); result.Code = -1; result.Msg = e.Message; } return(result); }
/// <summary> /// 根据条件查询 /// </summary> /// <returns></returns> public ResultContract <object> GetTagsByCondition(ThemeSearchContract contract) { var data = new Dictionary <string, object>(); data.Add("index", ESIndex); data.Add("type", ESType); //排序 var sortmaps = new Dictionary <string, object>(); sortmaps.Add("uploadTime", "DESC"); data.Add("sortMaps", sortmaps); //范围条件 var rangeMaps = new List <Dictionary <string, object> >(); var rangeMap = new Dictionary <string, object>(); if (!string.IsNullOrWhiteSpace(contract.StartTime)) { rangeMap.Add("from", contract.StartTime); } if (!string.IsNullOrWhiteSpace(contract.EndTime)) { rangeMap.Add("to", contract.EndTime); } if (rangeMap.Count > 0) { rangeMap.Add("field", "uploadTime"); } rangeMaps.Add(rangeMap); data.Add("rangeMaps", rangeMaps); //精确查询条件 var mustQuery = new Dictionary <string, object>(); var mustnotQuery = new Dictionary <string, object>(); var shouldQuery = new Dictionary <string, object>(); if (!string.IsNullOrWhiteSpace(contract.FileType)) { List <string> FileTypeList = contract.FileType.Split(",").ToList(); List <string> QueryList = new List <string>(); foreach (var item in FileTypeList) { QueryList.Add(item.ToLower()); QueryList.Add(item.ToUpper()); } string[] fileTypeArray = QueryList.ToArray(); shouldQuery.Add("fileType", fileTypeArray); data.Add("inShouldQuery", shouldQuery); } if (!string.IsNullOrWhiteSpace(contract.NotFileType)) { List <string> notFileTypeList = contract.NotFileType.Split(",").ToList(); List <string> notQueryList = new List <string>(); foreach (var item in notFileTypeList) { notQueryList.Add(item.ToLower()); notQueryList.Add(item.ToUpper()); } string[] notfileTypeArray = notQueryList.ToArray(); mustnotQuery.Add("fileType", notfileTypeArray); data.Add("inMustnotQuery", mustnotQuery); } if (!string.IsNullOrWhiteSpace(contract.OrgId)) { mustQuery.Add("orgId", contract.OrgId); } if (!string.IsNullOrWhiteSpace(contract.AppId)) { mustQuery.Add("appId", contract.AppId); } if (!string.IsNullOrWhiteSpace(contract.Tags)) { mustQuery.Add("tags", contract.Tags); } if (!string.IsNullOrWhiteSpace(contract.ThemeType)) { mustQuery.Add("themeType", contract.ThemeType); } if (!string.IsNullOrWhiteSpace(contract.GroupId)) { mustQuery.Add("groupId", contract.GroupId); } if (!string.IsNullOrWhiteSpace(contract.IsUpload)) { mustQuery.Add("IsUpload", bool.Parse(contract.IsUpload)); } if (!string.IsNullOrWhiteSpace(contract.RetrievalText)) { var retrieval = new Dictionary <string, object>(); var query = new string[] { contract.RetrievalText }; retrieval.Add("query", query); var fields = new string[] { "fileId", "userId", "orgId", "appId", "groupId", "orgName", "fileName", "newFileName", "upload", "url", "tags", "fileType", "displayName", "remark", "thumbnailUrl" }; retrieval.Add("fields", fields); data.Add("inFullSearch", retrieval); } data.Add("mustQuery", mustQuery); data.Add("from", contract.From ?? 0); data.Add("size", contract.Size ?? 1000); LogHelper.logInfo("查询条件:" + SerializeHelper.serializeToString(data)); var result = HttpHelper.HttpPost(SerializeHelper.serializeToString(data), ESAddress + "/document/getTagsByCondition"); ResultContract <object> resultcontract = JsonConvert.DeserializeObject <ResultContract <object> >(result); if (resultcontract.Code == 200) { resultcontract.Code = 0; } return(resultcontract); }