//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; } }
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; } }
private void UpdatePanelSearchData(bool update) { if (update) { if (searchSet == null) return; ipAddress.Text =searchSet.Address; numericUpDownPort.Value =searchSet.Port; numericUpDownTimeOut.Value =searchSet.TimeOut; numericUpDownMaxMatches.Value =searchSet.MaxMatches; numericUpDownMaxTransport.Value = searchSet.MaxTrans; textBoxSearchdPath.Text=searchSet.LogPath; textBoxQueryPath.Text = searchSet.QueryLogPath; } else { if (searchSet == null) searchSet = new SearchSet(); searchSet.Address =ipAddress.Text; searchSet.LogPath=textBoxSearchdPath.Text; searchSet.MaxMatches=(int)numericUpDownMaxMatches.Value; searchSet.MaxTrans = (int)numericUpDownMaxTransport.Value; searchSet.Port = (int)numericUpDownPort.Value; searchSet.QueryLogPath=textBoxQueryPath.Text; searchSet.TimeOut = (int)numericUpDownTimeOut.Value; } }
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; } }
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; } }
public void ReadXml(XmlReader reader) { string startElementName = reader.Name; string currentElementName, currentNodeName, currentItemName; this.sourceList.Clear(); this.indexList.Clear(); do { currentElementName = reader.Name; if (currentElementName == startElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { reader.Read(); break; } switch (currentElementName) { case "CommonSetting": #region CommonSet CommonSet commonSet =new CommonSet(); do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "DbType": commonSet.DBType = DbType.GetDbType(reader.ReadElementString()); break; case "HostName": commonSet.HostName = reader.ReadElementString(); break; case "DataBase": commonSet.DataBase = reader.ReadElementString(); break; case "UserName": commonSet.UserName = reader.ReadElementString(); break; case "Password": commonSet.Password = reader.ReadElementString(); break; case "Source": commonSet.Source = reader.ReadElementString(); break; default: reader.Read(); break; } } while (true); this.commonSet=commonSet; #endregion reader.Read(); break; case "Indexer": #region Indexer IndexerSet indexerSet = new IndexerSet(); do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "MainIndexTime": indexerSet.MainIndexReCreateTime = DateTime.Parse(reader.ReadElementString()); break; default: reader.Read(); break; } } while (true); this.indexerSet=indexerSet; #endregion reader.Read(); break; case "Searchd": #region Searchd SearchSet searchSet = new SearchSet(); do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "MaxChildren": searchSet.MaxChildren = int.Parse(reader.ReadElementString()); break; case "MaxMatches": searchSet.MaxMatches = int.Parse(reader.ReadElementString()); break; case "MaxTrans": searchSet.MaxTrans = int.Parse(reader.ReadElementString()); break; case "MinScore": searchSet.MinScore = float.Parse(reader.ReadElementString()); break; default: reader.Read(); break; } } while (true); this.searchSet = searchSet; #endregion reader.Read(); break; default: reader.Read(); break; } } while (true); }
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; }
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; }