public static TimeSpan WriteIndexWithEvent(Analyzer analyzer, IndexerSet indexer, Source source, bool create, IndexCompletedEventHandler OnIndexCompleted, IndexProgressChangedEventHandler OnProgressChanged) { try { //ChineseSegAnalysis csa = new ChineseSegAnalysis(index.BasePath, index.NamePath, index.NumberPath, index.CustomPaths); //csa.FilterFilePath = index.FilterPath; //Analyzer analyzer = csa.GetAnalyzer(); string connect = source.GetConnString(); DateTime start; if (create) { DBRamCreateIndexer dbcIndexer = new DBRamCreateIndexer(analyzer, source.DBType, connect, index.Path,index.Caption); dbcIndexer.OnIndexCompleted += OnIndexCompleted; dbcIndexer.OnProgressChanged += OnProgressChanged; start = DateTime.Now; dbcIndexer.WriteResultsWithEvent(source.Query, indexer.MaxFieldLength, indexer.RamBufferSize, indexer.MergeFactor, indexer.MaxBufferedDocs); return DateTime.Now - start; } else { DBRamIncremIndexer dbiIndexer = new DBRamIncremIndexer(analyzer, source.DBType, connect, index.Path,index.Caption); dbiIndexer.OnIndexCompleted += OnIndexCompleted; dbiIndexer.OnProgressChanged += OnProgressChanged; start = DateTime.Now; dbiIndexer.WriteResultsWithEvent(source.Query, indexer.MaxFieldLength, indexer.RamBufferSize, indexer.MergeFactor, indexer.MaxBufferedDocs); return DateTime.Now - start; } } catch (Exception e) { throw e; } }
public static TimeSpan WriteIndex(Analyzer analyzer,IndexerSet indexer, Source source,bool create) { try { //ChineseSegAnalysis csa = new ChineseSegAnalysis(index.BasePath, index.NamePath, index.NumberPath, index.CustomPaths); //csa.FilterFilePath = index.FilterPath; //Analyzer analyzer = csa.GetAnalyzer(); string connect = source.GetConnString(); DateTime start; if (create) { DBCreateIndexer dbcIndexer = new DBCreateIndexer(analyzer, source.DBType, connect, index.Path,index.Caption); dbcIndexer.PrimaryKey = source.PrimaryKey; start = DateTime.Now; dbcIndexer.WriteResults(source.Query,indexer.MaxFieldLength,indexer.RamBufferSize, indexer.MergeFactor, indexer.MaxBufferedDocs); return DateTime.Now - start; } else { DBIncremIndexer dbiIndexer = new DBIncremIndexer(analyzer, source.DBType, connect, index.Path,index.Caption); dbiIndexer.PrimaryKey = source.PrimaryKey; start = DateTime.Now; dbiIndexer.WriteResults(source.Query, indexer.MaxFieldLength, indexer.RamBufferSize, indexer.MergeFactor, indexer.MaxBufferedDocs); return DateTime.Now - start; } } catch (Exception e) { throw e; } }
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; } }
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(); }
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; } } } }
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); } }
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 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; } }
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 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; } }
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; }
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); }