public IEnumerable <HouseInfo> Search(HouseCondition condition) { if (string.IsNullOrEmpty(condition.Source)) { var houseList = new List <HouseInfo>(); // 获取当前城市的房源配置 var cityConfigs = _configService.LoadSources(condition.CityName); var limitCount = condition.HouseCount / cityConfigs.Count; foreach (var config in cityConfigs) { //建荣家园数据质量比较差,默认不出 if (config.Source == ConstConfigName.CCBHouse) { continue; } condition.Source = config.Source; condition.HouseCount = limitCount; houseList.AddRange(DBSearch(condition)); } return(houseList.OrderByDescending(h => h.PubTime)); } else { return(DBSearch(condition)); } }
public IEnumerable <DBHouse> NewSearch(HouseCondition condition) { if (condition == null) { return(default(List <DBHouse>)); } if (string.IsNullOrEmpty(condition.Source) && string.IsNullOrEmpty(condition.Keyword)) { var houseList = new List <DBHouse>(); // 获取当前城市的房源配置 var cityConfigs = _configService.LoadSources(condition.City); if (cityConfigs.Count == 0) { return(houseList); } var limitCount = condition.Size / cityConfigs.Count; foreach (var config in cityConfigs) { condition.Source = config.Source; condition.Size = limitCount; houseList.AddRange(NewDBSearch(condition)); } return(houseList.OrderByDescending(h => h.PubTime)); } else { return(NewDBSearch(condition)); } }
public void RefreshSearch(HouseCondition condition) { condition.Refresh = true; Search(condition); LogHelper.RunActionTaskNotThrowEx(() => { }, "RefreshSearch", condition); }
public void RefreshHouse() { LogHelper.Info("开始RefreshHouse..."); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var cityDashboards = _configService.LoadCitySources(); foreach (var item in cityDashboards) { //聚合房源的缓存,前600条数据 var search = new HouseCondition() { CityName = item.Key, HouseCount = 600, IntervalDay = 14, Refresh = true }; Search(search); foreach (var dashboard in item.Value) { //每类房源的默认缓存,前600条数据 search.HouseCount = 600; search.Source = dashboard.Source; this.Search(search); // 为小程序做的缓存,每次拉10条,一共20页 for (var page = 0; page <= 30; page++) { search.HouseCount = 20; search.Source = dashboard.Source; search.Page = page; this.Search(search); } } //为移动端做的缓存,每次拉180条,一共10页 for (var page = 0; page <= 10; page++) { search.Source = ""; search.HouseCount = 180; search.Page = page; this.Search(search); } //为小程序做的缓存,每次拉20条,一共30页 for (var page = 0; page <= 30; page++) { search.Source = ""; search.HouseCount = 20; search.Page = page; this.Search(search); } } sw.Stop(); string copyTime = sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture); LogHelper.Info("RefreshHouse结束,花费时间:" + copyTime); }
public List <DBHouse> SearchHouses(HouseCondition condition) { var houses = new List <DBHouse>(); using (IDbConnection dbConnection = GetConnection()) { dbConnection.Open(); houses = dbConnection.Query <DBHouse>(condition.QueryText, condition).ToList(); return(houses); } }
public IEnumerable <HouseInfo> SearchHouses(HouseCondition condition) { var houses = new List <HouseInfo>(); using (IDbConnection dbConnection = GetConnection()) { dbConnection.Open(); houses = dbConnection.Query <HouseInfo>(condition.QueryText, condition).ToList(); return(houses); } }
public void RefreshHouseV3() { Console.WriteLine("RefreshHouseV3..."); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var cityDashboards = _configService.LoadCitySources(); foreach (var item in cityDashboards) { //无指定来源,前600条数据 var condition = new HouseCondition() { City = item.Key, Refresh = true }; for (var page = 0; page <= 5; page++) { condition.Page = page; Console.WriteLine($"正在刷新[{condition.RedisKey}]缓存"); Search(condition); } //无指定来源,每次拉180条,一共10页,一般用于移动端地图 for (var page = 0; page <= 10; page++) { condition.Source = ""; condition.Size = 180; condition.Page = page; Console.WriteLine($"正在刷新[{condition.RedisKey}]缓存"); this.Search(condition); } //无指定来源,每次拉20条,一共30页,一般用于小程序或者移动端列表 for (var page = 0; page <= 30; page++) { condition.Source = ""; condition.Size = 20; condition.Page = page; Console.WriteLine($"正在刷新[{condition.RedisKey}]缓存"); this.Search(condition); } } sw.Stop(); string copyTime = sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture); Console.WriteLine("RefreshHouseV2结束,花费时间:" + copyTime); }
public void RefreshHouseV3() { LogHelper.Info("RefreshHouseV3..."); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var cityDashboards = _configService.LoadCitySources(); foreach (var item in cityDashboards) { //无指定来源,前600条数据 var search = new HouseCondition() { City = item.Key, Size = 600, IntervalDay = 14, Refresh = true }; for (var page = 0; page <= 5; page++) { search.Page = page; NewSearch(search); } //无指定来源,每次拉180条,一共10页,一般用于移动端地图 for (var page = 0; page <= 10; page++) { search.Source = ""; search.Size = 180; search.Page = page; this.NewSearch(search); } //无指定来源,每次拉20条,一共30页,一般用于小程序或者移动端列表 for (var page = 0; page <= 30; page++) { search.Source = ""; search.Size = 20; search.Page = page; this.NewSearch(search); } } sw.Stop(); string copyTime = sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture); LogHelper.Info("RefreshHouseV2结束,花费时间:" + copyTime); }
private static List <string> GetKeywords(HouseCondition condition) { var keywords = new List <string>(); if (condition.Keyword.Contains(",")) { keywords = condition.Keyword.Split(',').ToList(); } else if (condition.Keyword.Contains("|")) { keywords = condition.Keyword.Split('|').ToList(); } else { keywords.Add(condition.Keyword); } return(keywords); }
public List <DBHouse> SearchHouses(HouseCondition condition) { try { var houses = new List <DBHouse>(); using (IDbConnection dbConnection = GetConnection()) { dbConnection.Open(); houses = dbConnection.Query <DBHouse>(condition.QueryText, condition).ToList(); return(houses); } } catch (Exception ex) { LogHelper.Error("SearchHouses fail", ex, condition); return(new List <DBHouse>()); } }
private List <DBHouse> NewDBSearch(HouseCondition condition) { if (condition == null || condition.City == null) { throw new Exception("查询条件不能为null"); } var houses = _redisTool.ReadCache <List <DBHouse> >(condition.RedisKey, RedisKey.NewHouses.DBName); if (houses == null || condition.Refresh) { houses = !string.IsNullOrEmpty(condition.Keyword) ? _elasticService.Query(condition) : _newHouseDapper.SearchHouses(condition); if (houses != null) { _redisTool.WriteObject(condition.RedisKey, houses, RedisKey.NewHouses.DBName); } } return(houses); }
private static QueryContainer ConvertToQuery(HouseCondition condition, QueryContainerDescriptor <DBHouse> q) { List <string> keywords = GetKeywords(condition); var qcList = keywords.Select(k => ConvertToQueryContainer(k)).ToArray(); var query = q.Bool(b => b.Should(qcList).MinimumShouldMatch(1)) && q.Match(m => m.Field(f => f.City).Query(condition.City)); if (!string.IsNullOrEmpty(condition.Source)) { query = query && q.Match(m => m.Field(f => f.Source).Query(condition.Source)); } if (condition.FromPrice > 0 && condition.ToPrice > 0 && condition.ToPrice >= condition.ToPrice) { query = query && q.Range(r => r.Field(f => f.Price) .GreaterThanOrEquals(condition.FromPrice) .LessThanOrEquals(condition.ToPrice)); } return(query); }
private IEnumerable <HouseInfo> DBSearch(HouseCondition condition) { // LogHelper.Info($"Search start,key:{condition.RedisKey}"); if (condition == null || condition.CityName == null) { throw new Exception("查询条件不能为null"); } var houses = _redisTool.ReadCache <List <HouseInfo> >(condition.RedisKey, RedisKey.Houses.DBName); if (houses == null || houses.Count == 0 || condition.Refresh) { houses = _houseDapper.SearchHouses(condition).ToList(); if (houses != null && houses.Count > 0) { _redisTool.WriteObject(condition.RedisKey, houses, RedisKey.Houses.DBName); } } return(houses); }
public void RefreshHouseV2() { Console.WriteLine("开始RefreshHouseV2..."); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var cityDashboards = _configService.LoadCitySources(); foreach (var item in cityDashboards) { var condition = new HouseCondition() { City = item.Key, Refresh = true }; foreach (var dashboard in item.Value) { //指定来源,每次拉600条,一般用于地图页 for (var page = 0; page <= 3; page++) { condition.Size = 600; condition.Page = page; condition.Source = dashboard.Source; Console.WriteLine($"正在刷新[{condition.RedisKey}]缓存"); Search(condition); } // 指定来源,每次拉20条,前30页,一般用于小程序/移动端列表页 for (var page = 0; page <= 30; page++) { condition.Size = 20; condition.Source = dashboard.Source; condition.Page = page; Console.WriteLine($"正在刷新[{condition.RedisKey}]缓存"); this.Search(condition); } } } sw.Stop(); string copyTime = sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture); Console.WriteLine("RefreshHouseV2结束,花费时间:" + copyTime); }
public void RefreshHouseV2() { LogHelper.Info("开始RefreshHouseV2..."); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var cityDashboards = _configService.LoadCitySources(); foreach (var item in cityDashboards) { var search = new HouseCondition() { City = item.Key, Size = 600, IntervalDay = 14, Refresh = true }; foreach (var dashboard in item.Value) { //指定来源,每次拉600条,一般用于地图页 for (var page = 0; page <= 3; page++) { search.Size = 600; search.Page = page; search.Source = dashboard.Source; NewSearch(search); } // 指定来源,每次拉20条,前30页,一般用于小程序/移动端列表页 for (var page = 0; page <= 30; page++) { search.Size = 20; search.Source = dashboard.Source; search.Page = page; this.NewSearch(search); } } } sw.Stop(); string copyTime = sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture); LogHelper.Info("RefreshHouseV2结束,花费时间:" + copyTime); }
public List <DBHouse> Query(HouseCondition condition) { var searchRsp = _elasticClient.Search <DBHouse>(s => s .Index("house-data-*") .Explain() .From(condition.Page * condition.Page) .Size(condition.Size) .Sort(sort => sort.Descending(h => h.PubTime)) .Query(q => ConvertToQuery(condition, q)) ); if (searchRsp.IsValid) { return(searchRsp.Documents.ToList()); } else { LogHelper.Info(searchRsp.DebugInformation); } return(new List <DBHouse>()); }