public object GetOption(int indexType) { ISeeIndexServer server = BLL.SearchBLL.GetISeeServer(indexType); if (server == null) { return(new { Rcode = -1, Rmsg = "未获取到对应索引:" + indexType }); } return(new { Rcode = 1, Fields = server.Fields, Attrs = server.Attrs }); }
/// <summary> /// 获取检索结果 /// </summary> /// <param name="query">检索对象</param> /// <param name="usetime">检索用时</param> /// <param name="errmsg">错误信息</param> /// <returns>检索结果</returns> public static SearchResult SearchQuery(QuerySearchModel query, ref TimeSpan usetime, ref string errmsg) { ISeeClient ISee = new ISeeClient(); ISeeIndexServer ISeeServerInfo = GetISeeServer(query.restype); if (ISeeServerInfo == null) { errmsg = "未获取到对应索引:" + query.restype; return(null); } ISee.Ip = ISeeServerInfo.IP; ISee.Port = ISeeServerInfo.Port; ISee.AutoFilterTag = false;// ISeeServerInfo.AutoFilterTag; ISee.MaxMatchCount = ISeeServerInfo.MaxMatchCount; ISee.SearchMode = SearchMode.MatchExtended2; if (query.rows <= 0) { query.rows = ISeeServerInfo.MaxMatchCount; } SearchOptions option = new SearchOptions(); option.Limit = query.rows; option.Offset = (query.page - 1) * query.rows; option.Offset = option.Offset + ISee.Limit > ISeeServerInfo.MaxMatchCount ? (ISeeServerInfo.MaxMatchCount - ISee.Limit) : option.Offset; option.Index = ISeeServerInfo.Index; FilterAttrs(query.queryExp, query.restype, ref option, out errmsg); if (!string.IsNullOrEmpty(errmsg)) { return(null); } // 分组字段 if (!string.IsNullOrEmpty(query.groupName)) { option.GroupAttrName = query.groupName; option.ResultAttrs = query.groupName; // 分组排序 GroupSort groupSort = GroupSort.CountDesc; if (!string.IsNullOrEmpty(query.sortExp) && Enum.TryParse <GroupSort>(query.sortExp, out groupSort)) { option.GroupSort = groupSort; } else { option.GroupSort = GroupSort.CountDesc; // 默认 } } else { // 排序 if (!string.IsNullOrEmpty(query.sortExp)) { option.SortExp = query.sortExp; } //查询词计数 //if (!string.IsNullOrEmpty(option.KeyExp)) //{ // if (query.isSearch) // { // string _errmsg; // Regex regex = new Regex("[\u4e00-\u9fa5]+"); // Dictionary<string, int> keylist = new Dictionary<string, int>(); // foreach (Match match in regex.Matches(option.KeyExp)) // { // if (match.Success && match.Groups.Count > 0 && !keylist.ContainsKey(match.Groups[0].Value)) // keylist.Add(match.Groups[0].Value, 0); // } // if (keylist.Count > 0) // { // string[] keyarr = new string[keylist.Count]; // int i = 0; // foreach (string key in keylist.Keys) // { // keyarr[i] = key; // i++; // } // DAL.SearchDAL.UpdateHotKeyData(keyarr, out _errmsg); // } // } //} } // 查询结果 SearchResult results = ISee.Query(option); if (!string.IsNullOrEmpty(ISee.ErrMsg)) { errmsg = ISee.ErrMsg; return(null); } if (!string.IsNullOrEmpty(results.Warnmsg)) { } usetime = ISee.FoundTime; return(results); }