示例#1
0
 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;
     }
 }
示例#2
0
 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;
     }
 }
示例#3
0
 private void btnDelSource_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(textBoxSourceName.Text))
         return;
     if (sourceList == null)
         return;
     if (source == null)
         return;
     if (sourceList.Count <= 0)
         return;
     status = Status.Delete;
     if (ShowQuestion("确认删除吗?") == false)
         return;
     sourceList.Remove(source);
     foreach (IndexSet set in indexList)
     {
         if (set.SourceName == source.SourceName)
         {
             indexList.Remove(set);
         }
     }
     if (indexList.Count > 0)
     {
         if (indexSet.SourceName == source.SourceName)
             indexSet = indexList[0];
     }
     else
     {
         indexSet = new IndexSet();
     }
     InitListBoxIndex(indexList);
     if (sourceList.Count > 0)
         source = sourceList[0];
     else
         source = new Source();
     InitListBoxSource(sourceList);
     InitComboBoxSourceSel(sourceList);
     UpdatePanelSourceData(true);
     EnablePanelSourceButtons(status);
 }
示例#4
0
 private void btnAddSource_Click(object sender, EventArgs e)
 {
     if (sourceList == null) return;
     source = new Source();
     UpdatePanelSourceData(true);
     EnablePanelSourceControls(true);
     status = Status.Insert;
     EnablePanelSourceButtons(status);
     listBoxSource.Enabled = false;
 }
示例#5
0
 private void UpdatePanelSourceData(bool update)
 {
     if (update)
     {
         if (source == null) return;
         textBoxSourceName.Text=source.SourceName;
         comboBoxSourceType.Text = ISUtils.Common.DbType.GetDbTypeStr(source.DBType);
         textBoxDataBase.Text=source.DataBase;
         textBoxFields.Text=source.GetFields();
         textBoxHostName.Text=source.HostName;
         textBoxPassword.Text=source.Password;
         textBoxQuery.Text=source.Query;
         textBoxUserName.Text=source.UserName;
     }
     else
     {
         if (source == null) source = new Source();
         source.SourceName = textBoxSourceName.Text;
         source.DBType = ISUtils.Common.DbType.GetDbType(comboBoxSourceType.Text);
         source.DataBase = textBoxDataBase.Text;
         source.Fields = IndexField.ToList(textBoxFields.Text);
         source.HostName = textBoxHostName.Text;
         source.Password = textBoxPassword.Text;
         source.Query = textBoxQuery.Text;
         source.UserName = textBoxUserName.Text;
     }
 }
示例#6
0
 private void InitPanelSourceControls(string sourcename)
 {
     foreach (Source s in sourceList)
     {
         if (s.SourceName.ToUpper().CompareTo(sourcename.ToUpper()) == 0)
         {
             source = s;
         }
     }
     UpdatePanelSourceData(true);
 }
示例#7
0
 private void btnSourceCancel_Click(object sender, EventArgs e)
 {
     if (sourceList != null && sourceList.Count>0)
     {
         source = sourceList[0];
         UpdatePanelSourceData(true);
     }
     EnablePanelSourceControls(false);
     status = Status.Cancel;
     listBoxSource.Enabled = true;
     EnablePanelSourceButtons(status);
 }
示例#8
0
        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 "Source":
                        #region Read Source
                        Source source = new Source();
                        source.SourceName = SupportClass.FileUtil.GetXmlAttribute(reader, "Name", typeof(string));
                        do
                        {
                            currentNodeName = reader.Name;
                            if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                            {
                                break;
                            }
                            switch (currentNodeName)
                            {
                                case "DbType":
                                    source.DBType = DbType.GetDbType(reader.ReadElementString());
                                    break;
                                case "HostName":
                                    source.HostName = reader.ReadElementString();
                                    break;
                                case "DataBase":
                                    source.DataBase = reader.ReadElementString();
                                    break;
                                case "UserName":
                                    source.UserName = reader.ReadElementString();
                                    break;
                                case "Password":
                                    source.Password = reader.ReadElementString();
                                    break;
                                case "Query":
                                    source.Query = reader.ReadElementString();
                                    break;
                                case "PrimaryKey":
                                    source.PrimaryKey = reader.ReadElementString();
                                    break;
                                case "Fields":
                                    List<IndexField> fpList = new List<IndexField>();
                                    do
                                    {
                                        currentItemName = reader.Name;
                                        if (currentItemName == currentNodeName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                                        {
                                            break;
                                        }
                                        switch (currentItemName)
                                        {
                                            case "Field":
                                                IndexField fp = new IndexField();
                                                fp.Name = SupportClass.FileUtil.GetXmlAttribute(reader, "Name", typeof(string));
                                                fp.Caption = SupportClass.FileUtil.GetXmlAttribute(reader, "Caption", typeof(string));
                                                fp.Boost = float.Parse(SupportClass.FileUtil.GetXmlAttribute(reader, "Boost", typeof(float)));
                                                fp.IsTitle = bool.Parse(SupportClass.FileUtil.GetXmlAttribute(reader, "IsTitle", typeof(bool)));
                                                fp.Order = int.Parse(SupportClass.FileUtil.GetXmlAttribute(reader, "Order", typeof(int)));
                                                fpList.Add(fp);
                                                reader.Read();
                                                break;
                                            default:
                                                reader.Read();
                                                break;
                                        }
                                    } while (true);
                                    source.Fields=fpList;
                                    reader.Read();
                                    break;
                                default :
                                    reader.Read();
                                    break;
                            }
                        } while (true);
                        this.sourceList.Add(source);
                        #endregion
                        reader.Read();
                        break;
                    case "Index":
                        #region Read Index
                        IndexSet indexSet = new IndexSet();
                        indexSet.IndexName = SupportClass.FileUtil.GetXmlAttribute(reader, "Name", typeof(string));
                        indexSet.Caption = SupportClass.FileUtil.GetXmlAttribute(reader, "Caption", typeof(string));
                        indexSet.Type = IndexType.GetIndexType(SupportClass.FileUtil.GetXmlAttribute(reader, "Type", typeof(string)));
                        do
                        {
                            currentNodeName = reader.Name;
                            if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                            {
                                break;
                            }
                            switch (currentNodeName)
                            {
                                case "Source":
                                    indexSet.SourceName= reader.ReadElementString();
                                    break;
                                case "Path":
                                    indexSet.Path = reader.ReadElementString();
                                    break;
                                default:
                                    reader.Read();
                                    break;
                            }
                        } while (true);
                        this.indexList.Add(indexSet);
                        #endregion
                        reader.Read();
                        break;
                    case "FileIndex":
                        #region Read FileIndex
                        do
                        {
                            currentNodeName = reader.Name;
                            if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                            {
                                break;
                            }
                            switch (currentNodeName)
                            {
                                case "Path":
                                    this.fileSet.Path = reader.ReadElementString();
                                    break;
                                case "Directories":
                                    List<string> dirList = new List<string>();
                                    do
                                    {
                                        currentItemName = reader.Name;
                                        if (currentItemName == currentNodeName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                                        {
                                            break;
                                        }
                                        switch (currentItemName)
                                        {
                                            case "Directory":
                                                dirList.Add(reader.ReadElementString());
                                                break;
                                            default:
                                                reader.Read();
                                                break;
                                        }
                                    } while (true);
                                    this.fileSet.BaseDirs =dirList;
                                    reader.Read();
                                    break;
                                default:
                                    reader.Read();
                                    break;
                            }
                        } while (true);
                        #endregion
                        reader.Read();
                        break;
                    case "Dictionary":
                        #region Read Dictionary
                        do
                        {
                            currentNodeName = reader.Name;
                            if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                            {
                                break;
                            }
                            switch (currentNodeName)
                            {
                                case "BasePath":
                                    this.dictSet.BasePath = reader.ReadElementString();
                                    break;
                                case "NamePath":
                                    this.dictSet.NamePath = reader.ReadElementString();
                                    break;
                                case "NumberPath":
                                    this.dictSet.NumberPath = reader.ReadElementString();
                                    break;
                                case "FilterPath":
                                    this.dictSet.FilterPath = reader.ReadElementString();
                                    break;
                                case "CustomPaths":
                                    List<string> pathList = new List<string>();
                                    do
                                    {
                                        currentItemName = reader.Name;
                                        if (currentItemName == currentNodeName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                                        {
                                            break;
                                        }
                                        switch (currentItemName)
                                        {
                                            case "Path":
                                                pathList.Add(reader.ReadElementString());
                                                break;
                                            default:
                                                reader.Read();
                                                break;
                                        }
                                    } while (true);
                                    this.dictSet.CustomPaths = pathList;
                                    reader.Read();
                                    break;
                                default:
                                    reader.Read();
                                    break;
                            }
                        } while (true);
                        #endregion
                        reader.Read();
                        break;
                    case "Indexer":
                        #region Read Indexer
                        do
                        {
                            currentNodeName = reader.Name;
                            if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                            {
                                break;
                            }
                            switch (currentNodeName)
                            {
                                case "MainIndexTime":
                                    this.indexer.MainIndexReCreateTime = DateTime.Parse(reader.ReadElementString());
                                    break;
                                case "MainIndexSpan":
                                    this.indexer.MainIndexReCreateTimeSpan = int.Parse(reader.ReadElementString());
                                    break;
                                case "IncrIndexSpan":
                                    this.indexer.IncrIndexReCreateTimeSpan = int.Parse(reader.ReadElementString());
                                    break;
                                case "RamBufferSize":
                                    this.indexer.RamBufferSize = double.Parse(reader.ReadElementString());
                                    break;
                                case "MaxBufferedDocs":
                                    this.indexer.MaxBufferedDocs = int.Parse(reader.ReadElementString());
                                    break;
                                case "MaxFieldLength":
                                    this.indexer.MaxFieldLength = int.Parse(reader.ReadElementString());
                                    break;
                                case "MergeFactor":
                                    this.indexer.MergeFactor = int.Parse(reader.ReadElementString());
                                    break;
                                default:
                                    reader.Read();
                                    break;
                            }
                        } while (true);
                        #endregion
                        reader.Read();
                        break;
                    case "Searchd":
                        #region Read Searchd
                        do
                        {
                            currentNodeName = reader.Name;
                            if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement))
                            {
                                break;
                            }
                            switch (currentNodeName)
                            {
                                case "Address":
                                    this.searchd.Address = reader.ReadElementString();
                                    break;
                                case "LogPath":
                                    this.searchd.LogPath = reader.ReadElementString();
                                    break;
                                case "MaxChildren":
                                    this.searchd.MaxChildren = int.Parse(reader.ReadElementString());
                                    break;
                                case "MaxMatches":
                                    this.searchd.MaxMatches = int.Parse(reader.ReadElementString());
                                    break;
                                case "MaxTrans":
                                    this.searchd.MaxTrans = int.Parse(reader.ReadElementString());
                                    break;
                                case "Port":
                                    this.searchd.Port = int.Parse(reader.ReadElementString());
                                    break;
                                case "TimeOut":
                                    this.searchd.TimeOut = int.Parse(reader.ReadElementString());
                                    break;
                                case "QueryLog":
                                    this.searchd.QueryLogPath = reader.ReadElementString();
                                    break;
                                case "MinScore":
                                    this.searchd.MinScore = float.Parse(reader.ReadElementString());
                                    break;
                                default:
                                    reader.Read();
                                    break;
                            }
                        } while (true);
                        #endregion
                        reader.Read();
                        break;
                    default:
                        reader.Read();
                        break;

                }
            } while (true);
        }
示例#9
0
 public static void BoostIndexWithEvent(Source source, bool isIncreament, IndexCompletedEventHandler OnIndexCompleted, IndexProgressChangedEventHandler OnProgressChanged)
 {
     if (!initSettings)
         throw new ApplicationException("Index Settings not init!");
     if (indexDict.Count > 0 && indexDict.ContainsKey(indexSet))
     {
         //DataBaseLibrary.SearchUpdateManage dblSum = new DataBaseLibrary.SearchUpdateManage();
         SupportClass.FileUtil.DeleteFolder(indexSet.Path);
         IWriter.WriteBoostIndexWithEvent(analyzer, indexerSet, indexSet, indexDict[indexSet], type == IndexTypeEnum.Ordinary, OnIndexCompleted, OnProgressChanged);
     }
 }
示例#10
0
 public static Dictionary<IndexSet,Source> GetExcelSettings(string path)
 {
     if (SupportClass.FileUtil.IsFileExists(path) == false)
         throw new ArgumentException("path is not valid.", "path");
     DataTable table = ExcelLinker.GetDataTableFromFile(path);
     List<Source> sourceList = new Dictionary<IndexSet, Source>();
     string tableName = "",currentTableName;
     Source source=null;
     IndexSet indexSet=null;
     List<IndexField> fpList=new List<IndexField>();
     bool change=false;
     foreach (DataRow row in table.Rows)
     {
         IndexField fp=new IndexField();
         fp.Visible = true;
         fp.Order = 0;
         foreach (DataColumn column in table.Columns)
         {
             System.Console.Write(row[column] + "\t");
             if (column.ColumnName.Equals("Table"))
             {
                 currentTableName = row[column].ToString();
                 if (currentTableName != tableName)
                 {
                     if (source != null && indexSet != null)
                     {
                         source.Fields=fpList;
                         if (dict.ContainsKey(indexSet) == false)
                         {
                             dict.Add(indexSet, source);
                             IndexSet newIndexSet =new IndexSet(indexSet);
                             Source newSource = new Source(source);
                             newIndexSet.IndexName = Config.IndexPrefix + newIndexSet.IndexName;
                             newIndexSet.SourceName = Config.SourcePrefix + newIndexSet.SourceName;
                             newIndexSet.Type = IndexTypeEnum.Increment;
                             newSource.SourceName = Config.SourcePrefix + newSource.SourceName;
                             newSource.Query = newSource.Query + " where SearchLabel=1";
                             dict.Add(newIndexSet, newSource);
                         }
                     }
                     tableName = currentTableName;
                     fpList = new List<IndexField>();
                     source = new Source();
                     indexSet = new IndexSet();
                     source.SourceName = row[column].ToString();
                     source.Query = "select * from " + row[column].ToString();
                     indexSet.IndexName = row[column].ToString();
                     indexSet.SourceName = row[column].ToString();
                     indexSet.Path = @"D:\IndexData\" + indexSet.IndexName;
                     change =true;
                 }
                 else
                 {
                     change =false;
                 }
             }
             else if (column.ColumnName.Equals("TableCaption"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     indexSet.Caption = row[column].ToString();
             }
             else if (column.ColumnName.Equals("DbType"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.DBType = ISUtils.Common.DbType.GetDbType(row[column].ToString());
             }
             else if (column.ColumnName.Equals("HostName"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.HostName = row[column].ToString();
             }
             else if (column.ColumnName.Equals("DataBase"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.DataBase = row[column].ToString();
             }
             else if (column.ColumnName.Equals("UserName"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.UserName = row[column].ToString();
             }
             else if (column.ColumnName.Equals("Password"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.Password = row[column].ToString();
             }
             else if (column.ColumnName.Equals("Field"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                     fp.Name = row[column].ToString();
             }
             else if (column.ColumnName.Equals("Caption"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                     fp.Caption = row[column].ToString();
             }
             else if (column.ColumnName.Equals("IsTitle"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                 {
                     if (row[column].Equals("标题"))
                     {
                         fp.IsTitle=true;
                     }
                     else if (row[column].Equals("内容"))
                     {
                         fp.IsTitle =false;
                     }
                     else 
                     {
                         try
                         {
                             fp.IsTitle =bool.Parse(row[column].ToString());
                         }
                         catch(Exception)
                         {
                             fp.IsTitle =false;
                         }
                     }
                 }
             }
             else if (column.ColumnName.Equals("Boost"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                 {
                     try
                     {
                         fp.Boost = float.Parse(row[column].ToString());
                     }
                     catch (Exception)
                     {
                         fp.Boost = 1.0f;
                     }
                 }
             }
             else if (column.ColumnName.Equals("Order"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                 {
                     try
                     {
                         fp.Order = int.Parse(row[column].ToString());
                     }
                     catch (Exception)
                     {
                         fp.Order = 0;
                     }
                 }
             }
             else if (column.ColumnName.Equals("PK"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                 {
                     try
                     {
                         source.PrimaryKey=row[column].ToString();
                     }
                     catch (Exception)
                     {
                     }
                 }
             }
             else
             { 
             }
         }
         fpList.Add(fp);
         System.Console.WriteLine();
     }
     if (source != null && indexSet != null)
     {
         source.Fields = fpList;
         if (dict.ContainsKey(indexSet) == false)
         {
             dict.Add(indexSet, source);
             IndexSet newIndexSet = new IndexSet(indexSet);
             Source newSource = new Source(source);
             newIndexSet.IndexName = Config.IndexPrefix + newIndexSet.IndexName;
             newIndexSet.SourceName = Config.SourcePrefix + newIndexSet.SourceName;
             newIndexSet.Type = IndexTypeEnum.Increment;
             newSource.SourceName = Config.SourcePrefix + newSource.SourceName;
             newSource.Query = newSource.Query + " where SearchLabel=1";
             dict.Add(newIndexSet, newSource);
         }
     }
     return dict;
 }