Ejemplo n.º 1
0
        //private static Dictionary<string, IndexSet> nameIndexDict = new Dictionary<string, IndexSet>();
        #endregion
        #region "搜索基本设置"
        public static void SetSearchSettings(string configFileName,bool isXmlFile)
        {
            if (initSettings) return;
            try
            {
                List<Source> sourceList ;
                List<IndexSet> indexList;
                if (isXmlFile)
                {
                    Config config = (Config)SupportClass.FileUtil.GetObjectFromXmlFile(configFileName, typeof(Config));
                    sourceList = config.SourceList;
                    indexList = config.IndexList;
                    searchSet = config.SearchSet;
                    dictSet = config.DictionarySet;
                    fileSet = config.FileIndexSet;
                }
                else
                {
                    List<string> srcList = SupportClass.FileUtil.GetFileText(configFileName);
                    sourceList = Source.GetSourceList(srcList);
                    indexList = IndexSet.GetIndexList(srcList);
                    searchSet = SearchSet.GetSearchSet(srcList);
                    dictSet = DictionarySet.GetDictionarySet(srcList);
                }
                searchIndexList.AddRange(indexList);
                ISUtils.CSegment.Segment.SetPaths(dictSet.BasePath, dictSet.NamePath, dictSet.NumberPath, dictSet.FilterPath, dictSet.CustomPaths);
                ISUtils.CSegment.Segment.SetDefaults(new ISUtils.CSegment.DictionaryLoader.TextDictionaryLoader(), new ISUtils.CSegment.ForwardMatchSegment());
                if (indexDict == null)
                    indexDict = new Dictionary<IndexSet, Source>();
                foreach (IndexSet set in indexList)
                {
                    foreach (Source source in sourceList)
                    {
                        if (source.SourceName == set.SourceName)
                        {
                            if(indexDict.ContainsKey(set)==false)
                                indexDict.Add(set, source);
                            break;
                        }
                    }
                }
                SetBasicDict();
                initSettings = true;
            }
            catch (Exception e)
            {
#if DEBUG
                System.Console.WriteLine(e.StackTrace.ToString());
#endif
                throw e;
            }
        }
Ejemplo n.º 2
0
        public static void SetIndexSettings(string configFileName,bool isXmlFile)
        {
            if (initSettings) return;
            initSettings = true;
            try
            {
                List<Source> sourceList;
                List<IndexSet> indexList;
                if (isXmlFile)
                {
                    Config config = (Config)SupportClass.FileUtil.GetObjectFromXmlFile(configFileName, typeof(Config));
                    sourceList = config.SourceList;
                    indexList = config.IndexList;
                    indexerSet = config.IndexerSet;
                    dictSet = config.DictionarySet;
                    fileSet = config.FileIndexSet;
                }
                else
                {
                    List<string> srcList = SupportClass.FileUtil.GetFileText(configFileName);
                    sourceList = Source.GetSourceList(srcList);
                    indexList = IndexSet.GetIndexList(srcList);
                    indexerSet = IndexerSet.GetIndexer(srcList);
                    dictSet = DictionarySet.GetDictionarySet(srcList);
                }
                if (indexDict == null)
                    indexDict = new Dictionary<IndexSet, Source>();
                foreach (IndexSet set in indexList)
                {
                    foreach (Source source in sourceList)
                    {
                        if (source.SourceName == set.SourceName)
                        {
                            if(indexDict.ContainsKey(set)==false)
                                indexDict.Add(set, source);
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
#if DEBUG
                System.Console.WriteLine(e.StackTrace.ToString());
#endif
                throw e;
            }
        }
Ejemplo n.º 3
0
        public SearchMaker(string filename)
        {
            try
            {
                Config parser = new Config(filename,true);
                searchd = parser.GetSearchd();
                sourceList = parser.GetSourceList();
                indexList = parser.GetIndexList();
                dictSet = parser.GetDictionarySet();
                fileSet = parser.FileIndexSet;
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(string.Format("Exception for open file {0},{1}", filename, ex.ToString()));
#endif
                throw;
            }
        }
Ejemplo n.º 4
0
        public IndexMaker(string filename)
        {
            try
            {
                Config parser = new Config(filename,true);
                sourceList = parser.GetSourceList();
                indexList = parser.GetIndexList();
                indexer = parser.GetIndexer();
                dictSet = parser.GetDictionarySet();
                fileSet = parser.FileIndexSet;
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(string.Format("IndexMaker,发生异常,文件名:\t{0},\t异常:\t{1}", filename, ex.ToString()));
#endif
                throw;
            }
            Init();
        }
Ejemplo n.º 5
0
 public static void SetIndexSettings(List<Source> sourceList, List<IndexSet> indexList, DictionarySet dictSet, IndexerSet indexerSet)
 {
     if (initSettings) return;
     initSettings = true;
     IndexUtil.indexerSet = indexerSet;
     IndexUtil.dictSet = dictSet;
     if (indexDict == null)
         indexDict = new Dictionary<IndexSet, Source>();
     foreach (IndexSet set in indexList)
     {
         foreach (Source source in sourceList)
         {
             if (source.SourceName == set.SourceName)
             {
                 if(indexDict.ContainsKey(set)==false)
                     indexDict.Add(set, source);
                 break;
             }
         }
     }
 }
Ejemplo n.º 6
0
 public static void WriteToFile(ref System.IO.StreamWriter sw, DictionarySet dictSet)
 {
     sw.WriteLine("#############################################");
     sw.WriteLine("#dictionary settings");
     sw.WriteLine("#############################################");
     sw.WriteLine(Config.DictionaryFlag.ToLower());
     sw.WriteLine(Config.Prefix);
     sw.WriteLine("\t#基本词库");
     sw.WriteLine("\t" + DictionarySet.BasePathFlag.ToLower() + "=" + dictSet.BasePath);
     sw.WriteLine();
     sw.WriteLine("\t#姓氏词库");
     sw.WriteLine("\t" + DictionarySet.NamePathFlag.ToLower() + "=" + dictSet.NamePath);
     sw.WriteLine();
     sw.WriteLine("\t#数值词库");
     sw.WriteLine("\t" + DictionarySet.NumberPathFlag.ToLower() + "=" + dictSet.NumberPath);
     sw.WriteLine();
     sw.WriteLine("\t#用户词库");
     foreach(string s in dictSet.CustomPaths)
        sw.WriteLine("\t" + DictionarySet.CustomPathFlag.ToLower() + "=" + s);
     sw.WriteLine();
     sw.WriteLine("\t#过滤词库");
     sw.WriteLine("\t" + DictionarySet.FilterPathFlag.ToLower() + "=" + dictSet.FilterPath);
     sw.WriteLine(Config.Suffix);
 }
Ejemplo n.º 7
0
        /**/
        /// <summary>
        /// 获取字符串列表中的索引列表
        /// </summary>
        /// <param name="srcList">字符串列表</param>
        /// <returns>返回类型</returns>
        public static DictionarySet GetDictionarySet(List<string> srcList)
        {
            DictionarySet dictSet = new DictionarySet();
            List<string> pathList = new List<string>();
            bool findDict = false, dictStart = false;
            foreach (string s in srcList)
            {
                if (SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s), Config.DictionaryFlag))
                {
                    findDict = true;
                    continue;
                }
                if (findDict && SupportClass.String.FormatStr(s).StartsWith(Config.Prefix))
                {
                    dictStart = true;
                    continue;
                }
                if (findDict && dictStart && SupportClass.String.FormatStr(s).StartsWith(Config.Suffix))
                {
                    findDict = false;
                    dictStart = false;
                    break;
                }
                if (SupportClass.String.FormatStr(s).StartsWith(Config.Ignore))
                    continue;
                if (findDict && dictStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s), DictionarySet.BasePathFlag))
                {
                    string format = SupportClass.String.FormatStr(s);
                    string[] split = SupportClass.String.Split(format,Config.Devider);

#if DEBUG
                    Console.WriteLine(format);
                    foreach (string a in split)
                        Console.WriteLine(a);
#endif
                    if (split.Length >= 2)
                        dictSet.BasePath = split[1];
                    else
                        dictSet.BasePath = "";
                    continue;
                }
                if (findDict && dictStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s), DictionarySet.CustomPathFlag))
                {
                    string format = SupportClass.String.FormatStr(s);
                    string[] split = SupportClass.String.Split(format, Config.Devider);
#if DEBUG
                    Console.WriteLine(format);
                    foreach (string a in split)
                        Console.WriteLine(a);
#endif
                    if (split.Length >= 2)
                        pathList.Add(split[1]);
                    continue;
                }
                if (findDict && dictStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s), DictionarySet.FilterPathFlag))
                {
                    string format = SupportClass.String.FormatStr(s);
                    string[] split = SupportClass.String.Split(format, Config.Devider);
#if DEBUG
                    Console.WriteLine(format);
                    foreach (string a in split)
                        Console.WriteLine(a);
#endif
                    if (split.Length >= 2)
                        dictSet.FilterPath = split[1];
                    else
                        dictSet.FilterPath = "";
                    continue;
                }
                if (findDict && dictStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s), DictionarySet.NamePathFlag))
                {
                    string format = SupportClass.String.FormatStr(s);
                    string[] split = SupportClass.String.Split(format, Config.Devider);
#if DEBUG
                    Console.WriteLine(format);
                    foreach (string a in split)
                        Console.WriteLine(a);
#endif
                    if (split.Length >= 2)
                        dictSet.NamePath = split[1];
                    else
                        dictSet.NamePath = "";
                    continue;
                }
                if (findDict && dictStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s), DictionarySet.NumberPathFlag))
                {
                    string format = SupportClass.String.FormatStr(s);
                    string[] split = SupportClass.String.Split(format, Config.Devider);
#if DEBUG
                    Console.WriteLine(format);
                    foreach (string a in split)
                        Console.WriteLine(a);
#endif
                    if (split.Length >= 2)
                        dictSet.NumberPath = split[1];
                    else
                        dictSet.NumberPath = "";
                    continue;
                }
            }
            dictSet.CustomPaths = pathList;
            return dictSet;
        }
Ejemplo n.º 8
0
 public static void WriteConfigFile(string path, List<Source> sourceList, List<IndexSet> indexList,FileIndexSet fileSet, DictionarySet dictSet, IndexerSet indexerSet, SearchSet searchSet)
 {
     try
     {
         if (IsFileExists(path) != false)
         {
             System.IO.File.Delete(path); 
         }
         FileStream fs = new FileStream(path, FileMode.CreateNew);
         StreamWriter sw = new StreamWriter(fs,Encoding.GetEncoding("gb2312"));
         if(sourceList !=null)
         foreach (Source s in sourceList)
             Source.WriteToFile(ref sw, s);
         if (indexList!=null)
         foreach (IndexSet i in indexList)
             IndexSet.WriteToFile(ref sw, i);
         if (fileSet != null)
             FileIndexSet.WriteToFile(ref sw, fileSet);
         if (dictSet !=null)
             DictionarySet.WriteToFile(ref sw, dictSet);
         if(indexerSet !=null)
             IndexerSet.WriteToFile(ref sw, indexerSet);
         if(searchSet !=null)
             SearchSet.WriteToFile(ref sw, searchSet);
         sw.Flush();
         sw.Close();
         fs.Close();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 9
0
        public static void Execute(List<Source> sourceList, DictionarySet dictSet, IndexerSet indexer, bool create, ref Message msg)
        {
            try
            {
                DateTime allStart = DateTime.Now;
                msg.AddInfo("All Start at :" + allStart.ToLocalTime());
                Utils.IndexUtil.SetIndexSettings(dict, dictSet, indexer);
                //由于中文分词结果随中文词库的变化而变化,为了使索引不需要根据中文词库的变化而变化,
                //故采用默认的Analyzer来进行分词,即StandardAnalyzer
                //Utils.IndexUtil.UseDefaultChineseAnalyzer(true);
                Utils.IndexUtil.Index(create);
                msg.AddInfo("All End at :"+DateTime.Now.ToLocalTime());
                TimeSpan allSpan=DateTime.Now -allStart;
                msg.AddInfo(string.Format("All Spend {0} millionseconds.",allSpan.TotalMilliseconds));
                msg.Success =true;
                msg.Result="Execute Success.";
            }
            catch (Exception e)
            {
#if DEBUG
                Console.WriteLine("Execute Indexer Error.Reason:"+e.Message);
#endif
                msg.AddInfo("Write Index Error.Reason:"+e.StackTrace.ToString());
                msg.Success=false;
                msg.ExceptionOccur = true;
                throw e;
            }
        }
Ejemplo n.º 10
0
 public static void SetIndexSettings(List<Source> sourceList, FileIndexSet fileIndexSet, DictionarySet dictSet, IndexerSet indexerSet)
 {
     if (initSettings) return;
     initSettings = true;
     if (dict != null)
         indexDict = dict;
     else
         indexDict = new Dictionary<IndexSet, Source>();
     IndexUtil.dictSet = dictSet;
     IndexUtil.indexerSet = indexerSet;
     IndexUtil.fileSet = fileIndexSet;
 }
Ejemplo n.º 11
0
 public static void SetSearchSettings(List<Source> sourceList, List<IndexSet> indexList, DictionarySet dictSet, SearchSet searchSet)
 {
     if (initSettings) return;
     SearchUtil.searchSet = searchSet;
     SearchUtil.dictSet = dictSet;
     ISUtils.CSegment.Segment.SetPaths(dictSet.BasePath, dictSet.NamePath, dictSet.NumberPath, dictSet.FilterPath, dictSet.CustomPaths);
     ISUtils.CSegment.Segment.SetDefaults(new ISUtils.CSegment.DictionaryLoader.TextDictionaryLoader(), new ISUtils.CSegment.ForwardMatchSegment());
     searchIndexList.AddRange(indexList);
     if (indexDict == null)
         indexDict = new Dictionary<IndexSet, Source>();
     foreach (IndexSet set in indexList)
     {
         foreach (Source source in sourceList)
         {
             if (source.SourceName == set.SourceName)
             {
                 if(indexDict.ContainsKey(set)==false)
                     indexDict.Add(set, source);
                 break;
             }
         }
     }
     SetBasicDict();
     initSettings = true;
 }
Ejemplo n.º 12
0
 public static void SetSearchSettings(List<Source> sourceList, FileIndexSet fileIndexSet, DictionarySet dictSet, SearchSet searchSet)
 {
     if (initSettings) return;
     if (dict != null)
         indexDict = dict;
     else
         indexDict = new Dictionary<IndexSet, Source>();
     searchIndexList.AddRange(indexDict.Keys);
     SearchUtil.dictSet = dictSet;
     SearchUtil.searchSet = searchSet;
     SearchUtil.fileSet = fileIndexSet;
     ISUtils.CSegment.Segment.SetPaths(dictSet.BasePath, dictSet.NamePath, dictSet.NumberPath, dictSet.FilterPath, dictSet.CustomPaths);
     ISUtils.CSegment.Segment.SetDefaults(new ISUtils.CSegment.DictionaryLoader.TextDictionaryLoader(), new ISUtils.CSegment.ForwardMatchSegment());
     SetBasicDict();
     initSettings = true;
 }