public void Initialize()
        {
            log4net.Config.XmlConfigurator.Configure();

            _logger = LogManager.GetLogger(GetType());
            _logger.Info("====== Initializing Service ======\n\n");
            _serviceManager      = new ServicesManager();
            _searchEngineManager = new SearchEngineManager();

            _logger.Info("\n\n====== SETTING UP SENTIMENT EVALUATOR ======\n\n");
            var negativeWords = _serviceManager.GetAllWords().Where(x => x.Sentiment == "Negativo").Select(x => x.Name).ToList();
            var positiveWords = _serviceManager.GetAllWords().Where(x => x.Sentiment == "Positivo").Select(x => x.Name).ToList();
            var ignoreList    = new List <string>()
            {
                ".", ","
            };

            _sentimentValuator = new SentimentValuator
            {
                NegativeWords = negativeWords,
                PositiveWords = positiveWords,
                IgnoreChars   = ignoreList
            };
            _logger.Info("\n\n====== SENTIMENT EVALUATOR SET UP SUCCESSFULLY ======\n\n");

            SearchEngineManager.ConfigureAddins();
            _logger.Info("\n\n====== Service Initialized ======\n\n");
        }
Пример #2
0
 public void Initialize(SearchEngineManager engineManager)
 {
     this.engineManager           = engineManager;
     SearchEngineCB.DisplayMember = "Key";
     SearchEngineCB.ValueMember   = "Value";
     SearchEngineCB.DataSource    = new BindingSource(engineManager.Engines, null);
 }
Пример #3
0
        static void Main(string[] searchArguments)
        {
            SearchEngineManager engines = new SearchEngineManager();
            ResultsCalculator   results = new ResultsCalculator(engines, searchArguments);
            ResultsOutputter    output  = new ResultsOutputter(results);

            output.PrintWinnersToConsole();
        }
Пример #4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            XmlConfigurator.Configure();
            SearchEngineManager.ConfigureAddins();
        }
Пример #5
0
        // POST api/values
        public Result [] Post([FromBody] string [] searchArguments)
        {
            SearchEngineManager engines = new SearchEngineManager();
            ResultsCalculator   results = new ResultsCalculator(engines, searchArguments);
            ResultsOutputter    output  = new ResultsOutputter(results);

            return(output.GetResults());
        }
Пример #6
0
        /// <summary>
        /// 商品关键字搜索自动完成功能
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static ProductACSearchResult GetProductACSearchResultBySolr(string keywordPrefix)
        {
            SearchCondition condition = new SearchCondition()
            {
                KeyWord = keywordPrefix
            };
            ProductACSearchResult result = SearchEngineManager.Query <ProductACSearchResult>(condition);

            return(result);
        }
Пример #7
0
        public void ConfigureAddinsTest()
        {
            SearchEngineManager.ConfigureAddins();
            var searchEngineManager = new SearchEngineManager();
            var result = searchEngineManager.Search(string.Empty, new List <string>()
            {
                "SearchEngineMock"
            });

            Assert.AreEqual(result.Count, 2);
        }
Пример #8
0
        /// <summary>
        /// Delete all ad/lucene images and remove from lucene
        /// </summary>
        /// <param name="ad"></param>
        public static void DeletePhotosFromLuceneIndex(int adId, string stringId, IEnumerable <ClassifiedAdPhoto> photos)
        {
            var lucenerecord = SearchEngineManager.GetClassifiedAdWithDetails(adId);
            // delete photos
            var dir        = HostingEnvironment.MapPath("~/Photos/" + stringId.Substring(2, 4) + "/" + stringId.Substring(0, 4));
            var lucenepath = Path.Combine(dir, "lucene");

            if (photos != null)
            {
                foreach (var pho in photos)
                {
                    try
                    {
                        // Delete Regular
                        if (File.Exists(Path.Combine(dir, pho.AdDetails_FileName)))
                        {
                            File.Delete(Path.Combine(dir, pho.AdDetails_FileName));
                        }
                        if (File.Exists(Path.Combine(dir, pho.AdList_FileName)))
                        {
                            File.Delete(Path.Combine(dir, pho.AdList_FileName));
                        }
                        if (File.Exists(Path.Combine(dir, pho.Raw_FileName)))
                        {
                            File.Delete(Path.Combine(dir, pho.Raw_FileName));
                        }
                    }
                    catch (Exception) { }
                }
            }
            if (lucenerecord != null && lucenerecord.Photos != null)
            {
                foreach (var pho in lucenerecord.Photos)
                {
                    // Delete Lucene
                    if (File.Exists(Path.Combine(lucenepath, pho.AdDetails_FileName)))
                    {
                        File.Delete(Path.Combine(lucenepath, pho.AdDetails_FileName));
                    }
                    if (File.Exists(Path.Combine(lucenepath, pho.AdList_FileName)))
                    {
                        File.Delete(Path.Combine(lucenepath, pho.AdList_FileName));
                    }
                    if (File.Exists(Path.Combine(lucenepath, pho.Raw_FileName)))
                    {
                        File.Delete(Path.Combine(lucenepath, pho.Raw_FileName));
                    }
                }
            }

            // Delete temp folder
            PhotoFileManager.DeleteTempPhotos(adId, stringId);
        }
        public JsonResult SearchResults(string parameters, string searchEngines, string sentiment, string socialNetworking, string userName)
        {
            var result = new List <Post>();
            var model  = new SearchResultModel();

            if (ModelState.IsValid)
            {
                var searchEngineManager = new SearchEngineManager();
                result = searchEngineManager.Search(parameters, searchEngines.Split(',').ToList());
                result = result.OrderByDescending(o => o.CreatedAt).ToList();
                if (result.Count > 0)
                {
                    GetAllWords();

                    var sentimentValuator = new SentimentValuator
                    {
                        NegativeWords = negativeWords,
                        PositiveWords = positiveWords,
                        IgnoreChars   = ignoreList
                    };

                    foreach (var item in result)
                    {
                        sentimentValuator.ProcessItem(item);

                        if (string.IsNullOrEmpty(sentiment) && string.IsNullOrEmpty(socialNetworking) && string.IsNullOrEmpty(userName))
                        {
                            model.Items.Add(item);
                        }

                        else if (ValidateFilters(sentiment, socialNetworking, userName, item))
                        {
                            model.Items.Add(item);
                        }
                    }

                    sentimentValuator.ResetCounters();

                    foreach (var item in model.Items)
                    {
                        sentimentValuator.ProcessItem(item);
                    }

                    BuildSentimentBox(model, sentimentValuator);
                    BuildEnginesBox(model);
                    BuildTopUsersBox(model);
                }
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Пример #10
0
        public IPagedList <ClassifiedAdFavouriteList> GetMyFavouritedAds(int pageNumber = 1)
        {
            IEnumerable <int> cuf = new List <int>();

            if (CurrentUser != null)
            {
                cuf = CacheHelper.GetFromCache <IEnumerable <int> >(string.Format("{0}-Favourites", CurrentUser.Id));
                if (cuf == null)
                {
                    using (var newthreadcontext = new ApplicationDbContext())
                    {
                        cuf = newthreadcontext.Users.SingleOrDefault(x => x.Id == CurrentUser.Id).Favourites.Select(s => s.ClassifiedAdId);
                        CacheHelper.SaveTocache(string.Format("{0}-Favourites", CurrentUser.Id), cuf, DateTime.Now.AddMinutes(5));
                    }
                }
                return(SearchEngineManager.GetUserFavouritedAds(cuf, pageNumber));
            }
            else
            {
                var anonymousUserId = HttpContext.Current.Request.Cookies["MyFavourites"]?.Value?.ToString();
                if (anonymousUserId != null)
                {
                    cuf = CacheHelper.GetFromCache <IEnumerable <int> >(string.Format("{0}-Favourites", anonymousUserId));
                    if (cuf == null)
                    {
                        using (var newthreadcontext = new ApplicationDbContext())
                        {
                            cuf = newthreadcontext.AnonymousUserDB.SingleOrDefault(x => x.Id.ToString() == anonymousUserId)?.Favourites.Select(s => s.ClassifiedAdId);
                            // cleanup cookie if user does not exist in db
                            if (cuf == null)
                            {
                                var deletecookie = new HttpCookie("MyFavourites", anonymousUserId)
                                {
                                    Secure = true, HttpOnly = true, Expires = DateTime.Now.AddDays(-1)
                                };
                                HttpContext.Current.Response.Cookies.Add(deletecookie);
                                HttpContext.Current.Response.Cookies.Set(deletecookie);
                                HttpContext.Current.Request.Cookies.Remove("MyFavourites");
                                return(null);
                            }
                            CacheHelper.SaveTocache(string.Format("{0}-Favourites", anonymousUserId), cuf, DateTime.Now.AddMinutes(5));
                        }
                    }
                    return(SearchEngineManager.GetUserFavouritedAds(cuf, pageNumber));
                }
            }

            return(new List <ClassifiedAdFavouriteList>().ToPagedList(1, 1));
        }
Пример #11
0
 public OptionPage()
 {
     settingStoreProvider = new SettingStoreProvider("ErrorSearchOn");
     if (settingStoreProvider.Exist("SearchEngine"))
     {
         searchEngineManager =
             new SearchEngineManager(
                 (SearchEngineTypes)
                 Enum.Parse(typeof(SearchEngineTypes), settingStoreProvider.Get("SearchEngine")));
     }
     else
     {
         searchEngineManager = new SearchEngineManager();
     }
 }
Пример #12
0
 public Client(OperaLink.Configs conf)
 {
     conf_ = conf;
       typeds_ = new TypedHistoryManager();
       ses_ = new SearchEngineManager();
       sds_ = new SpeedDialManager();
       notes_ = new NoteManager();
       bms_ = new BookmarkManager();
       xml_settings_ = new XmlWriterSettings
       {
     Encoding = System.Text.Encoding.UTF8,
     NewLineOnAttributes = false,
       };
       sync_state_ = 0;
       short_interval_ = 60;
       long_interval_ = 120;
       token_ = "";
       LastStatus = "";
       enc_ = Encoding.GetEncoding("utf-8");
 }
Пример #13
0
        public static void AddUpdateLuceneIndex(ClassifiedAdLucene sampleData)
        {
            var oldlucenerecord = SearchEngineManager.GetClassifiedAdWithDetails(sampleData.Id);
            var dir             = HostingEnvironment.MapPath("~/Photos/" + sampleData.StringId.Substring(2, 4) + "/" + sampleData.StringId.Substring(0, 4));
            var lucenepath      = Path.Combine(dir, "lucene");

            // init lucene
            using (var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
                using (var writer = new IndexWriter(_write, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    var searchQuery = new TermQuery(new Term("Id", sampleData.Id.ToString()));
                    writer.DeleteDocuments(searchQuery);
                    // Add
                    Document doc        = null;
                    var      ManagerSeo = new SeoManager();
                    _createLuceneIndex(sampleData, writer, ManagerSeo, doc);
                }
            var newlucenerecord = SearchEngineManager.GetClassifiedAdWithDetails(sampleData.Id);

            // Compare photos for changes and remove unused
            if (oldlucenerecord != null && newlucenerecord != null)
            {
                var photostodelete = oldlucenerecord.Photos.Except(newlucenerecord.Photos, new PhotoComparer());
                foreach (var pho in photostodelete)
                {
                    // Delete Lucene
                    if (File.Exists(Path.Combine(lucenepath, pho.AdDetails_FileName)))
                    {
                        File.Delete(Path.Combine(lucenepath, pho.AdDetails_FileName));
                    }
                    if (File.Exists(Path.Combine(lucenepath, pho.AdList_FileName)))
                    {
                        File.Delete(Path.Combine(lucenepath, pho.AdList_FileName));
                    }
                    if (File.Exists(Path.Combine(lucenepath, pho.Raw_FileName)))
                    {
                        File.Delete(Path.Combine(lucenepath, pho.Raw_FileName));
                    }
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Generate from DB
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public string GenerateListDetailsUrl(int Id)
        {
            var key = string.Format("ld-{0}", Id);

            var urlCache = CacheHelper.GetFromCache <string>(key);

            if (urlCache != null)
            {
                return(urlCache);
            }

            var    format = "/cld-{0}/{1}/{2}/{3}";
            string returnUrl;
            var    ad = SearchEngineManager.GetClassifiedAdWithDetailsFromDb(Id);

            if (ad == null)
            {
                return(null);
            }
            returnUrl = string.Format(format, CategorySlug(ad.Category.Id, ad.SubCategory.Id, ad.Category.Name, ad.SubCategory.Name), LocationSlug(ad.Country.Id, ad.Region.Id), ad.Id, TitleSlug(ad.Title));
            CacheHelper.SaveTocache(key, returnUrl, DateTime.Now.AddHours(1));
            return(returnUrl);
        }
Пример #15
0
        public IndexPage(int countryId, int regionId, int catId, int subCatId) : base(countryId, regionId, catId, subCatId)
        {
            using (ClassifiedAdManager Manager = new ClassifiedAdManager())
            {
                CategoryTiles = Manager.GetCategoryTiles();

                foreach (var c in CategoryTiles)
                {
                    c.FeaturedAds    = SearchEngineManager.GetCategoryTileFeaturedAds(c.Id);
                    c.RecentlyPosted = SearchEngineManager.GetRecentClassifiedAdIndex(c.Id);
                }

                // Ad Count
                AdCount = Manager.GetAdCount();

                // Recent Ad setup
                ClassifiedAdListRecent = SearchEngineManager.GetRecentClassifiedAdIndex();

                // Random Ad setup
                ClassifiedAdRandomPicks = SearchEngineManager.GetRandomPickedClassifiedAds();

                // Sponsored Ad setup
            }
        }
Пример #16
0
 public bool IsAdSuspended(int Id)
 {
     return(SearchEngineManager.IsAdSuspended(Id));
 }
Пример #17
0
        public static ProductSearchResult GetProductSearchResultBySolr(ProductSearchCondition condition)
        {
            ProductSearchResult result = new ProductSearchResult();

            //商品聚合显示
            //condition.IsGroupQuery = true;

            #region  第一次搜索(初始化左导航,需要排除条件endecaId)
            //第一次搜索(初始化左导航,需要排除条件endecaId)
            ProductSearchCondition initialCondition = new ProductSearchCondition()
            {
                PagingInfo    = condition.PagingInfo,
                KeyWord       = condition.KeyWord,
                WithInKeyWord = condition.WithInKeyWord,
                Filters       = condition.Filters,
                IsGroupQuery  = condition.IsGroupQuery
            };
            if (condition.NValueList != null && condition.NValueList.Count > 0)
            {
                initialCondition.Filters = initialCondition.Filters == null ? new List <FilterBase>(0) : initialCondition.Filters;
                foreach (string item in condition.NValueList)
                {
                    if (!condition.Filters.Exists(x =>
                    {
                        if (x is FieldFilter)
                        {
                            return(((FieldFilter)x).Value.Equals(item, StringComparison.CurrentCultureIgnoreCase));
                        }
                        return(false);
                    }) && !string.Equals(item, condition.EndecaId))
                    {
                        initialCondition.Filters.Add(new FieldFilter("Nvalue", item));
                    }
                }
            }

            ProductSearchResult initialResult = SearchEngineManager.Query <ProductSearchResult>(initialCondition);
            result.Navigation = initialResult.Navigation;
            #endregion

            #region  第二次搜索(初始化过滤条件,需要排除N值)
            //第二次搜索(初始化过滤条件,需要排除N值)
            ProductSearchCondition filterCondition = new ProductSearchCondition()
            {
                PagingInfo    = condition.PagingInfo,
                KeyWord       = condition.KeyWord,
                WithInKeyWord = condition.WithInKeyWord,
                Filters       = condition.Filters == null ? new List <FilterBase>(0) : /*是否有折扣不影响条件选择区*/
                                condition.Filters.Where(x => x.Field != "Nvalue" && x.Field != "p_cashrebate").ToList(),
                IsGroupQuery = condition.IsGroupQuery
            };
            if (condition.NValueList != null && condition.NValueList.Count > 0)
            {
                filterCondition.Filters = filterCondition.Filters == null ? new List <FilterBase>(0) : filterCondition.Filters;
                foreach (string item in condition.NValueList)
                {
                    List <string> NValue = GetNValueList(condition.NFilter);
                    if (NValue != null && NValue.Count > 0)
                    {
                        if (!NValue.Contains(item))
                        {
                            filterCondition.Filters.Add(new FieldFilter("Nvalue", item));
                        }
                    }
                    else
                    {
                        filterCondition.Filters.Add(new FieldFilter("Nvalue", item));
                    }
                }
            }
            ProductSearchResult filterResult = SearchEngineManager.Query <ProductSearchResult>(filterCondition);
            result.FilterNavigation = filterResult.Navigation;
            #endregion

            #region 第三次搜索(搜商品,加上所有搜索条件)

            //第三次搜索(搜商品,加上所有搜索条件)
            if (condition.NValueList != null && condition.NValueList.Count > 0)
            {
                condition.Filters = condition.Filters == null ? new List <FilterBase>(0) : condition.Filters;
                foreach (string item in condition.NValueList)
                {
                    if (!condition.Filters.Exists(x =>
                    {
                        if (x is FieldFilter)
                        {
                            return(((FieldFilter)x).Value.Equals(item, StringComparison.CurrentCultureIgnoreCase));
                        }
                        return(false);
                    }))
                    {
                        condition.Filters.Add(new FieldFilter("Nvalue", item));
                    }
                }
            }
            //商品二维码搜索条件
            if (!string.IsNullOrWhiteSpace(condition.Barcode))
            {
                if (!condition.Filters.Exists(x => x.Field.Equals("p_barcode", StringComparison.CurrentCultureIgnoreCase)))
                {
                    condition.Filters.Add(new FieldFilter("p_barcode", condition.Barcode));
                }
            }
            ProductSearchResult productResult = SearchEngineManager.Query <ProductSearchResult>(condition);
            result.ProductDataList = productResult.ProductDataList;
            #endregion

            return(result);
        }