Пример #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;
            }
        }
Пример #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;
            }
        }
Пример #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;
            }
        }
Пример #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();
        }
Пример #5
0
 private void UpdatePanelIndexerData(bool update)
 {
     if (update)
     {
         if (indexerSet == null) return;
         dateTimePickerMainReCreate.Text = indexerSet.MainIndexReCreateTime.ToShortTimeString();
         numericUpDownMainCreateTimeSpan.Value =indexerSet.MainIndexReCreateTimeSpan; 
         numericUpDownIncrTimeSpan.Value =indexerSet.IncrIndexReCreateTimeSpan; 
         numericUpDownRamBufferSize.Value =(int)indexerSet.RamBufferSize;
         numericUpDownMaxFieldLength.Value=indexerSet.MaxFieldLength;
         numericUpDownMaxBufferedDocs.Value =indexerSet.MaxBufferedDocs;
         numericUpDownMergeFactor.Value =indexerSet.MergeFactor;
         if (fileSet == null) return;
         textBoxFilePath.Text = fileSet.Path;
         listBoxFileDirs.Items.Clear();
         listBoxFileDirs.Items.AddRange(fileSet.BaseDirs.ToArray());
     }
     else
     {
         if (indexerSet == null) indexerSet = new IndexerSet();
         indexerSet.IncrIndexReCreateTimeSpan = (int)numericUpDownIncrTimeSpan.Value;
         indexerSet.MainIndexReCreateTime=DateTime.Parse(dateTimePickerMainReCreate.Text);
         indexerSet.MainIndexReCreateTimeSpan = (int)numericUpDownMainCreateTimeSpan.Value;
         indexerSet.MaxBufferedDocs = (int)numericUpDownMaxBufferedDocs.Value;
         indexerSet.MaxFieldLength = (int)numericUpDownMaxFieldLength.Value;
         indexerSet.MergeFactor = (int)numericUpDownMergeFactor.Value;
         indexerSet.RamBufferSize=(double)numericUpDownRamBufferSize.Value;
         if (fileSet == null) fileSet = new FileIndexSet();
         fileSet.Path = textBoxFilePath.Text;
         object[] objs = new object[listBoxFileDirs.Items.Count];
         string[] paths = new string[listBoxFileDirs.Items.Count];
         listBoxFileDirs.Items.CopyTo(objs, 0);
         objs.CopyTo(paths, 0);
         fileSet.BaseDirs.Clear();
         fileSet.AddDirectory(paths);
     }
 }
Пример #6
0
        private bool InitData(string filename)
        {
            try
            {
                Config parser = new Config(filename,true);
                searchSet = parser.GetSearchd();
                sourceList = parser.GetSourceList();
                indexList = parser.GetIndexList();
                dictSet = parser.GetDictionarySet();
                indexerSet = parser.GetIndexer();
                fileSet = parser.FileIndexSet;
                return true;
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(string.Format("Exception for open file {0},{1}", filename, ex.ToString()));
#endif
                ShowError(string.Format("Exception for open file {0},{1}", filename, ex.ToString()));
                return false;
            }
        }
Пример #7
0
 public static bool Index(Analyzer analyzer, FileIndexSet fileIndex,IndexerSet indexer, bool create)
 {
     try
     {
         IndexWriter writer = new IndexWriter(fileIndex.Path, analyzer, create);
         writer.SetMaxFieldLength(indexer.MaxFieldLength);
         writer.SetRAMBufferSizeMB(indexer.RamBufferSize);
         writer.SetMergeFactor(indexer.MergeFactor);
         writer.SetMaxBufferedDocs(indexer.MaxBufferedDocs);
         foreach (string dir in fileIndex.BaseDirs)
         {
             IndexDir(writer, dir);
         }
         return true;
     }
     catch (Exception )
     {
         return false;
     }
 }
Пример #8
0
 public static bool Index(Analyzer analyzer, FileIndexSet set, int maxFieldLength, double ramBufferSize, int mergeFactor, int maxBufferedDocs, bool create)
 {
     try
     {
         IndexWriter writer = new IndexWriter(set.Path, analyzer, create);
         writer.SetMaxFieldLength(maxFieldLength);
         writer.SetRAMBufferSizeMB(ramBufferSize);
         writer.SetMergeFactor(mergeFactor);
         writer.SetMaxBufferedDocs(maxBufferedDocs);
         foreach (string dir in set.BaseDirs)
         {
             IndexDir(writer, dir);
         }
         return true;
     }
     catch (Exception )
     {
         return false;
     }
 }
Пример #9
0
 /**/
 /// <summary>
 /// 构造函数
 /// </summary>
 public Config()
 { 
 }
 /**/
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="configFilePath">配置文件路径</param>
 public Config(string configFilePath,bool isXmlFile)
 {
     if (configFilePath == null)
         throw new ArgumentNullException("configFilePath", "configFilePath must no be null!");
     if (SupportClass.FileUtil.IsFileExists(configFilePath) == false)
         throw new ArgumentException("configFilePath must be exists!", "configFilePath");
     if (isXmlFile)
     {
         Config config ;
         config = (Config)SupportClass.FileUtil.GetObjectFromXmlFile(configFilePath,typeof(Config));
         this.dictSet = config.dictSet;
         this.indexer = config.indexer;
         this.indexList = config.indexList;
         this.searchd = config.searchd;
         this.sourceList = config.sourceList;
         this.fileSet = config.fileSet;
     }
     else
     {
         List<string> src = SupportClass.FileUtil.GetFileText(configFilePath);
         sourceList = Source.GetSourceList(src);
         indexList = IndexSet.GetIndexList(src);
         indexer = IndexerSet.GetIndexer(src);
         searchd = SearchSet.GetSearchSet(src);
         dictSet = DictionarySet.GetDictionarySet(src);
     }
 }
Пример #10
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;
     }
 }
Пример #11
0
 public static void SetIndexSettings(List<Source> sourceList, List<IndexSet> indexList, FileIndexSet fileIndexSet, DictionarySet dictSet, IndexerSet indexerSet)
 {
     if (initSettings) return;
     initSettings = true;
     IndexUtil.fileSet = fileIndexSet;
     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;
             }
         }
     }
 }
Пример #12
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;
 }
Пример #13
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;
 }
Пример #14
0
 public static void SetSearchSettings(List<Source> sourceList, List<IndexSet> indexList,FileIndexSet fileIndexSet, DictionarySet dictSet, SearchSet searchSet)
 {
     if (initSettings) return;
     SearchUtil.searchSet = searchSet;
     SearchUtil.dictSet = dictSet;
     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());
     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;
 }