Пример #1
0
        public IEnumerable <DBHouse> Search(DBHouseQuery 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;

                var limitCount = condition.Size > 0 ? condition.Size / cityConfigs.Count : 100;
                foreach (var config in cityConfigs)
                {
                    condition.Source = config.Source;
                    condition.Size   = limitCount;
                    houseList.AddRange(HouseQuery(condition));
                }
                return(houseList.OrderByDescending(h => h.PubTime));
            }
            else
            {
                if (condition.Size == 0)
                {
                    condition.Size = 1200;
                }
                return(HouseQuery(condition));
            }
        }
Пример #2
0
        public List <DBHouse> SearchHouses(DBHouseQuery condition)
        {
            var houses = new List <DBHouse>();

            using (IDbConnection dbConnection = GetConnection())
            {
                dbConnection.Open();
                houses = dbConnection.Query <DBHouse>(condition.QueryText, condition).ToList();
                return(houses);
            }
        }
Пример #3
0
        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 DBHouseQuery()
                {
                    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);
                    }

                    for (var page = 0; page <= 3; page++)
                    {
                        condition.Size   = 1200;
                        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);
        }
Пример #4
0
        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 DBHouseQuery()
                {
                    City = item.Key, Refresh = true
                };
                for (var page = 0; page <= 5; page++)
                {
                    condition.Page = page;
                    Console.WriteLine($"正在刷新[{condition.RedisKey}]缓存");
                    var dhHouses = Search(condition);
                    foreach (var dbHouse in dhHouses)
                    {
                        _houseMongoMapper.WriteRecord(new MongoHouseEntity(dbHouse));
                    }
                }

                //无指定来源,每次拉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);
        }
Пример #5
0
        private List <DBHouse> HouseQuery(DBHouseQuery condition)
        {
            if (condition == null || condition.City == null)
            {
                throw new Exception("查询条件不能为null");
            }
            var houses = _redisTool.ReadCache <List <DBHouse> >(condition.RedisKey, RedisKeys.NewHouses.DBName);

            if (houses == null || condition.Refresh)
            {
                houses = !string.IsNullOrEmpty(condition.Keyword) ? _elasticService.Query(condition) : _houseDapper.SearchHouses(condition);
                if (houses != null)
                {
                    _redisTool.WriteObject(condition.RedisKey, houses, RedisKeys.NewHouses.DBName);
                }
            }
            return(houses);
        }
Пример #6
0
        private static List <string> GetKeywords(DBHouseQuery 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);
        }
Пример #7
0
 public List<DBHouse> SearchHouses(DBHouseQuery 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>();
     }
 }
Пример #8
0
        private static QueryContainer ConvertToQuery(DBHouseQuery 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);
        }
Пример #9
0
        public List <DBHouse> Query(DBHouseQuery 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
                       .GroupBy(h => h.OnlineURL).Select(items => items.FirstOrDefault()).ToList());
            }
            else
            {
                LogHelper.Info(searchRsp.DebugInformation);
            }
            return(new List <DBHouse>());
        }
Пример #10
0
 public void RefreshSearch(DBHouseQuery condition)
 {
     condition.Refresh = true;
     Search(condition);
 }