Example #1
0
        public static IList <Attachment> GetCardsAttachments(SimpleSearchFilter filter, bool isKnownUser)
        {
            var    response      = GetSimpleSearchResult(filter);
            var    cards         = new List <Attachment>();
            string carDetailsUrl = ConfigurationManager.AppSettings["CarDetailsURL"];
            var    stores        = response.Stores;

            foreach (var car in response.SearchVehicles)
            {
                string price           = GetCarPrice(car, isKnownUser);
                string vin             = BotConstants.LABEL_VIN + BotConstants.LABEL_SPACE + car.Vehicle.Vin;
                string condition       = BotConstants.LABEL_CONDITION + BotConstants.LABEL_SPACE + car.Vehicle.StockType;
                string inventoryStatus = GetCarInventoryStatus(car);
                var    cardAction      = GetCardAction(car, isKnownUser);
                var    distance        = GetDistance(car, stores);

                cards.Add(CardHelper.GetHeroCard(
                              title: car.Name,
                              subtitle: vin + BotConstants.LABEL_NEW_LINE + condition + BotConstants.LABEL_NEW_LINE + inventoryStatus + BotConstants.LABEL_NEW_LINE + distance,
                              text: price,
                              cardImages: new List <CardImage> {
                    new CardImage(url: BotConstants.IMAGE_PROTOCOL + car.ImageURL)
                },
                              cardActions: new List <CardAction> {
                    cardAction,
                    new CardAction(ActionTypes.OpenUrl, BotConstants.BUTTON_VIEW_CAR, value: carDetailsUrl + car.Vehicle.Vin)
                }
                              ));
            }


            return(cards);
        }
Example #2
0
        private static SimpleSearchResponse GetSimpleSearchResult(SimpleSearchFilter filter)
        {
            var serializer       = new JavaScriptSerializer();
            var url              = ConfigurationManager.AppSettings["SearchURL"] + serializer.Serialize(filter);
            var webRequestHelper = new HttpRequestHelper(url);
            var responseponse    = webRequestHelper.GetResponse();

            return(serializer.Deserialize <SimpleSearchResponse>(responseponse));
        }
Example #3
0
 /// <summary>
 /// 搜索热词
 /// </summary>
 public string HotSearchWord(SimpleSearchFilter filter)
 {
     try
     {
         var pindex = VideoNodeKeyArray.Instance.Items[new VideoNodeKey(filter.platform, 0, filter.auth)];
         var words  = LuceneDictionary.Instance.Dictionary[pindex].Items;
         IEnumerable <XElement> page = null;
         if (filter.lang == CustomArray.LanguageArray[1])
         {
             page = words.Skip(filter.c * (filter.s - 1)).Take(filter.c).Select <InstrumentNode, XElement>
                        (v =>
             {
                 return(new XElement("keyword", LanguageUtils.FormatTraditionChinese(v.Key)));
             });
         }
         else
         {
             page = words.Skip(filter.c * (filter.s - 1)).Take(filter.c).Select <InstrumentNode, XElement>
                        (v =>
             {
                 return(new XElement("keyword", v.Key));
             });
         }
         var xml = new XElement("keywords",
                                new XElement("count", words.Count),
                                new XElement("page_count", PageUtils.PageCount(words.Count, filter.c)),
                                page
                                );
         return(xml.ToString(SaveOptions.DisableFormatting));
     }
     catch (KeyNotFoundException)
     {
         return(BoxUtils.FormatErrorMsg("不存在该平台下的热词信息"));
     }
     catch (Exception ex)
     {
         return(BoxUtils.FormatErrorMsg(ex));
     }
 }
Example #4
0
 public static IQueryable <TEntity> ApplySimpleFilter <TEntity>(this IQueryable <TEntity> entities, string searchTerm, string[] propertyNames)
 {
     return(string.IsNullOrEmpty(searchTerm) ? entities : entities.Where(SimpleSearchFilter.GetSimpleSearchExpression <TEntity>(propertyNames, searchTerm)));
 }
Example #5
0
        public static SimpleSearchFilter GetSearchFilter(LuisResult result, string postalCode)
        {
            //Check if value exists
            if (PageSize <= 0)
            {
                PageSize       = AppSettingsUtility.GetInt("RecordsPerPage");
                MaxMileage     = AppSettingsUtility.GetInt("MaxMileage");
                MaxPrice       = AppSettingsUtility.GetInt("MaxPrice");
                SortBy         = AppSettingsUtility.GetString("SortBy");
                DefaultZipCode = AppSettingsUtility.GetString("DefaultZipCode");
            }


            var filter = new SimpleSearchFilter
            {
                MinMileage    = 0,
                MaxMileage    = MaxMileage,
                PageNo        = 1,
                PageSize      = PageSize,
                MinPrice      = 0,
                MaxPrice      = MaxPrice,
                Radius        = -1,
                SortBy        = SortBy,
                SortDirection = 0,
                PostalCode    = DefaultZipCode
            };

            if (!string.IsNullOrEmpty(postalCode))
            {
                filter.PostalCode = postalCode;
            }

            if (result != null && result.Entities != null && result.Entities.Count > 0)
            {
                if (result.Entities.Any(e => e.Type == BotConstants.LUIS_ENTITY_CONDITION))
                {
                    filter.StockType = result.Entities.FirstOrDefault(e => e.Type == BotConstants.LUIS_ENTITY_CONDITION).Entity;
                }

                if (result.Entities.Any(e => e.Type == BotConstants.LUIS_ENTITY_MAKE))
                {
                    filter.Make = result.Entities.FirstOrDefault(e => e.Type == BotConstants.LUIS_ENTITY_MAKE).Entity;
                }

                if (result.Entities.Any(e => e.Type == BotConstants.LUIS_ENTITY_MODEL))
                {
                    filter.Model = result.Entities.FirstOrDefault(e => e.Type == BotConstants.LUIS_ENTITY_MODEL).Entity;
                }

                if (result.Entities.Any(e => e.Type == BotConstants.LUIS_ENTITY_COLOR))
                {
                    filter.ExteriorColor = result.Entities.FirstOrDefault(e => e.Type == BotConstants.LUIS_ENTITY_COLOR).Entity;
                }

                if (result.Entities.Any(e => e.Type == BotConstants.LUIS_ENTITY_YEAR))
                {
                    filter.Year = result.Entities.FirstOrDefault(e => e.Type == BotConstants.LUIS_ENTITY_YEAR).Entity;
                }

                var priceOptions = GetPriceOptions(result);

                if (result.Entities.Any(e => e.Type == BotConstants.LUIS_ENTITY_PRICE_UNDER) && priceOptions.Count > 0)
                {
                    filter.MaxPrice = priceOptions.OrderByDescending(p => p).FirstOrDefault();
                }

                if (result.Entities.Any(e => e.Type == BotConstants.LUIS_ENTITY_PRICE_ABOVE) && priceOptions.Count > 0)
                {
                    filter.MinPrice = priceOptions.OrderBy(p => p).FirstOrDefault();
                }
            }

            return(filter);
        }