Exemple #1
0
 private static void InitDict()
 {
     if (LuceneNetConfig.ChildrenCultureDirectoryList != null && LuceneNetConfig.ChildrenCultureDirectoryList.Count > 0)
     {
         lock (lockObject)
         {
             string applicationPath = null;
             foreach (string childDirectory in LuceneNetConfig.ChildrenCultureDirectoryList)
             {
                 applicationPath = Path.Combine(LuceneNetConfig.LuceneDictDirectory, childDirectory, SYNONYM_FILE_NAME);
                 if (File.Exists(applicationPath))
                 {
                     Dictionary <string, string[]> synonymsDict = new Dictionary <string, string[]>();
                     Encoding encoding = EncodingType.GetType(applicationPath);
                     using (StreamReader sr = new StreamReader(applicationPath, encoding))
                     {
                         while (!sr.EndOfStream)
                         {
                             string line = sr.ReadLine();
                             if (!string.IsNullOrEmpty(line))
                             {
                                 string[] synonymsWords = SplitWordTool.SplitWord(line);
                                 if (synonymsWords.Length > 0)
                                 {
                                     synonymsDict[line] = synonymsWords;
                                 }
                             }
                         }
                     }
                     _SynonymsDict[childDirectory] = synonymsDict;
                 }
             }
         }
     }
 }
        /// <summary>
        /// 获取同义词,相关词
        /// </summary>
        /// <param name="keyWord"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public static List <string> GetKeyWordsWithSynonyms(string keyWord, string language = "EN")
        {
            List <string> wordList = new List <string>();

            string[] keywords = SplitWordTool.SplitWord(keyWord);
            foreach (string word in keywords)
            {
                string item = SplitWordTool.SnowballWord(word, language);
                wordList.AddRange(SynonymDict.GetSynonymsWord(language, item));
            }
            return(wordList);
        }
Exemple #3
0
        /// <summary>
        /// 搜索结果高亮显示
        /// </summary>
        /// <param name="keyword">关键字</param>
        /// <param name="content">搜索结果</param>
        /// <returns>高亮后显示的结果</returns>
        public static string HighLight(string keyword, string content)
        {
            string[] keywords  = SplitWordTool.SplitWord(keyword);
            bool     isInclude = false;

            if (keywords.Length > 1)
            {
                content = HighLight(keyword, content, out isInclude);
            }
            if (!isInclude)
            {
                foreach (string word in keywords)
                {
                    content = HighLight(word, content, out isInclude);
                }
            }
            return(content);
        }
 /// <summary>
 /// 得到关键字
 /// </summary>
 /// <param name="keyword"></param>
 /// <returns></returns>
 public static string GetKeyWords(string keyword)
 {
     string[] keywords = SplitWordTool.SplitWord(keyword);
     return(GetKeyWords(keywords));
 }