Esempio n. 1
0
        public IEnumerable <DBHouseInfo> Search(string cityName, string source = "",
                                                int houseCount = 100, int intervalDay = 7, string keyword = "", bool refresh = false)
        {
            string redisKey = $"{cityName}-{source}-{intervalDay}-{houseCount}-{keyword}";
            var    houses   = new List <DBHouseInfo>();

            if (!refresh)
            {
                houses = redisService.ReadSearchCache(redisKey);
                if (houses != null)
                {
                    return(houses);
                }
            }
            using (IDbConnection dbConnection = GetConnection())
            {
                dbConnection.Open();
                string search_SQL = $"SELECT * from { ConstConfigurationName.GetTableName(source)} where 1=1 " +
                                    $"and LocationCityName = @LocationCityName and  PubTime >= @PubTime";
                if (!string.IsNullOrEmpty(keyword))
                {
                    search_SQL = search_SQL + " and (HouseText like @KeyWord or HouseLocation like @KeyWord or HouseTitle like @KeyWord) ";
                }
                search_SQL = search_SQL + $" order by PubTime desc limit {houseCount} ";
                houses     = dbConnection.Query <DBHouseInfo>(search_SQL,
                                                              new
                {
                    LocationCityName = cityName,
                    KeyWord          = $"%{keyword}%",
                    PubTime          = DateTime.Now.Date.AddDays(-intervalDay)
                }).ToList();
                redisService.WriteSearchCache(redisKey, houses);
                return(houses);
            }
        }
Esempio n. 2
0
        public IEnumerable <HouseInfo> Search(HouseSearchCondition condition)
        {
            string redisKey = condition.RedisKey;
            var    houses   = new List <HouseInfo>();

            if (!condition.Refresh)
            {
                houses = redisService.ReadSearchCache(redisKey);
                if (houses != null && houses.Count > 0)
                {
                    return(houses);
                }
            }
            using (IDbConnection dbConnection = GetConnection())
            {
                dbConnection.Open();
                houses = dbConnection.Query <HouseInfo>(condition.QueryText, condition).ToList();
                if (houses != null && houses.Count > 0)
                {
                    redisService.WriteSearchCache(redisKey, houses);
                }
                return(houses);
            }
        }