private void UpdatePanelIndexData(bool update) { if (update) { if (indexSet == null) return; textBoxIndexName.Text = indexSet.IndexName; textBoxIndexCaption.Text = indexSet.Caption; comboBoxIndexType.Text = IndexType.GetIndexTypeStr(indexSet.Type); comboBoxSouceSel.Text = indexSet.SourceName; textBoxIndexPath.Text = indexSet.Path; } else { if (indexSet == null) indexSet = new IndexSet(); indexSet.IndexName = textBoxIndexName.Text; indexSet.Caption = textBoxIndexCaption.Text; indexSet.Type = IndexType.GetIndexType(comboBoxIndexType.Text); indexSet.SourceName = comboBoxSouceSel.Text; indexSet.Path = textBoxIndexPath.Text; } }
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); }
private void btnIndexCancel_Click(object sender, EventArgs e) { if (indexList != null && indexList.Count > 0) { indexSet = indexList[0]; UpdatePanelIndexData(true); } EnablePanelIndexControls(false); status = Status.Cancel; listBoxIndex.Enabled = true; EnableControls(btnAddIndex, btnEditIndex, btnDelIndex, btnIndexConfirm, btnIndexCancel); }
private void InitPanelIndexControls(string indexname) { foreach (IndexSet i in indexList) { if (i.IndexName.ToUpper().CompareTo(indexname.ToUpper()) == 0) { indexSet = i; } } UpdatePanelIndexData(true); }
private void btnAddIndex_Click(object sender, EventArgs e) { if (indexList == null) return; indexSet = new IndexSet(); UpdatePanelIndexData(true); EnablePanelIndexControls(true); status = Status.Insert; EnableControls(btnAddIndex, btnEditIndex, btnDelIndex, btnIndexConfirm, btnIndexCancel); listBoxIndex.Enabled = false; }
private void btnDelIndex_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxIndexName.Text)) return; if (indexList == null) return; if (indexSet == null) return; if (indexList.Count <= 0) return; status = Status.Delete; if (ShowQuestion("确认删除吗?")) { indexList.Remove(indexSet); InitListBoxIndex(indexList); if (indexList.Count > 0) indexSet = indexList[0]; else indexSet = new IndexSet(); InitListBoxIndex(indexList); UpdatePanelSourceData(true); } }
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; }
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); }
public IndexSet(IndexSet set) { this.Caption = set.Caption; this.IndexName = set.IndexName; this.Path = set.Path; this.SourceName = set.SourceName; this.Type = set.Type; }
public static void WriteToFile(ref System.IO.StreamWriter sw, IndexSet indexSet) { sw.WriteLine("#############################################"); sw.WriteLine(string.Format("#index {0}", indexSet.IndexName)); sw.WriteLine("#############################################"); sw.WriteLine(Config.IndexFlag.ToLower() + " " + indexSet.IndexName); sw.WriteLine(Config.Prefix); sw.WriteLine("\t#索引源名"); sw.WriteLine("\t" + Config.SourceFlag.ToLower() + "=" + indexSet.SourceName); sw.WriteLine(); sw.WriteLine("\t#索引类型"); sw.WriteLine("\t#" + IndexSet.TypeFlag.ToLower() + "=" + IndexType.GetIndexTypeStr(IndexTypeEnum.Increment)); sw.WriteLine("\t#" + IndexSet.TypeFlag.ToLower() + "=" + IndexType.GetIndexTypeStr(IndexTypeEnum.Ordinary)); sw.WriteLine("\t" + IndexSet.TypeFlag.ToLower() + "=" + IndexType.GetIndexTypeStr(indexSet.Type)); sw.WriteLine(); sw.WriteLine("\t#索引存储路径"); sw.WriteLine("\t" + IndexSet.PathFlag.ToLower() + "=" + indexSet.Path); sw.WriteLine(Config.Suffix); }
/**/ /// <summary> /// 获取字符串列表中的索引列表 /// </summary> /// <param name="srcList">字符串列表</param> /// <returns>返回类型</returns> public static List<IndexSet> GetIndexList(List<string> srcList) { List<IndexSet> indexList = new List<IndexSet>(); bool findIndex = false, indexStart = false; IndexSet index = new IndexSet(); foreach (string s in srcList) { if (SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s),Config.IndexFlag)) { findIndex = true; index = new IndexSet(); string format = SupportClass.String.FormatStr(s); string[] split = SupportClass.String.Split(format, " \t"); #if DEBUG Console.WriteLine(format); foreach (string a in split) Console.WriteLine(a); #endif if (split.Length < 2) throw new ApplicationException("No index name in this index"); index.IndexName = split[1]; continue; } if (findIndex && SupportClass.String.FormatStr(s).StartsWith(Config.Prefix)) { indexStart = true; continue; } if (findIndex && indexStart && SupportClass.String.FormatStr(s).StartsWith(Config.Suffix)) { findIndex = false; indexStart = false; if (string.IsNullOrEmpty(index.IndexName) == false) indexList.Add(index ); continue; } if (SupportClass.String.FormatStr(s).StartsWith(Config.Ignore)) continue; if (findIndex && indexStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s),IndexSet.TypeFlag)) { 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) try { index.Type=IndexType.GetIndexType(split[1]); } catch(Exception e) { index.Type=IndexTypeEnum.Ordinary; #if DEBUG System.Console.WriteLine(e.StackTrace.ToString()); #endif } else index.Type = IndexTypeEnum.Ordinary; continue; } if (findIndex && indexStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s),IndexSet.PathFlag)) { 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) index.Path = split[1]; else index .Path= ""; continue; } if (findIndex && indexStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s), Config.SourceFlag)) { 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) index.SourceName = split[1]; else index.SourceName = ""; continue; } if (findIndex && indexStart && SupportClass.String.StartsWithNoCase(SupportClass.String.FormatStr(s), IndexSet.CaptionFlag)) { 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) index.Caption = split[1]; else index.Caption = ""; continue; } } return indexList; }
public static Query GetQuery(IndexSet indexSet) { BooleanQuery queryRet = new BooleanQuery(); queryRet.Add(GetFuzzyQuery(indexSet), BooleanClause.Occur.MUST); queryRet.Add(GetExactQuery(), BooleanClause.Occur.MUST); return queryRet; }
private static Query GetFuzzyQuery(IndexSet indexSet, out QueryResult.SearchInfo info) { string[] fields; info = new QueryResult.SearchInfo(); info.IndexName = indexSet.IndexName; if (indexFieldsDict.Count > 0 && indexFieldsDict.ContainsKey(indexSet)) fields = indexFieldsDict[indexSet].ToArray(); else fields = indexDict[indexSet].StringFields.ToArray(); info.Fields.AddRange(fields); string[] wordAllContainArray = SupportClass.String.Split(wordsAllContains); string[] exactPhraseArray = SupportClass.String.Split(exactPhraseContain); string[] oneWordContainArray = SupportClass.String.Split(oneOfWordsAtLeastContain); string[] wordNoIncludeArray = SupportClass.String.Split(wordNotInclude); MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer); BooleanQuery queryRet = new BooleanQuery(); foreach (string words in wordAllContainArray) { List<string> wordList = ISUtils.CSegment.Segment.SegmentStringEx(words); foreach(string word in wordList) { Query query = parser.Parse(word); queryRet.Add(query, BooleanClause.Occur.MUST); } } foreach (string words in exactPhraseArray) { List<string> wordList = ISUtils.CSegment.Segment.SegmentStringEx(words); foreach (string word in wordList) { Query query = parser.Parse(word); queryRet.Add(query, BooleanClause.Occur.MUST); } } foreach (string words in oneWordContainArray) { List<string> wordList = ISUtils.CSegment.Segment.SegmentStringEx(words); foreach(string word in wordList) { Query query = parser.Parse(word); queryRet.Add(query, BooleanClause.Occur.SHOULD); } } foreach (string words in wordNoIncludeArray) { List<string> wordList = ISUtils.CSegment.Segment.SegmentStringEx(words); foreach(string word in wordList) { Query query = parser.Parse(word); queryRet.Add(query, BooleanClause.Occur.MUST_NOT); } } return queryRet; }