/**/ /// <summary> /// 构造函数 /// </summary> /// <param name="DBTypeEnum">合并因子 (mergeFactor)</param> /// <param name="maxBufferedDocs">文档内存最大存储数</param> public DBCreateIndexer(Analyzer analyzer, DBTypeEnum type, string connectString, string directory,string dbName) :base(dbName) { this.analyzer = analyzer; _connectString = connectString; _directory = directory; } /**/ /// <summary> /// 将数据库查询结果写入索引 /// </summary> /// <param name="strSQL">数据库查询语句</param> public override void WriteResults(string strSQL) { DBLinker linker; switch (dbType) { case DBTypeEnum.SQL_Server: linker=new SqlServerLinker(_connectString); break; case DBTypeEnum.OLE_DB: linker = new OleDbLinker(_connectString); break; case DBTypeEnum.ODBC: linker = new OdbcLinker(_connectString); break; case DBTypeEnum.Oracle: linker = new OracleLinker(_connectString); break; default: linker = new SqlServerLinker(_connectString); break; } DataTable dt = linker.ExecuteSQL(strSQL); DbWriterBase writer = new DBCreateIWriter(analyzer,dbName, _directory,int.MaxValue,512,1000,1000); writer.WriteDataTable(dt); linker.Close(); }
public static bool TestQuery(DBTypeEnum dbType, string hostName, string db, string user, string pwd, string query) { string connStr = "", format = ""; DBLinker linker; try { switch (dbType) { case DBTypeEnum.ODBC: format = "Server={0};Database={1};Uid={2};Pwd={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker =new OdbcLinker(connStr); break; case DBTypeEnum.OLE_DB: format = "Server={0};Database={1};Uid={2};Pwd={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new OleDbLinker(connStr); break; case DBTypeEnum.Oracle: format = "host={0};Data source={1};User id={2};Password={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new OracleLinker(connStr); break; case DBTypeEnum.SQL_Server: format = "Data Source={0};Initial Catalog= {1};User Id={2};Password={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new SqlServerLinker(connStr); break; default: format = "Data Source={0};Initial Catalog= {1};User Id={2};Password={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new SqlServerLinker(connStr); break; } DataTable dt = linker.ExecuteSQL(query); int count = dt.Rows.Count; dt.Clear(); linker.Close(); if (count > 0) return true; else return false; } catch (Exception e) { #if DEBUG System.Console.WriteLine(e.StackTrace.ToString()); #endif return false; } }
/**/ /// <summary> /// 将数据库查询结果写入索引 /// </summary> /// <param name="strSQL">数据库查询语句</param> /// <param name="mergeFactor">合并因子 (mergeFactor)</param> /// <param name="maxBufferedDocs">文档内存最大存储数</param> public override void WriteResultsWithEvent(string strSQL, int maxFieldLength, double ramBufferSize, int mergeFactor, int maxBufferedDocs, Dictionary<string, float> fieldBoostDict) { DBLinker linker; switch (dbType) { case DBTypeEnum.SQL_Server: linker = new SqlServerLinker(_connectString); break; case DBTypeEnum.OLE_DB: linker = new OleDbLinker(_connectString); break; case DBTypeEnum.ODBC: linker = new OdbcLinker(_connectString); break; case DBTypeEnum.Oracle: linker = new OracleLinker(_connectString); break; default: linker = new SqlServerLinker(_connectString); break; } DataTable dt = linker.ExecuteSQL(strSQL); DbWriterBase writer = new DBCreateIWriter(analyzer,dbName, _directory, maxFieldLength, ramBufferSize, mergeFactor, maxBufferedDocs); writer.OnProgressChanged += new WriteDbProgressChangedEventHandler(Writer_OnProgressChanged); writer.WriteDataTableWithEvent(dt,fieldBoostDict); linker.Close(); IndexCompletedEventArgs args = new IndexCompletedEventArgs("CreateIndex"); OnIndexCompletedEvent(this, args); } /**/ /// <summary> /// 将数据库查询结果写入索引 /// </summary> /// <param name="strSQL">数据库查询语句</param> /// <param name="mergeFactor">合并因子 (mergeFactor)</param> /// <param name="maxBufferedDocs">文档内存最大存储数</param> public override void WriteResultsWithEvent(string strSQL, int maxFieldLength, double ramBufferSize, int mergeFactor, int maxBufferedDocs) { DBLinker linker; switch (dbType) { case DBTypeEnum.SQL_Server: linker = new SqlServerLinker(_connectString); break; case DBTypeEnum.OLE_DB: linker = new OleDbLinker(_connectString); break; case DBTypeEnum.ODBC: linker = new OdbcLinker(_connectString); break; case DBTypeEnum.Oracle: linker = new OracleLinker(_connectString); break; default: linker = new SqlServerLinker(_connectString); break; } DataTable dt = linker.ExecuteSQL(strSQL); DbWriterBase writer = new DBCreateIWriter(analyzer,dbName, _directory, maxFieldLength, ramBufferSize, mergeFactor, maxBufferedDocs); writer.OnProgressChanged += new WriteDbProgressChangedEventHandler(Writer_OnProgressChanged); writer.WriteDataTableWithEvent(dt); linker.Close(); IndexCompletedEventArgs args = new IndexCompletedEventArgs("CreateIndex"); OnIndexCompletedEvent(this, args); }
/**/ /// <summary> /// 将数据库查询结果写入索引 /// </summary> /// <param name="strSQL">数据库查询语句</param> /// <param name="mergeFactor">合并因子 (mergeFactor)</param> /// <param name="maxBufferedDocs">文档内存最大存储数</param> public override void WriteResults(string strSQL, int maxFieldLength, double ramBufferSize, int mergeFactor, int maxBufferedDocs) { DBLinker linker; switch (dbType) { case DBTypeEnum.SQL_Server: linker=new SqlServerLinker(_connectString); break; case DBTypeEnum.OLE_DB: linker = new OleDbLinker(_connectString); break; case DBTypeEnum.ODBC: linker = new OdbcLinker(_connectString); break; case DBTypeEnum.Oracle: linker = new OracleLinker(_connectString); break; default: linker = new SqlServerLinker(_connectString); break; } DataTable dt = linker.ExecuteSQL(strSQL); DbWriterBase writer = new DBCreateIWriter(analyzer,dbName, _directory,maxFieldLength,ramBufferSize,mergeFactor,maxBufferedDocs); writer.WriteDataTable(dt); linker.Close(); } /**/ /// <summary> /// 将数据库查询结果写入索引 /// </summary> /// <param name="strSQL">数据库查询语句</param> /// <param name="mergeFactor">合并因子 (mergeFactor)</param> /// <param name="maxBufferedDocs">文档内存最大存储数</param> public override void WriteResults(string strSQL, int maxFieldLength, double ramBufferSize, int mergeFactor, int maxBufferedDocs, Dictionary<string, float> fieldBoostDict) { DBLinker linker; switch (dbType) { case DBTypeEnum.SQL_Server: linker = new SqlServerLinker(_connectString); break; case DBTypeEnum.OLE_DB: linker = new OleDbLinker(_connectString); break; case DBTypeEnum.ODBC: linker = new OdbcLinker(_connectString); break; case DBTypeEnum.Oracle: linker = new OracleLinker(_connectString); break; default: linker = new SqlServerLinker(_connectString); break; } DataTable dt = linker.ExecuteSQL(strSQL); DbWriterBase writer = new DBCreateIWriter(analyzer,dbName, _directory, maxFieldLength, ramBufferSize, mergeFactor, maxBufferedDocs); writer.WriteDataTable(dt,fieldBoostDict); linker.Close(); }
public static Dictionary<string, List<FieldInfo>> GetQueryTableFields(DBTypeEnum dbType, string connStr, string query) { Dictionary<string, List<FieldInfo>> tableFieldDict = new Dictionary<string, List<FieldInfo>>(); DBLinker linker; try { switch (dbType) { case DBTypeEnum.ODBC: linker = new OdbcLinker(connStr); break; case DBTypeEnum.OLE_DB: linker = new OleDbLinker(connStr); break; case DBTypeEnum.Oracle: linker = new OracleLinker(connStr); break; case DBTypeEnum.SQL_Server: linker = new SqlServerLinker(connStr); break; default: linker = new SqlServerLinker(connStr); break; } List<string> tableList = SupportClass.QueryParser.TablesInQuery(query); foreach (string table in tableList) { DataTable dt = linker.ExecuteSQL(SupportClass.QueryParser.TopOneOfTable(table)); List<FieldInfo> fieldList = new List<FieldInfo>(); foreach (DataColumn column in dt.Columns) { fieldList.Add(new FieldInfo(column.ColumnName,column.DataType,column.Unique)); } if (tableFieldDict.ContainsKey(table) == false) tableFieldDict.Add(table, fieldList); dt.Clear(); } linker.Close(); } catch (Exception e) { #if DEBUG System.Console.WriteLine(e.StackTrace.ToString()); #endif } return tableFieldDict; }
public static bool TestFields(DBTypeEnum dbType, string hostName, string db, string user, string pwd, string query,string fields) { string connStr = "", format = ""; DBLinker linker; try { switch (dbType) { case DBTypeEnum.ODBC: format = "Server={0};Database={1};Uid={2};Pwd={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new OdbcLinker(connStr); break; case DBTypeEnum.OLE_DB: format = "Server={0};Database={1};Uid={2};Pwd={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new OleDbLinker(connStr); break; case DBTypeEnum.Oracle: format = "host={0};Data source={1};User id={2};Password={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new OracleLinker(connStr); break; case DBTypeEnum.SQL_Server: format = "Data Source={0};Initial Catalog= {1};User Id={2};Password={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new SqlServerLinker(connStr); break; default: format = "Data Source={0};Initial Catalog= {1};User Id={2};Password={3};"; connStr = string.Format(format, hostName, db, user, pwd); linker = new SqlServerLinker(connStr); break; } DataTable dt = linker.ExecuteSQL(query); int count = dt.Rows.Count; if (count < 0) { dt.Clear(); linker.Close(); return false; } List<IndexField> fpList = new List<IndexField>(); if (fields.IndexOf(')') > 0) { string[] split = SupportClass.String.Split(fields, ")"); foreach (string token in split) fpList.Add(new IndexField(token)); } else { string[] split = SupportClass.String.Split(fields, ","); foreach (string token in split) fpList.Add(new IndexField(token)); } bool find; foreach (IndexField fp in fpList) { find = false; foreach(DataColumn column in dt.Columns) { if(column.ColumnName.ToLower().CompareTo(fp.Name.ToLower())==0) { find = true; break; } } if (!find) { dt.Clear(); linker.Close(); return false; } } dt.Clear(); linker.Close(); return true; } catch (Exception e) { #if DEBUG System.Console.WriteLine(e.StackTrace.ToString()); #endif return false; } }