Beispiel #1
0
        /// <summary>
        /// 区域码
        /// </summary>
        public static void GenerateAreaCodes()
        {
            try
            {
#if DEBUG
                string fileOfKeywords = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\..\\tool\\ProjectHelper\\ProjectHelper\\Areas.txt");
                string fileOfErlang   = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\..\\server-new\\src\\gen\\lib_area.erl");
#else
                string fileOfKeywords = Path.Combine(Environment.CurrentDirectory, "tool\\ProjectHelper\\ProjectHelper\\Areas.txt");
                string fileOfErlang   = Path.Combine(Environment.CurrentDirectory, "server-new\\src\\gen\\lib_area.erl");
#endif
                string erlangCodes = KeywordGenerator.BuildErlangCodes("lib_area", fileOfKeywords, false, true);

                using (StreamWriter sw = new StreamWriter(fileOfErlang, false))
                {
                    sw.Write(erlangCodes);
                }

                MessageBox.Show("区域检测代码生成完毕");
            }
            catch (Exception ex)
            {
                MessageBox.Show("区域检测代码生成失败:" + ex.Message);
            }
        }
        private List <DictionaryEntry> SearchByTranslation(string searchQuery, bool exactMatch)
        {
            var keygen            = new KeywordGenerator();
            var sanitizedKeywords = keygen.SanitizeSearchInput(searchQuery, null);
            int numKeywords       = sanitizedKeywords.Length;
            var keywordTable      = Manager.GetExistingKeywordsFromDb();

            var aggregationPipeline = keywordTable.Aggregate()
                                      .Match(new FilterDefinitionBuilder <KeywordSearch>().In(x => x.Keyword, sanitizedKeywords))
                                      .Unwind <KeywordSearch, UnwoundKeywordSearch>(x => x.EntryIds)
                                      .Group(x => x.EntryIds, y => new TemporaryEntrySet {
                Id = y.Key, Count = y.Count()
            });

            aggregationPipeline = exactMatch ?
                                  aggregationPipeline.Match(x => x.Count == numKeywords) :
                                  aggregationPipeline.SortByDescending(x => x.Count);

            var something = aggregationPipeline
                            .Lookup(
                foreignCollection: Manager.GetExistingDbEntries(),
                localField: x => x.Id,
                foreignField: y => y.Id,
                @as: (KeywordResult result) => result.DictionaryEntry)
                            .Unwind <KeywordResult, UnwoundKeywordResult>(x => x.DictionaryEntry)
                            .ToList();

            return(something.Select(x => x.DictionaryEntry).ToList());
        }