Esempio n. 1
0
        public WayModel GetClosestWay(FuzzySearchResult First, List <FuzzySearchResult> Second, CachedDataModel DataOfBot)
        {
            Organization        _First  = DataOfBot.Organizations.FirstOrDefault(x => x.OrganizationID == First.ID);
            List <Organization> _Second = new List <Organization>();

            foreach (var item in Second)
            {
                _Second.Add(DataOfBot.Organizations.FirstOrDefault(x => x.OrganizationID == item.ID));
            }
            return(GetClosestWay(_First, _Second, DataOfBot));
        }
Esempio n. 2
0
        /// <summary>
        /// Добавочный поиск по подстроке + мод. левинштейна
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public List <FuzzySearchResult> BotSecondSearch(string text)
        {
            List <FuzzyStringComparisonOptions> options = new List <FuzzyStringComparisonOptions>();

            options.Add(FuzzyStringComparisonOptions.UseLongestCommonSubstring);

            List <FuzzySearchResult> resluts = new List <FuzzySearchResult>();

            foreach (var item in _collectionOfFuzzySearchResult)
            {
                if (!string.IsNullOrWhiteSpace(item.Name))
                {
                    var distinction = AverageDistinction(text, item.Name.ToLower(), options);
                    if (distinction < _threshold)
                    {
                        item.Distinction = distinction;
                        resluts.Add(item);
                    }
                    // была проблема с тем, что один и тот же объект затирал себя, поэтому терялся Distinction
                    FuzzySearchResult temp;
                    if (item.DataType == FuzzySearchResultDataType.Customer)
                    {
                        temp = new FuzzySearchResult(item.Name, item.ID, item.CustomersKey, item.LocaleCity, item.Distinction, item.Raiting, item.DataType, item.KeyWords);
                    }
                    else
                    {
                        temp = new FuzzySearchResult(item.Name, item.ID, item.Distinction, item.Raiting, item.DataType, item.KeyWords);
                    }

                    distinction = AverageDistinction(text, ToTranslit(item.Name.ToLower()), options);
                    if (distinction < _threshold)
                    {
                        temp.Distinction = distinction;
                        resluts.Add(temp);
                    }
                }
            }
            return(resluts);
        }
Esempio n. 3
0
        /// <summary>
        /// Поиск гудоиск
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public List <FuzzySearchResult> BotMainSearch(string text)
        {
            List <FuzzyStringComparisonOptions> options = new List <FuzzyStringComparisonOptions>();

            options.Add((FuzzyStringComparisonOptions)MyFuzzyStringComparisonOptions.UseDamerauLevenshtein);

            List <FuzzySearchResult> resluts = new List <FuzzySearchResult>();

            foreach (var item in _collectionOfFuzzySearchResult)
            {
                if (!string.IsNullOrWhiteSpace(item.Name))
                {
                    var sourses = item.Name.Split(' ');
                    FuzzySearchResult temp;
                    double            distinction;

                    foreach (var sourse in sourses)
                    {
                        if (item.DataType == FuzzySearchResultDataType.Customer)
                        {
                            temp = new FuzzySearchResult(item.Name, item.ID, item.CustomersKey, item.LocaleCity, item.Distinction, item.Raiting, item.DataType, item.KeyWords);
                        }
                        else
                        {
                            temp = new FuzzySearchResult(item.Name, item.ID, item.Distinction, item.Raiting, item.DataType, item.OtherData, item.KeyWords);
                        }

                        distinction = AverageDistinction(text, sourse, options);
                        if (distinction < _threshold)
                        {
                            temp.Distinction = distinction;
                            resluts.Add(temp);
                        }

                        if (item.DataType == FuzzySearchResultDataType.Customer)
                        {
                            temp = new FuzzySearchResult(item.Name, item.ID, item.CustomersKey, item.LocaleCity, item.Distinction, item.Raiting, item.DataType, item.KeyWords);
                        }
                        else
                        {
                            temp = new FuzzySearchResult(item.Name, item.ID, item.Distinction, item.Raiting, item.DataType, item.OtherData, item.KeyWords);
                        }

                        distinction = AverageDistinction(text, ToTranslit(sourse), options);
                        if (distinction < _threshold)
                        {
                            temp.Distinction = distinction;
                            resluts.Add(temp);
                        }
                    }
                    #region KeyWordsSearch
                    if (item.KeyWords != null)
                    {
                        char[]        splitters = { '~', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '+', '=', '!', '"', '№', ';', '%', ':', '?', '.', ',', '/', '<', '|', '>', '`', '\\', '\'', ' ' };
                        List <string> KeyWords  = item.KeyWords.Split(',').Select(e => e.Trim(splitters)).Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                        foreach (string keyWord in KeyWords)
                        {
                            if (!string.IsNullOrWhiteSpace(keyWord))
                            {
                                if (item.DataType == FuzzySearchResultDataType.Customer)
                                {
                                    temp = new FuzzySearchResult(item.Name, item.ID, item.CustomersKey, item.LocaleCity, item.Distinction, item.Raiting, item.DataType, item.KeyWords);
                                }
                                else
                                {
                                    temp = new FuzzySearchResult(item.Name, item.ID, item.Distinction, item.Raiting, item.DataType, item.OtherData, item.KeyWords);
                                }

                                distinction = AverageDistinction(text, keyWord, options) * 1.5;
                                if (distinction < _threshold)
                                {
                                    if (distinction == 0)
                                    {
                                        distinction = 0.00001;
                                    }
                                    temp.Distinction = distinction;
                                    resluts.Add(temp);
                                }
                                if (distinction == 0)
                                {
                                    break;
                                }

                                if (item.DataType == FuzzySearchResultDataType.Customer)
                                {
                                    temp = new FuzzySearchResult(item.Name, item.ID, item.CustomersKey, item.LocaleCity, item.Distinction, item.Raiting, item.DataType, item.KeyWords);
                                }
                                else
                                {
                                    temp = new FuzzySearchResult(item.Name, item.ID, item.Distinction, item.Raiting, item.DataType, item.OtherData, item.KeyWords);
                                }

                                distinction = AverageDistinction(text, ToTranslit(keyWord), options) * 1.5;
                                if (distinction < _threshold)
                                {
                                    if (distinction == 0)
                                    {
                                        distinction = 0.00001;
                                    }
                                    temp.Distinction = distinction;
                                    resluts.Add(temp);
                                }

                                if (distinction == 0.00001)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            return(resluts);
        }