Beispiel #1
0
        private void GetAnalyzerName(HubbleConnection conn, string tableName)
        {
            if (titleAnalyzerName != null && descAnalyzerName != null)
            {
                return;
            }

            string sql = string.Format("exec SP_Columns '{0}'", tableName.Replace("'", "''"));

            HubbleCommand cmd = new HubbleCommand(sql, conn);

            foreach (System.Data.DataRow row in cmd.Query().Tables[0].Rows)
            {
                if (row["FieldName"].ToString().Equals("Title", StringComparison.CurrentCultureIgnoreCase))
                {
                    titleAnalyzerName = row["Analyzer"].ToString();
                }

                if (row["FieldName"].ToString().Equals("Description", StringComparison.CurrentCultureIgnoreCase))
                {
                    descAnalyzerName = row["Analyzer"].ToString();
                }
            }

        }
Beispiel #2
0
        public void Connect(string serverName)
        {
            ServerName = serverName;

            try
            {
                string settingFile = Hubble.Framework.IO.Path.AppendDivision(serverName, '\\') +
                                     Hubble.Core.Global.Setting.FileName;

                if (!System.IO.File.Exists(settingFile))
                {
                    _SettingPath = null;
                }
                else
                {
                    _SettingPath = System.IO.Path.GetDirectoryName(settingFile);
                }
            }
            catch
            {
                _SettingPath = null;
            }

            if (_SettingPath != null)
            {
                Hubble.Core.Global.Setting.SettingPath = _SettingPath;
                Hubble.Core.Service.CurrentConnection.Connect();
                Hubble.Core.Service.CurrentConnection curConnection = new Hubble.Core.Service.CurrentConnection(
                    new Hubble.Core.Service.ConnectionInformation(DatabaseName));

                string currentDirectory = Environment.CurrentDirectory;

                Environment.CurrentDirectory = _SettingPath;

                try
                {
                    DBProvider.Init(_SettingPath);
                }
                finally
                {
                    Environment.CurrentDirectory = currentDirectory;
                }
            }
            else
            {
                System.Data.SqlClient.SqlConnectionStringBuilder sqlConnBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder();
                sqlConnBuilder.DataSource     = serverName;
                sqlConnBuilder.InitialCatalog = DatabaseName;
                _Conn = new HubbleConnection(sqlConnBuilder.ConnectionString);
                _Conn.Open();
            }
        }
Beispiel #3
0
        /// <summary>
        /// 搜索可能喜欢的文档
        /// </summary>  
        /// <param name="pageNo"></param>
        /// <param name="pageLen"></param>
        /// <returns></returns>
        public ArrayList SearchMaybeLike(string title, int pageNo, int pageLen,int docId)
        {
            string connStr = Helper.ConfigHelper.HubbleConnStr;            
            DataSet ds;
            ArrayList rList = new ArrayList();
            using (HubbleConnection conn = new HubbleConnection(connStr))
            {
                #region hubble
                conn.Open();
                GetAnalyzerName(conn, TableName);
                string wordssplitbyspace;
                HubbleCommand matchCmd = new HubbleCommand(conn);

                string matchString = matchCmd.GetKeywordAnalyzerStringFromServer(
                    TableName, "Title", title, int.MaxValue, out wordssplitbyspace);

                HubbleDataAdapter da = new HubbleDataAdapter();
                da.SelectCommand = new HubbleCommand(
                    string.Format(
                        "select between @begin to @end * from {0} where IsAudit=1 and ( Description match @matchString or title^2 match @matchString or tags^2 match @matchString ) "
                        + " and DocumentId<>@docid order by score desc"
                        , TableName),
                        conn);
                da.SelectCommand.Parameters.Add("@begin", pageNo * pageLen);
                da.SelectCommand.Parameters.Add("@end", (pageNo + 1) * pageLen - 1);
                da.SelectCommand.Parameters.Add("@matchString", matchString);
                da.SelectCommand.Parameters.Add("@docid",docId);

                da.SelectCommand.CacheTimeout = 0;

                ds = new DataSet();
                HubbleCommand cmd = da.SelectCommand;
                ds = cmd.Query(0);

                long[] docids = new long[ds.Tables[0].Rows.Count];

                int i = 0;

                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    docids[i++] = (long)row["DocId"];
                }

                rList.AddRange(DataToList(ds, title, false));
                
                #endregion
            }
               
            
            return rList;
        }
Beispiel #4
0
        public DataContext(HubbleConnection conn)
        {
            if (conn == null)
            {
                throw new ArgumentException("Conn can't be NULL.");
            }

            _Conn = conn;

            if (!_Conn.Connected)
            {
                _Conn.Open();
            }
        }
Beispiel #5
0
        private string descAnalyzerName; //描述分析器名称

        public ArrayList Search(string keyWords, int pageNo, int pageLen, out int recCount, out long elapsedMilliseconds)
        {
            string connStr = Helper.ConfigHelper.HubbleConnStr;
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            DataSet ds;
            using (HubbleConnection conn = new HubbleConnection(connStr))
            {
                #region hubble
                conn.Open();
                GetAnalyzerName(conn, TableName);
                string wordssplitbyspace;
                HubbleCommand matchCmd = new HubbleCommand(conn);
                string matchString = matchCmd.GetKeywordAnalyzerStringFromServer(
                    TableName, "Title", keyWords, int.MaxValue, out wordssplitbyspace);
                HubbleDataAdapter da = new HubbleDataAdapter();
                string sqlTemplate = string.Empty;
                if (string.IsNullOrEmpty(this.DocType))
                    sqlTemplate = "select between @begin to @end * from {0} where IsAudit=1 and ( Description match @matchString or title^2 match @matchString or tags^2 match @matchString ) order by score desc";
                else
                    sqlTemplate = "select between @begin to @end * from {0} where IsAudit=1 and DocType='" + this.DocType + "' and ( Description match @matchString or title^2 match @matchString or tags^2 match @matchString ) order by score desc";
                
                da.SelectCommand = new HubbleCommand( string.Format(sqlTemplate,TableName),conn);
                da.SelectCommand.Parameters.Add("@begin",pageNo * pageLen);
                da.SelectCommand.Parameters.Add("@end", (pageNo+1) * pageLen - 1);
                da.SelectCommand.Parameters.Add("@matchString", matchString);
                

                da.SelectCommand.CacheTimeout = 0;

                ds = new DataSet();
                HubbleCommand cmd = da.SelectCommand;
                ds = cmd.Query(0);

                long[] docids = new long[ds.Tables[0].Rows.Count];

                int i = 0;

                //foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                //{
                //    docids[i++] = (long)row["DocumentId"];
                //}
                #endregion
            }
            recCount = ds.Tables[0].MinimumCapacity;
            ArrayList rList = DataToList(ds, keyWords,true);
            watch.Stop();
            elapsedMilliseconds = watch.ElapsedMilliseconds;
            return rList;
        }
Beispiel #6
0
        /// <summary>获取数据
        /// 全文搜索方法 获取数据
        /// </summary>
        /// <param name="conStr">hubble服务连接字符串</param>
        /// <param name="sql">查询sql语句 注意这里是T-SFQL语句 不是T-SQL语句</param>
        /// <param name="_paras">参数列表</param>
        /// <returns>返回数据集</returns>
        public DataTable GetDataTable(string conStr, string sql, params object[] _paras)
        {
            DataTable table = null;
            DataSet   set   = null;

            //获取使用分词的名称
            using (HubbleConnection hubbleCon = getAsyncConnect(conStr))
            {
                hubbleCon.Open();
                //打开链接
                try
                {
                    if (hubbleCon.State == ConnectionState.Closed)
                    {
                        hubbleCon.Open();
                    }
                    HubbleCommand hubbleCommand = new HubbleCommand(hubbleCon);
                    //适配器对象
                    HubbleDataAdapter adapter = new HubbleDataAdapter();
                    /*添加分页参数*/
                    adapter.SelectCommand = new HubbleCommand(sql, hubbleCon);
                    /*添加用户传递的参数*/
                    if (_paras != null)
                    {
                        for (int i = 0; i < _paras.Length; i += 2)
                        {
                            adapter.SelectCommand.Parameters.Add(_paras[i].ToString(), _paras[i + 1]);
                        }
                    }
                    hubbleCommand = adapter.SelectCommand;
                    set           = hubbleCommand.Query(this._cacheTimeout);
                }
                catch (Exception e)
                {
                    throw;
                }
                hubbleCon.Close();
            }
            if (set != null && set.Tables.Count == 1)
            {
                table = set.Tables[0];
            }

            return(table);
        }
Beispiel #7
0
 /// <summary>
 /// 重载,创建一个Hubble命令实例
 /// </summary>
 /// <returns></returns>
 private HubbleCommand CreateHubbleCommand()
 {
     HubbleConnection connection = new HubbleConnection(ConnectionString);
     HubbleCommand command = new HubbleCommand(connection);
     return command;
 }
Beispiel #8
0
        private void GetAnalyzerName(HubbleConnection conn, string tableName)
        {
            if (titleAnalyzerName != null && descAnalyzerName != null)
            {
                return;
            }

            string sql = string.Format("exec SP_Columns '{0}'", tableName.Replace("'", "''"));

            HubbleCommand cmd = new HubbleCommand(sql, conn);

            foreach (System.Data.DataRow row in cmd.Query().Tables[0].Rows)
            {
                if (row["FieldName"].ToString().Equals("Title", StringComparison.CurrentCultureIgnoreCase))
                {
                    titleAnalyzerName = row["Analyzer"].ToString();
                }

                if (row["FieldName"].ToString().Equals("Description", StringComparison.CurrentCultureIgnoreCase))
                {
                    descAnalyzerName = row["Analyzer"].ToString();
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 搜索可能喜欢的文档
        /// </summary>  
        /// <param name="pageNo"></param>
        /// <param name="pageLen"></param>
        /// <returns></returns>
        public ArrayList SearchMaybeLike(string title, int pageNo, int pageLen,int docId)
        {
            string connStr = Helper.ConfigHelper.HubbleConnStr;
            DataSet ds;
            ArrayList rList = new ArrayList();
            using (HubbleConnection conn = new HubbleConnection(connStr))
            {
                #region hubble
                conn.Open();
                GetAnalyzerName(conn, TableName);
                string wordssplitbyspace;
                HubbleCommand matchCmd = new HubbleCommand(conn);

                string matchString = matchCmd.GetKeywordAnalyzerStringFromServer(
                    TableName, "Title", title, int.MaxValue, out wordssplitbyspace);

                HubbleDataAdapter da = new HubbleDataAdapter();
                da.SelectCommand = new HubbleCommand(
                    string.Format(
                        "select between @begin to @end * from {0} where IsAudit=1 and ( Description match @matchString or title^2 match @matchString or tags^2 match @matchString ) "
                        + " and DocumentId<>@docid order by score desc"
                        , TableName),
                        conn);
                da.SelectCommand.Parameters.Add("@begin", pageNo * pageLen);
                da.SelectCommand.Parameters.Add("@end", (pageNo + 1) * pageLen - 1);
                da.SelectCommand.Parameters.Add("@matchString", matchString);
                da.SelectCommand.Parameters.Add("@docid",docId);

                da.SelectCommand.CacheTimeout = 0;

                ds = new DataSet();
                HubbleCommand cmd = da.SelectCommand;
                ds = cmd.Query(0);

                long[] docids = new long[ds.Tables[0].Rows.Count];

                int i = 0;

                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    docids[i++] = (long)row["DocId"];
                }

                rList.AddRange(DataToList(ds, title, false));

                #endregion
            }

            return rList;
        }
Beispiel #10
0
        public ArrayList Search(string keyWords, int pageNo, int pageLen, out int recCount, out long elapsedMilliseconds)
        {
            string connStr = Helper.ConfigHelper.HubbleConnStr;
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            DataSet ds;
            using (HubbleConnection conn = new HubbleConnection(connStr))
            {
                #region hubble
                conn.Open();
                GetAnalyzerName(conn, TableName);
                string wordssplitbyspace;
                HubbleCommand matchCmd = new HubbleCommand(conn);
                string matchString = matchCmd.GetKeywordAnalyzerStringFromServer(
                    TableName, "Title", keyWords, int.MaxValue, out wordssplitbyspace);
                HubbleDataAdapter da = new HubbleDataAdapter();
                string sqlTemplate = string.Empty;
                if (string.IsNullOrEmpty(this.DocType))
                    sqlTemplate = "select between @begin to @end * from {0} where IsAudit=1 and ( Description match @matchString or title^2 match @matchString or tags^2 match @matchString ) order by score desc";
                else
                    sqlTemplate = "select between @begin to @end * from {0} where IsAudit=1 and DocType='" + this.DocType + "' and ( Description match @matchString or title^2 match @matchString or tags^2 match @matchString ) order by score desc";

                da.SelectCommand = new HubbleCommand( string.Format(sqlTemplate,TableName),conn);
                da.SelectCommand.Parameters.Add("@begin",pageNo * pageLen);
                da.SelectCommand.Parameters.Add("@end", (pageNo+1) * pageLen - 1);
                da.SelectCommand.Parameters.Add("@matchString", matchString);

                da.SelectCommand.CacheTimeout = 0;

                ds = new DataSet();
                HubbleCommand cmd = da.SelectCommand;
                ds = cmd.Query(0);

                long[] docids = new long[ds.Tables[0].Rows.Count];

                int i = 0;

                //foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                //{
                //    docids[i++] = (long)row["DocumentId"];
                //}
                #endregion
            }
            recCount = ds.Tables[0].MinimumCapacity;
            ArrayList rList = DataToList(ds, keyWords,true);
            watch.Stop();
            elapsedMilliseconds = watch.ElapsedMilliseconds;
            return rList;
        }
Beispiel #11
0
 public SPDataContext(HubbleConnection conn)
     : base(conn)
 {
 }