Beispiel #1
0
        public static SearchKeyword AddSearchKeyword(SearchKeyword searchKeyword)
        {
            string sql =
                "INSERT SearchKeywords (Keyword, SearchCount)" +
                "VALUES (@Keyword, @SearchCount)";

            sql += " ; SELECT @@IDENTITY";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@Keyword", searchKeyword.Keyword),
                    new SqlParameter("@SearchCount", searchKeyword.SearchCount)
                };

                int newId = DBHelper.GetScalar(sql, para);
                return(GetSearchKeywordById(newId));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Beispiel #2
0
        private static IList <SearchKeyword> GetSearchKeywordsBySql(string sql, params SqlParameter[] values)
        {
            List <SearchKeyword> list = new List <SearchKeyword>();

            try
            {
                DataTable table = DBHelper.GetDataSet(sql, values);

                foreach (DataRow row in table.Rows)
                {
                    SearchKeyword searchKeyword = new SearchKeyword();

                    searchKeyword.Id          = (int)row["Id"];
                    searchKeyword.Keyword     = (string)row["Keyword"];
                    searchKeyword.SearchCount = (int)row["SearchCount"];

                    list.Add(searchKeyword);
                }

                return(list);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Beispiel #3
0
        public static SearchKeyword GetSearchKeywordById(int id)
        {
            string sql = "SELECT * FROM SearchKeywords WHERE Id = @Id";

            try
            {
                SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@Id", id));
                if (reader.Read())
                {
                    SearchKeyword searchKeyword = new SearchKeyword();

                    searchKeyword.Id          = (int)reader["Id"];
                    searchKeyword.Keyword     = (string)reader["Keyword"];
                    searchKeyword.SearchCount = (int)reader["SearchCount"];

                    reader.Close();

                    return(searchKeyword);
                }
                else
                {
                    reader.Close();
                    return(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Beispiel #4
0
        public static void ModifySearchKeyword(SearchKeyword searchKeyword)
        {
            string sql =
                "UPDATE SearchKeywords " +
                "SET " +
                "Keyword = @Keyword, " +
                "SearchCount = @SearchCount " +
                "WHERE Id = @Id";


            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@Id", searchKeyword.Id),
                    new SqlParameter("@Keyword", searchKeyword.Keyword),
                    new SqlParameter("@SearchCount", searchKeyword.SearchCount)
                };

                DBHelper.ExecuteCommand(sql, para);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
        public void GetSearchKeywordsByCategoryTestMethod()
        {
            using (ShimsContext.Create())
            {
                ShimSearchKeywordService.ConstructorIUnitOfWork = (d1, d2) =>
                {
                    d1.Repository = new Repository <SearchKeyword, int>(new MockContent());
                };
                var searchKeywordService = new ShimSearchKeywordService(new SearchKeywordService(new MockContent()));

                SearchKeyword searchKeyword1 = new SearchKeyword();
                searchKeyword1.AppId       = 16;
                searchKeyword1.Category    = 35;
                searchKeyword1.Keyword     = "来一发";
                searchKeyword1.SearchCount = 100;

                searchKeywordService.Instance.Repository.Insert(searchKeyword1);

                SearchKeyword searchKeyword2 = new SearchKeyword();
                searchKeyword2.AppId       = 16;
                searchKeyword2.Category    = 36;
                searchKeyword2.Keyword     = "昆特牌";
                searchKeyword2.SearchCount = 32;

                searchKeywordService.Instance.Repository.Insert(searchKeyword2);

                List <SearchKeywordView> testDataList =
                    searchKeywordService.Instance.GetSearchKeywordsByCategory(16, 2);

                Assert.IsTrue(testDataList.Count == 2);
            }
        }
Beispiel #6
0
        protected async override void FilterData()
        {
            SearchKeyword.Trim();
            DataGridSpinnerState = SpinnerState.Searching;
            DataGridState        = ViewModeType.Busy;
            await Task.Delay(500);

            switch (SearchProperty.HeaderName)
            {
            case "Id":
                ViewItems.Filter = StoreIdFilter;
                break;

            case "Name":
                ViewItems.Filter = StoreNameFilter;
                break;

            case "Address":
                ViewItems.Filter = StoreAddressFilter;
                break;

            default:
                break;
            }
            IsFiltered    = true;
            DataGridState = ViewModeType.Default;
        }
        private List <FaqInfoView> SearchPrivate(int appId, string keyword)
        {
            // 将搜索条件保存起来,并将搜索次数累加
            // 将字符串截断保存
            foreach (var key_word in keyword.Split(' '))
            {
                //避免截断串后有空字符
                if (!string.IsNullOrEmpty(key_word.Trim()))
                {
                    var searchKeyword = _searchKeywordService.Repository.Entities.Where(a => a.AppId == appId && a.Keyword == key_word).FirstOrDefault();
                    if (searchKeyword == null)
                    {
                        searchKeyword = new SearchKeyword()
                        {
                            AppId       = appId,
                            SearchCount = 1,
                            Keyword     = key_word
                        };
                        _searchKeywordService.Repository.Insert(searchKeyword);
                    }
                    else
                    {
                        searchKeyword.SearchCount++;
                        _searchKeywordService.Repository.Update(searchKeyword);
                    }
                }
            }
            var article = _objService.GetListBySearchKey(appId, keyword);

            return(article);
        }
Beispiel #8
0
        private void SearchClearCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            SearchController.Clear();

            SearchKeyword.Text = "";
            SearchKeyword.Focus();
        }
Beispiel #9
0
        private bool FilterStudent(object o)
        {
            if (!(o is Models.Student s))
            {
                return(false);
            }

            if (EnableAdvanceFilter)
            {
                if (FilterByCourse && CourseFilter != null && s.CourseId != CourseFilter.Id)
                {
                    s.IsSelected = false;
                    return(false);
                }
            }

            if (string.IsNullOrEmpty(SearchKeyword))
            {
                return(true);
            }
            if (s.Fullname.ToLower().Contains(SearchKeyword.ToLower()))
            {
                return(true);
            }

            s.IsSelected = false;
            return(false);
        }
        private bool CustomerIDCardNumberFilter(object item)
        {
            Customer customer = item as Customer;

            if (customer.Tel == null)
            {
                return(false);
            }
            return(customer.IdCardNumber.ToLower().Contains(SearchKeyword.ToLower()));
        }
Beispiel #11
0
        private bool AssetCategoryFilter(object item)
        {
            Asset Asset = item as Asset;

            if (Asset.AssetCategory.Name == null)
            {
                return(false);
            }
            return(Asset.AssetCategory.Name.ToLower().Contains(SearchKeyword.ToLower()));
        }
Beispiel #12
0
        private bool StoreAddressFilter(object item)
        {
            Store Store = item as Store;

            if (Store.Address == null)
            {
                return(false);
            }
            return(Store.Address.ToLower().Contains(SearchKeyword.ToLower()));
        }
Beispiel #13
0
        private bool ProductOriginalNameFilter(object item)
        {
            Product Product = item as Product;

            if (Product.OriginalName == null)
            {
                return(false);
            }
            return(Product.OriginalName.ToLower().Contains(SearchKeyword.ToLower()));
        }
        private bool CustomerRelationshipFilter(object item)
        {
            Customer customer = item as Customer;

            if (customer.Relationship == null)
            {
                return(false);
            }
            return(customer.Relationship.ToLower().Contains(SearchKeyword.ToLower()));
        }
        private bool CustomerRankFilter(object item)
        {
            Customer customer = item as Customer;

            if (customer.CustomerRank.Name == null)
            {
                return(false);
            }
            return(customer.CustomerRank.Name.ToLower().Contains(SearchKeyword.ToLower()));
        }
        public async Task TestSearchKeywordAsync()
        {
            await TestHelpers.SearchPagesAsync(i => TMDbClient.SearchKeywordAsync("plot", i));

            SearchContainer <SearchKeyword> result = await TMDbClient.SearchKeywordAsync("plot");

            SearchKeyword item = result.Results.Single(s => s.Id == 11121);

            await Verify(item);
        }
        private bool CategoryNameFilter(object item)
        {
            Category Category = item as Category;

            if (Category.Name == null)
            {
                return(false);
            }
            return(Category.Name.ToLower().Contains(SearchKeyword.ToLower()));
        }
Beispiel #18
0
        private static SearchKeyword AddKeyword(SearchKeyword keyword)
        {
            SearchKeyword existingItem = Keywords.FirstOrDefault(x => x.Id == keyword.Id);

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

            Keywords.Add(keyword);
            return(keyword);
        }
Beispiel #19
0
        private readonly SortSlideList sortSlideList;       //変更済み

        public PhotoFrameApplication(KeywordRepository keywordRepository, PhotoRepository photoRepository, PhotoFileService photoFileService)
        {
            this.createPhotoList = new CreatePhotoList(photoRepository, photoFileService); //済み
            this.addKeyword      = new AddKeyword(keywordRepository);                      //済み
            this.changeKeyword   = new ChangeKeyword(keywordRepository, photoRepository);  //済み
            this.changeFavorite  = new ChangeFavorite(photoRepository);                    //済み
            this.searchKeyword   = new SearchKeyword();                                    //済み
            this.searchFavorite  = new SearchFavorite();                                   //済み
            this.searchDate      = new SearchDate();                                       //済み
            this.sortDate        = new SortDate();                                         //済み
            this.sortSlideList   = new SortSlideList();                                    //済み
        }
Beispiel #20
0
        /// <summary>
        /// Search rules including rule points and named rules, and add searching
        /// result to SearchResult property.
        /// </summary>
        private void SearchRules(Stack <RuleBaseContext> workingBuffer)
        {
            const int MaxWorkload           = 10;
            const int MaxSearchResultNumber = 1000;

            if (workingBuffer != _workingBuffer)
            {
                // System has started an another searching work by a new keyword.
                return;
            }

            int count = 0;

            while (workingBuffer.Count > 0 && count < MaxWorkload)
            {
                RuleBaseContext theContext = workingBuffer.Pop();
                if (String.IsNullOrEmpty(SearchKeyword))
                {
                    _searchResult.Add(theContext);
                }
                else
                {
                    // Call ToUpper() for search in case-insensitive way.
                    if (theContext.DisplayName.ToUpper().Contains(SearchKeyword.ToUpper()))
                    {
                        _searchResult.Add(theContext);
                    }
                }

                theContext.UpdateDisplayTexts();

                // Add children into working queue if it has.
                RulePointContext rulePoint = theContext as RulePointContext;
                if (rulePoint != null)
                {
                    foreach (var child in rulePoint.Children.Reverse()) // first child, first serve
                    {
                        workingBuffer.Push(child);
                    }
                }

                ++count;
            }

            if (_workingBuffer.Count > 0 && _searchResult.Count < MaxSearchResultNumber)
            {
                Dispatcher.CurrentDispatcher.BeginInvoke(
                    new Action <Stack <RuleBaseContext> >(SearchRules),
                    DispatcherPriority.Background,
                    workingBuffer);
            }
        }
Beispiel #21
0
        public void TestSearchKeyword()
        {
            TestHelpers.SearchPages(i => _config.Client.SearchKeyword("plot", i).Result);

            SearchContainer <SearchKeyword> result = _config.Client.SearchKeyword("plot").Result;

            Assert.IsTrue(result.Results.Any());
            SearchKeyword item = result.Results.SingleOrDefault(s => s.Id == 11121);

            Assert.IsNotNull(item);
            Assert.AreEqual(11121, item.Id);
            Assert.AreEqual("plot", item.Name);
        }
Beispiel #22
0
        private void Search()
        {
            string keyword = SearchKeyword.Text.Trim().ToLower();

            if (keyword.Length >= Constant.MinKeywordLength)
            {
                FileFilter filter = (FileFilter)SearchFilter.SelectedIndex;
                SearchController.Search(keyword, filter);

                SearchButton.IsEnabled = false;
                SearchKeyword.SelectAll();
                SearchKeyword.Focus();
            }
        }
        private bool CustomerAddressFilter(object item)
        {
            bool     x = false, y = false;
            Customer customer = item as Customer;

            if (customer.Address1 != null)
            {
                x = customer.Address1.ToLower().Contains(SearchKeyword.ToLower());
            }
            if (customer.Address2 != null)
            {
                y = customer.Address2.ToLower().Contains(SearchKeyword.ToLower());
            }
            return(x || y);
        }
        /// <summary>
        /// 根据Keyword获得SearchKeyword对象
        /// </summary>
        /// <param name="Keyword"></param>
        /// <returns></returns>
        public SearchKeyword GetSearchKeywordByKeyword(string keyword)
        {
            SearchKeyword searchKeyword = null;
            string        sql           = "select Id,Keyword,SearchCount from SearchKeywords where Keyword=@keyword";
            SqlDataReader reader        = DBHelper.ExecuteReader(sql, CommandType.Text, new SqlParameter("@Keyword", keyword));

            if (reader.HasRows)
            {
                if (reader.Read())
                {
                    searchKeyword = LoadSearchKeyword(reader);
                }
            }
            reader.Close();
            return(searchKeyword);
        }
 private bool Filter(object obj)
 {
     if (!(obj is Household h))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(SearchKeyword))
     {
         return(true);
     }
     if (h.Incharge?.Fullname?.ToLower()?.Contains(SearchKeyword.ToLower()) ?? false)
     {
         return(true);
     }
     return(false);
 }
 private bool Filter(object obj)
 {
     if (!(obj is Certificate h))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(SearchKeyword))
     {
         return(true);
     }
     if (h.Tawo?.Fullname?.ToLower()?.Contains(SearchKeyword.ToLower()) ?? false)
     {
         return(true);
     }
     return(false);
 }
Beispiel #27
0
 public Form1(KeywordRepository in_keywordRepository, PhotoRepository in_photoRepository, PhotoFileService in_photoFileService)
 {
     InitializeComponent();
     this.keywordRepository = in_keywordRepository;
     this.photoRepository   = in_photoRepository;
     this.photoFileService  = in_photoFileService;
     addKeyword             = new AddKeyword(keywordRepository);
     changeFavorite         = new ChangeFavorite(photoRepository);
     changeKeyword          = new ChangeKeyword(keywordRepository, photoRepository);
     createPhotoList        = new CreatePhotoList(photoRepository, photoFileService);
     searchDate             = new SearchDate();
     searchFavorite         = new SearchFavorite();
     searchKeyword          = new SearchKeyword();
     sortDate = new SortDate();
     End_DateTimePicker.MaxDate = DateTime.Today;
 }
Beispiel #28
0
        public IActionResult Index(SearchKeyword keywordsInput)
        {
            SearchKeywordViewModel model = new SearchKeywordViewModel();

            if (keywordsInput == null || string.IsNullOrEmpty(keywordsInput.Body))
            {
                return(RedirectToAction("Index"));
            }
            stopWatch.Start();
            List <string> outputResult = this._microminer.FindUrl(keywordsInput.Body);

            stopWatch.Stop();
            model.Time       = stopWatch.Elapsed.TotalMilliseconds;
            model.ResultBody = string.Join("\n", outputResult.ToArray());
            return(View("Index", model));
        }
Beispiel #29
0
        public bool ModifySearchKeyword(SearchKeyword searchKeyword)
        {
            string sql =
                "UPDATE SearchKeywords " +
                "SET " +
                "Keyword = @Keyword, " +
                "SearchCount = @SearchCount " +
                "WHERE Id = @Id";

            SqlParameter[] para = new SqlParameter[]
            {
                new SqlParameter("@Id", searchKeyword.Id),
                new SqlParameter("@Keyword", searchKeyword.Keyword),
                new SqlParameter("@SearchCount", searchKeyword.SearchCount)
            };
            return(SqlHelper.ExecuteNonQuery(this.connection, CommandType.Text, sql, para) > 0);
        }
Beispiel #30
0
        /// <summary>
        /// 根据关键字搜索时,进行搜索计数
        /// </summary>
        /// <param name="keyword"></param>
        public static void Search(string keyword)
        {
            SearchKeyword skw = SearchKeywordService.GetKeyword(keyword);

            if (skw == null)
            {
                skw             = new SearchKeyword();
                skw.Keyword     = keyword;
                skw.SearchCount = 1;
                SearchKeywordService.AddSearchKeyword(skw);
            }
            else
            {
                skw.SearchCount++;
                SearchKeywordService.ModifySearchKeyword(skw);
            }
        }