HubbleDotNet 使用类

HubbleDotNet 使用类

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Hubble.SQLClient;

using System.Configuration;

using RJ.Entity.UI_A;

using System.Data;

using Hubble.Core.Analysis.HighLight;

using Hubble.Analyzer;

using RJ.DBConnection;

using RJ.DALS.UI_A;

using RJ.Common;

using RJ.Entity.UI_A.AboutRJ;

namespace RJ.DAL.UI_A

{

public class DHubble : UI_A_DALBaseClass

{

private static string _TitleAnalyzerName = null;

private static string _ContentAnalyzerName = null;

private const int CacheTimeout = 0; //In seconds

public static void GetAnalyzerName(HubbleAsyncConnection conn, string tableName)

{

if (_TitleAnalyzerName != null && _ContentAnalyzerName != 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("Content", StringComparison.CurrentCultureIgnoreCase))

{

_ContentAnalyzerName = row["Analyzer"].ToString();

}

}

}

/// <summary>

/// 搜索列表

/// </summary>

/// <param name="pageindex"></param>

/// <param name="pagesize"></param>

/// <param name="key"></param>

/// <param name="Count"></param>

/// <returns></returns>

public List<EArticle> SearchKnowList(int pageindex, int pagesize, string key, out int Count)

{

string strConn = ConfigurationManager.ConnectionStrings["Search"].ToString();

DataSet ds = new DataSet();

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

sw.Start();

using (HubbleAsyncConnection conn = new HubbleAsyncConnection(strConn))

{

conn.Open();

GetAnalyzerName(conn, "KnowSearch");

string wordssplitbyspace;

HubbleCommand matchCmd = new HubbleCommand(conn);

string matchString = matchCmd.GetKeywordAnalyzerStringFromServer("KnowSearch",

"documentname", (key.Split('_')[0]).ToString(), int.MaxValue, out wordssplitbyspace);

HubbleDataAdapter adapter = new HubbleDataAdapter();

//if (key.Split('_')[1] == "1")

//{

// adapter.SelectCommand = new HubbleCommand("select between @begin to @end * from KnowSearch where ( documentname Contains @matchString or documentname match @matchString ) order by score desc",

// conn);

//}

//else if (key.Split('_')[1] == "2")

//{

// adapter.SelectCommand = new HubbleCommand("select between @begin to @end ID,UNIID,DocumentName,publishTime from KnowSearch where ( documentname Contains @matchString or documentname match @matchString ) order by publishTime desc",

// conn);

//}

//else

//{

adapter.SelectCommand = new HubbleCommand("select between @begin to @end ID,UNIID,DocumentName,publishTime from KnowSearch where ( documentname Contains @matchString or documentname match @matchString ) order by score desc,publishTime desc",

conn);

//}

adapter.SelectCommand.Parameters.Add("@begin", (pagesize - 1) * pageindex);

adapter.SelectCommand.Parameters.Add("@end", pagesize * pageindex - 1);

adapter.SelectCommand.Parameters.Add("@matchString", matchString);

adapter.SelectCommand.CacheTimeout = CacheTimeout;

ds = new System.Data.DataSet();

//adapter.Fill(ds);

HubbleCommand cmd = adapter.SelectCommand;

ds = cmd.Query(CacheTimeout);

//titleWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Title", docids, int.MaxValue);

//contentWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Content", docids, int.MaxValue);

}

Count = ds.Tables[0].MinimumCapacity;

List<EArticle> result = new List<EArticle>();

foreach (System.Data.DataRow row in ds.Tables[0].Rows)

{

EArticle document = new EArticle();

document.ID = int.Parse(row["ID"].ToString());

document.UNIID = row["UNIID"].ToString();

document.Name = row["DocumentName"].ToString();

if (!string.IsNullOrEmpty(row["publishTime"].ToString().Trim()))

{

document.PublishTime = Convert.ToDateTime(row["publishTime"].ToString());

}

else

{

document.PublishTime = Convert.ToDateTime("9999-12-31");

}

SimpleHTMLFormatter simpleHTMLFormatter =

new SimpleHTMLFormatter("<font color=\"red\">", "</font>");

Highlighter titleHighlighter;

Highlighter contentHighlighter;

titleHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

contentHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

titleHighlighter.FragmentSize = 100;

contentHighlighter.FragmentSize = 100;

string lightname = titleHighlighter.GetBestFragment((key.Split('_')[0]).ToString(), document.Name);

if (string.IsNullOrEmpty(lightname))

{

document.TitleHighLighter = document.Name;

}

else

{

document.TitleHighLighter = lightname;

}

result.Add(document);

}

sw.Stop();

return result;

}

/// <summary>

/// 文档搜索列表

/// </summary>

/// <param name="pageindex"></param>

/// <param name="pagesize"></param>

/// <param name="key"></param>

/// <param name="Count"></param>

/// <returns></returns>

public List<EArticle> SearchDocList(int pageindex, int pagesize, string key, string isLevel, out int Count)

{

string strConn = ConfigurationManager.ConnectionStrings["Search"].ToString();

DataSet ds = new DataSet();

//string sql = "select * from News where Title match '" + key + "'";

//ds = SQLHelper.ExecuteDataset(strConn, CommandType.Text, sql, null);

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

sw.Start();

using (HubbleAsyncConnection conn = new HubbleAsyncConnection(strConn))

{

conn.Open();

GetAnalyzerName(conn, "DocumentSearch");

string wordssplitbyspace;

HubbleCommand matchCmd = new HubbleCommand(conn);

string matchString = matchCmd.GetKeywordAnalyzerStringFromServer("DocumentSearch",

"documentname", key, int.MaxValue, out wordssplitbyspace);

HubbleDataAdapter adapter = new HubbleDataAdapter();

StringBuilder strSql = new StringBuilder();

string[] levelPara;

if (string.IsNullOrEmpty(isLevel))

{

strSql.Append("select between @begin to @end id,UNIID,documentname,htmlurl,publishtime,addtime,SEO_D,PDF from DocumentSearch where ( documentname Contains @matchString or Content Contains @matchString or documentname match @matchString or Content match @matchString ) and VisitLevel ='' and release='true' order by score desc");

}

else

{

levelPara = isLevel.Split(',');

strSql.Append("select between @begin to @end id,UNIID,documentname,htmlurl,publishtime,addtime,SEO_D,PDF from DocumentSearch where ( documentname Contains @matchString or Content Contains @matchString or documentname match @matchString or Content match @matchString ) and (");

for (int i = 0; i < levelPara.Length; i++)

{

strSql.Append(" VisitLevel=@VisitLevel" + i + " or ");

}

strSql.Remove(strSql.Length - 3, 2);

strSql.Append(" or VisitLevel='') and release='true' order by score desc");

}

adapter.SelectCommand = new HubbleCommand(strSql.ToString(), conn);

adapter.SelectCommand.Parameters.Add("@begin", (pagesize - 1) * pageindex);

adapter.SelectCommand.Parameters.Add("@end", pagesize * pageindex - 1);

adapter.SelectCommand.Parameters.Add("@matchString", matchString);

if (!string.IsNullOrEmpty(isLevel))

{

for (int i = 0; i < isLevel.Split(',').Length; i++)

{

adapter.SelectCommand.Parameters.Add("@VisitLevel" + i, isLevel.Split(',')[i].Replace("'", ""));

}

}

adapter.SelectCommand.CacheTimeout = CacheTimeout;

ds = new System.Data.DataSet();

//adapter.Fill(ds);

HubbleCommand cmd = adapter.SelectCommand;

ds = cmd.Query(CacheTimeout);

//titleWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Title", docids, int.MaxValue);

//contentWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Content", docids, int.MaxValue);

}

Count = ds.Tables[0].MinimumCapacity;

List<EArticle> result = new List<EArticle>();

foreach (System.Data.DataRow row in ds.Tables[0].Rows)

{

EArticle document = new EArticle();

document.ID = int.Parse(row["ID"].ToString());

document.UNIID = row["UNIID"].ToString();

document.Name = row["DocumentName"].ToString();

document.htmlURL = row["htmlURL"].ToString();

document.SEO_D = row["SEO_D"].ToString();

document.PDF = row["PDF"].ToString();

if (!string.IsNullOrEmpty(row["publishTime"].ToString().Trim()))

{

document.PublishTime = Convert.ToDateTime(row["publishTime"].ToString());

}

else

{

document.PublishTime = Convert.ToDateTime(row["AddTime"].ToString());

}

SimpleHTMLFormatter simpleHTMLFormatter =

new SimpleHTMLFormatter("<font color=\"red\">", "</font>");

Highlighter titleHighlighter;

Highlighter contentHighlighter;

titleHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

contentHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

titleHighlighter.FragmentSize = 100;

contentHighlighter.FragmentSize = 100;

string lightname = titleHighlighter.GetBestFragment(key, document.Name);

if (string.IsNullOrEmpty(lightname))

{

document.TitleHighLighter = document.Name;

}

else

{

document.TitleHighLighter = lightname;

}

result.Add(document);

}

sw.Stop();

return result;

}

/// <summary>

/// 软件搜索列表

/// </summary>

/// <param name="pageindex"></param>

/// <param name="pagesize"></param>

/// <param name="key"></param>

/// <param name="Count"></param>

/// <returns></returns>

public List<EArticle> SearchSoftWareList(int pageindex, int pagesize, string key, string isLevel, out int Count)

{

string strConn = ConfigurationManager.ConnectionStrings["Search"].ToString();

DataSet ds = new DataSet();

//string sql = "select * from News where Title match '" + key + "'";

//ds = SQLHelper.ExecuteDataset(strConn, CommandType.Text, sql, null);

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

sw.Start();

using (HubbleAsyncConnection conn = new HubbleAsyncConnection(strConn))

{

conn.Open();

GetAnalyzerName(conn, "SoftwareSearch");

string wordssplitbyspace;

HubbleCommand matchCmd = new HubbleCommand(conn);

string matchString = matchCmd.GetKeywordAnalyzerStringFromServer("SoftwareSearch",

"DocumentName", key, int.MaxValue, out wordssplitbyspace);

HubbleDataAdapter adapter = new HubbleDataAdapter();

StringBuilder strSql = new StringBuilder();

string[] levelPara;

if (string.IsNullOrEmpty(isLevel))

{

strSql.Append("select between @begin to @end id,documentname,publishtime,addtime,UNIID,IsCheckPartner from SoftwareSearch where (DocumentName Contains @matchString or DocumentName match @matchString) and (VisitLevel ='' or visitlevel='JingBiaoLevel') and release='true' order by score desc");

}

else

{

levelPara = isLevel.Split(',');

strSql.Append("select between @begin to @end id,documentname,publishtime,addtime,UNIID,IsCheckPartner from SoftwareSearch where (DocumentName Contains @matchString or DocumentName match @matchString) and (");

for (int i = 0; i < levelPara.Length; i++)

{

strSql.Append(" VisitLevel=@VisitLevel" + i + " or ");

}

strSql.Remove(strSql.Length - 3, 2);

strSql.Append(" or VisitLevel='' or visitlevel='JingBiaoLevel') and release='true' order by score desc");

}

adapter.SelectCommand = new HubbleCommand(strSql.ToString(), conn);

adapter.SelectCommand.Parameters.Add("@begin", (pagesize - 1) * pageindex);

adapter.SelectCommand.Parameters.Add("@end", pagesize * pageindex - 1);

adapter.SelectCommand.Parameters.Add("@matchString", matchString);

if (!string.IsNullOrEmpty(isLevel))

{

for (int i = 0; i < isLevel.Split(',').Length; i++)

{

adapter.SelectCommand.Parameters.Add("@VisitLevel" + i, isLevel.Split(',')[i].Replace("'", ""));

}

}

adapter.SelectCommand.CacheTimeout = CacheTimeout;

ds = new System.Data.DataSet();

//adapter.Fill(ds);

HubbleCommand cmd = adapter.SelectCommand;

ds = cmd.Query(CacheTimeout);

//titleWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Title", docids, int.MaxValue);

//contentWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Content", docids, int.MaxValue);

}

Count = ds.Tables[0].MinimumCapacity;

List<EArticle> result = new List<EArticle>();

foreach (System.Data.DataRow row in ds.Tables[0].Rows)

{

EArticle software = new EArticle();

software.ID = int.Parse(row["ID"].ToString());

software.Name = row["DocumentName"].ToString();

software.UpdateTime = Convert.ToDateTime(row["AddTime"].ToString());

software.UNIID = row["UNIID"].ToString();

software.IsCheckPartner = Convert.ToBoolean(row["IsCheckPartner"]);

if (!string.IsNullOrEmpty(row["publishTime"].ToString().Trim()))

{

software.PublishTime = Convert.ToDateTime(row["publishTime"].ToString());

}

else

{

software.PublishTime = Convert.ToDateTime(row["Addtime"].ToString());

}

SimpleHTMLFormatter simpleHTMLFormatter =

new SimpleHTMLFormatter("<font color=\"red\">", "</font>");

Highlighter titleHighlighter;

Highlighter contentHighlighter;

titleHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

contentHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

titleHighlighter.FragmentSize = 100;

contentHighlighter.FragmentSize = 100;

software.TitleHighLighter = titleHighlighter.GetBestFragment(key, software.Name);

if (string.IsNullOrEmpty(software.TitleHighLighter))

{

software.TitleHighLighter = software.Name;

}

result.Add(software);

}

sw.Stop();

return result;

}

/// <summary>

///全站搜索

/// </summary>

/// <param name="pageindex"></param>

/// <param name="pagesize"></param>

/// <param name="key"></param>

/// <param name="Count"></param>

/// <returns></returns>

public List<ESearch> SearchAllList(int pagesize, int pageindex, string key, string isLevel, int typeid, out int Count, out DataTable dtcount)

{

string strConn = ConfigurationManager.ConnectionStrings["Search"].ToString();

DataSet ds = new DataSet();

using (HubbleAsyncConnection conn = new HubbleAsyncConnection(strConn))

{

conn.Open();

GetAnalyzerName(conn, "WholeSearch_CN");

string wordssplitbyspace;

HubbleCommand matchCmd = new HubbleCommand(conn);

string matchString = matchCmd.GetKeywordAnalyzerStringFromServer("WholeSearch_CN",

"Name", key, int.MaxValue, out wordssplitbyspace);

HubbleDataAdapter adapter = new HubbleDataAdapter();

StringBuilder strSql = new StringBuilder();

string[] levelPara;

strSql.Append(" select ");

if (pagesize != 0)

{

strSql.Append(" between @begin to @end ID,Name,TypeID,SEO_D,TypeName,strURL,addTime from ");

}

strSql.Append(" WholeSearch_CN where ( Name Contains @matchString or Name Match @matchString or SEO_D Contains @matchString or SEO_D Match @matchString) ");

if (string.IsNullOrEmpty(isLevel))

{

strSql.Append(" and (VisitLevel ='' or visitlevel='JingBiaoLevel')");

}

else

{

levelPara = isLevel.Split(',');

strSql.Append(" and (");

for (int i = 0; i < levelPara.Length; i++)

{

strSql.Append(" VisitLevel=@VisitLevel" + i + " or ");

}

strSql.Remove(strSql.Length - 3, 2);

strSql.Append(" or VisitLevel='' or visitlevel='JingBiaoLevel') ");

}

if (typeid > 0)

{

strSql.Append(" and typeid=@typeid");

}

else

{

strSql.Insert(0, " [GroupBy('Count', 'ID', 'TypeID', 10)] ");

}

strSql.Append(" order by score desc, lorder");

adapter.SelectCommand = new HubbleCommand(strSql.ToString(), conn);

adapter.SelectCommand.Parameters.Add("@begin", (pageindex - 1) * pagesize);

adapter.SelectCommand.Parameters.Add("@end", pageindex * pagesize - 1);

adapter.SelectCommand.Parameters.Add("@matchString", matchString);

adapter.SelectCommand.Parameters.Add("@typeid", typeid);

if (!string.IsNullOrEmpty(isLevel))

{

for (int i = 0; i < isLevel.Split(',').Length; i++)

{

adapter.SelectCommand.Parameters.Add("@VisitLevel" + i, isLevel.Split(',')[i].Replace("'", ""));

}

}

adapter.SelectCommand.CacheTimeout = CacheTimeout;

ds = new System.Data.DataSet();

//adapter.Fill(ds);

HubbleCommand cmd = adapter.SelectCommand;

ds = cmd.Query(CacheTimeout);

//titleWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Title", docids, int.MaxValue);

//contentWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Content", docids, int.MaxValue);

}

Count = ds.Tables[0].MinimumCapacity;

if (ds.Tables.Count > 1)

{

dtcount = ds.Tables[1];

}

else

{

dtcount = null;

}

List<ESearch> result = new List<ESearch>();

foreach (System.Data.DataRow row in ds.Tables[0].Rows)

{

ESearch search = new ESearch();

search.ID = int.Parse(row["ID"].ToString());

//search.UNIID = new Guid(row["UNIID"].ToString());

search.Name = Strings.NoHTML(row["Name"].ToString());

search.SEO_D = row["SEO_D"].ToString();

search.strURL = row["strURL"].ToString();

if (row["TypeID"].ToString() != "")

{

search.TypeID = int.Parse(row["TypeID"].ToString());

search.TypeName = row["TypeName"].ToString();

}

if (!string.IsNullOrEmpty(row["addTime"].ToString().Trim()))

{

search.addTime = Convert.ToDateTime(row["addTime"].ToString());

}

else

{

search.addTime = Convert.ToDateTime("9999-12-31");

}

SimpleHTMLFormatter simpleHTMLFormatter =

new SimpleHTMLFormatter("<font color=\"red\">", "</font>");

Highlighter titleHighlighter;

Highlighter contentHighlighter;

titleHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

contentHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

titleHighlighter.FragmentSize = 100;

contentHighlighter.FragmentSize = 100;

search.Abstract = contentHighlighter.GetBestFragment(key, search.SEO_D);

if (string.IsNullOrEmpty(search.Abstract))

{

search.Abstract = search.SEO_D;

}

search.TitleHighLighter = titleHighlighter.GetBestFragment(key, search.Name);

if (string.IsNullOrEmpty(search.TitleHighLighter))

{

search.TitleHighLighter = search.Name;

}

result.Add(search);

}

return result;

}

/// <summary>

/// 英文文档搜索列表

/// </summary>

/// <param name="pageindex"></param>

/// <param name="pagesize"></param>

/// <param name="key"></param>

/// <param name="Count"></param>

/// <returns></returns>

public List<EArticle> EN_SearchDocList(int pageindex, int pagesize, string key, string isLevel, out int Count)

{

string strConn = ConfigurationManager.ConnectionStrings["Search"].ToString();

DataSet ds = new DataSet();

//string sql = "select * from News where Title match '" + key + "'";

//ds = SQLHelper.ExecuteDataset(strConn, CommandType.Text, sql, null);

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

sw.Start();

using (HubbleAsyncConnection conn = new HubbleAsyncConnection(strConn))

{

conn.Open();

GetAnalyzerName(conn, "DocumentSearch_EN");

string wordssplitbyspace;

HubbleCommand matchCmd = new HubbleCommand(conn);

string matchString = matchCmd.GetKeywordAnalyzerStringFromServer("DocumentSearch_EN",

"documentname", key, int.MaxValue, out wordssplitbyspace);

HubbleDataAdapter adapter = new HubbleDataAdapter();

StringBuilder strSql = new StringBuilder();

string[] levelPara;

if (string.IsNullOrEmpty(isLevel))

{

strSql.Append("select between @begin to @end ID,UNIID,DocumentName,PDF,SEO_D,publishTime,addTime from DocumentSearch_EN where ( documentname Contains @matchString or documentname match @matchString ) and VisitLevel ='' and release='true' order by score desc");

}

else

{

levelPara = isLevel.Split(',');

strSql.Append("select between @begin to @end ID,UNIID,DocumentName,PDF,SEO_D,publishTime,addTime from DocumentSearch_EN where ( documentname Contains @matchString or documentname match @matchString or SEO_K Contains @matchString or SEO_K match @matchString ) and (");

for (int i = 0; i < levelPara.Length; i++)

{

strSql.Append(" VisitLevel=@VisitLevel" + i + " or ");

}

strSql.Remove(strSql.Length - 3, 2);

strSql.Append(" or VisitLevel='') and release='true' order by score desc");

}

adapter.SelectCommand = new HubbleCommand(strSql.ToString(), conn);

adapter.SelectCommand.Parameters.Add("@begin", (pagesize - 1) * pageindex);

adapter.SelectCommand.Parameters.Add("@end", pagesize * pageindex - 1);

adapter.SelectCommand.Parameters.Add("@matchString", matchString);

if (!string.IsNullOrEmpty(isLevel))

{

for (int i = 0; i < isLevel.Split(',').Length; i++)

{

adapter.SelectCommand.Parameters.Add("@VisitLevel" + i, isLevel.Split(',')[i].Replace("'", ""));

}

}

adapter.SelectCommand.CacheTimeout = CacheTimeout;

ds = new System.Data.DataSet();

//adapter.Fill(ds);

HubbleCommand cmd = adapter.SelectCommand;

ds = cmd.Query(CacheTimeout);

//titleWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Title", docids, int.MaxValue);

//contentWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Content", docids, int.MaxValue);

}

Count = ds.Tables[0].MinimumCapacity;

List<EArticle> result = new List<EArticle>();

foreach (System.Data.DataRow row in ds.Tables[0].Rows)

{

EArticle document = new EArticle();

document.ID = int.Parse(row["ID"].ToString());

document.UNIID = row["UNIID"].ToString();

document.Name = row["DocumentName"].ToString();

document.SEO_D = row["SEO_D"].ToString();

document.PDF = row["PDF"].ToString();

if (!string.IsNullOrEmpty(row["publishTime"].ToString().Trim()))

{

document.PublishTime = Convert.ToDateTime(row["publishTime"].ToString());

}

else

{

document.PublishTime = Convert.ToDateTime(row["addTime"].ToString());

}

SimpleHTMLFormatter simpleHTMLFormatter =

new SimpleHTMLFormatter("<font color=\"red\">", "</font>");

Highlighter titleHighlighter;

Highlighter contentHighlighter;

titleHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

contentHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

titleHighlighter.FragmentSize = 100;

contentHighlighter.FragmentSize = 100;

string lightname = titleHighlighter.GetBestFragment(key, document.Name);

if (string.IsNullOrEmpty(lightname))

{

document.TitleHighLighter = document.Name;

}

else

{

document.TitleHighLighter = lightname;

}

result.Add(document);

}

sw.Stop();

return result;

}

/// <summary>

///英文全站搜索

/// </summary>

/// <param name="pageindex"></param>

/// <param name="pagesize"></param>

/// <param name="key"></param>

/// <param name="Count"></param>

/// <returns></returns>

public List<ESearch> EN_SearchAllList(int pagesize, int pageindex, string key, string isLevel, int typeid, out int Count)

{

string strConn = ConfigurationManager.ConnectionStrings["Search"].ToString();

DataSet ds = new DataSet();

using (HubbleAsyncConnection conn = new HubbleAsyncConnection(strConn))

{

conn.Open();

GetAnalyzerName(conn, "WholeSearch_EN");

string wordssplitbyspace;

HubbleCommand matchCmd = new HubbleCommand(conn);

string matchString = matchCmd.GetKeywordAnalyzerStringFromServer("WholeSearch_EN",

"Name", key, int.MaxValue, out wordssplitbyspace);

HubbleDataAdapter adapter = new HubbleDataAdapter();

StringBuilder strSql = new StringBuilder();

string[] levelPara;

if (string.IsNullOrEmpty(isLevel))

{

if (pagesize == 0)

{

strSql.Append("select ID,Name,TypeID,SEO_D,TypeName,addTime from ");

}

else

{

strSql.Append("select between @begin to @end ID,Name,TypeID,SEO_D,TypeName,addTime from ");

}

strSql.Append(" WholeSearch_EN where ( Name Contains @matchString or Name Match @matchString or SEO_D Contains @matchString or SEO_D Match @matchString) and VisitLevel =''");

if (typeid > 0)

{

strSql.Append(" and typeid=@typeid");

}

strSql.Append(" order by score desc, lorder");

}

else

{

levelPara = isLevel.Split(',');

if (pagesize == 0)

{

strSql.Append("select ID,Name,TypeID,SEO_D,TypeName,addTime from ");

}

else

{

strSql.Append("select between @begin to @end ID,Name,TypeID,SEO_D,TypeName,addTime from ");

}

strSql.Append(" WholeSearch_EN where ( Name Contains @matchString or Name Match @matchString or SEO_D Contains @matchString or SEO_D Match @matchString) and (");

for (int i = 0; i < levelPara.Length; i++)

{

strSql.Append(" VisitLevel=@VisitLevel" + i + " or ");

}

strSql.Remove(strSql.Length - 3, 2);

strSql.Append(" or VisitLevel='') ");

if (typeid > 0)

{

strSql.Append(" and typeid=@typeid");

}

strSql.Append(" order by score desc, lorder");

}

adapter.SelectCommand = new HubbleCommand(strSql.ToString(), conn);

adapter.SelectCommand.Parameters.Add("@begin", (pageindex - 1) * pagesize);

adapter.SelectCommand.Parameters.Add("@end", pageindex * pagesize - 1);

adapter.SelectCommand.Parameters.Add("@matchString", matchString);

adapter.SelectCommand.Parameters.Add("@typeid", typeid);

if (!string.IsNullOrEmpty(isLevel))

{

for (int i = 0; i < isLevel.Split(',').Length; i++)

{

adapter.SelectCommand.Parameters.Add("@VisitLevel" + i, isLevel.Split(',')[i].Replace("'", ""));

}

}

adapter.SelectCommand.CacheTimeout = CacheTimeout;

ds = new System.Data.DataSet();

//adapter.Fill(ds);

HubbleCommand cmd = adapter.SelectCommand;

ds = cmd.Query(CacheTimeout);

//titleWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Title", docids, int.MaxValue);

//contentWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Content", docids, int.MaxValue);

}

Count = ds.Tables[0].MinimumCapacity;

List<ESearch> result = new List<ESearch>();

foreach (System.Data.DataRow row in ds.Tables[0].Rows)

{

ESearch search = new ESearch();

search.ID = int.Parse(row["ID"].ToString());

//search.UNIID = new Guid(row["UNIID"].ToString());

search.Name = Strings.NoHTML(row["Name"].ToString());

search.SEO_D = row["SEO_D"].ToString();

//search.content = Strings.NoHTML(row["content"].ToString());

search.TypeID = int.Parse(row["TypeID"].ToString());

search.TypeName = row["TypeName"].ToString();

//search.TXT = Strings.NoHTML(row["TXT"].ToString());

if (!string.IsNullOrEmpty(row["addTime"].ToString().Trim()))

{

search.addTime = Convert.ToDateTime(row["addTime"].ToString());

}

else

{

search.addTime = Convert.ToDateTime("9999-12-31");

}

SimpleHTMLFormatter simpleHTMLFormatter =

new SimpleHTMLFormatter("<font color=\"red\">", "</font>");

Highlighter titleHighlighter;

Highlighter contentHighlighter;

titleHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

contentHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

titleHighlighter.FragmentSize = 100;

contentHighlighter.FragmentSize = 100;

search.Abstract = contentHighlighter.GetBestFragment(key, search.SEO_D);

if (string.IsNullOrEmpty(search.Abstract))

{

search.Abstract = search.SEO_D;

}

search.TitleHighLighter = titleHighlighter.GetBestFragment(key, search.Name);

if (string.IsNullOrEmpty(search.TitleHighLighter))

{

search.TitleHighLighter = search.Name;

}

result.Add(search);

}

return result;

}

/// <summary>

/// 中文文档搜索列表

/// </summary>

/// <param name="pageindex"></param>

/// <param name="pagesize"></param>

/// <param name="key"></param>

/// <param name="Count"></param>

/// <returns></returns>

public List<EArticle> SearchDocListNew(int pageindex, int pagesize, string key, string isLevel, out int Count)

{

string strConn = ConfigurationManager.ConnectionStrings["Search"].ToString();

DataSet ds = new DataSet();

//string sql = "select * from News where Title match '" + key + "'";

//ds = SQLHelper.ExecuteDataset(strConn, CommandType.Text, sql, null);

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

sw.Start();

using (HubbleAsyncConnection conn = new HubbleAsyncConnection(strConn))

{

conn.Open();

GetAnalyzerName(conn, "DocumentSearch");

string wordssplitbyspace;

HubbleCommand matchCmd = new HubbleCommand(conn);

string matchString = matchCmd.GetKeywordAnalyzerStringFromServer("DocumentSearch",

"Documentname", (key.Split('_')[0]).ToString(), int.MaxValue, out wordssplitbyspace);

HubbleDataAdapter adapter = new HubbleDataAdapter();

StringBuilder strSql = new StringBuilder();

string[] levelPara;

//if (key.Split('_')[1] == "1")

//{

// if (string.IsNullOrEmpty(isLevel))

// {

// // strSql.Append("select between @begin to @end * from V_DocumentSearch where ( documentname^100 Contains @matchString or Content^50 Contains @matchString or documentname^100 match @matchString or Content^50 match @matchString ) and VisitLevel ='' and release='true' order by score desc");

// strSql.Append("select between @begin to @end ID,UNIID,DocumentName,SEO_D,PDF,htmlURL,gid_collection,publishTime,addTime from DocumentSearch where ( documentname Contains @matchString or documentname match @matchString ) and VisitLevel ='' and release='true' order by score desc");

// }

// else

// {

// levelPara = isLevel.Split(',');

// //strSql.Append("select between @begin to @end * from V_DocumentSearch where ( documentname^100 Contains @matchString or Content^50 Contains @matchString or documentname^100 match @matchString or Content^50 match @matchString ) and (");

// strSql.Append("select between @begin to @end ID,UNIID,DocumentName,SEO_D,PDF,htmlURL,gid_collection,publishTime,addTime from DocumentSearch where ( documentname Contains @matchString or documentname match @matchString ) and (");

// for (int i = 0; i < levelPara.Length; i++)

// {

// strSql.Append(" VisitLevel=@VisitLevel" + i + " or ");

// }

// strSql.Remove(strSql.Length - 3, 2);

// strSql.Append(" or VisitLevel='') and release='true' order by score desc");

// }

//}

//else if (key.Split('_')[1] == "2")

//{

// if (string.IsNullOrEmpty(isLevel))

// {

// //strSql.Append("select between @begin to @end * from V_DocumentSearch where ( documentname^100 Contains @matchString or Content^50 Contains @matchString or documentname^100 match @matchString or Content^50 match @matchString ) and VisitLevel ='' and release='true' order by publishTime desc");

// strSql.Append("select between @begin to @end ID,UNIID,DocumentName,SEO_D,PDF,htmlURL,gid_collection,publishTime,addTime from DocumentSearch where ( documentname Contains @matchString or documentname match @matchString ) and VisitLevel ='' and release='true' order by publishTime desc");

// }

// else

// {

// levelPara = isLevel.Split(',');

// //strSql.Append("select between @begin to @end * from V_DocumentSearch where ( documentname^100 Contains @matchString or Content^50 Contains @matchString or documentname^100 match @matchString or Content^50 match @matchString ) and (");

// strSql.Append("select between @begin to @end ID,UNIID,DocumentName,SEO_D,PDF,htmlURL,gid_collection,publishTime,addTime from DocumentSearch where ( documentname Contains @matchString or documentname match @matchString ) and (");

// for (int i = 0; i < levelPara.Length; i++)

// {

// strSql.Append(" VisitLevel=@VisitLevel" + i + " or ");

// }

// strSql.Remove(strSql.Length - 3, 2);

// strSql.Append(" or VisitLevel='') and release='true' order by publishTime desc");

// }

//}

//else

//{

if (string.IsNullOrEmpty(isLevel))

{

//strSql.Append("select between @begin to @end * from V_DocumentSearch where ( documentname^100 Contains @matchString or Content^50 Contains @matchString or documentname^100 match @matchString or Content^50 match @matchString ) and VisitLevel ='' and release='true' order by score desc, publishTime desc");

strSql.Append("select between @begin to @end ID,UNIID,DocumentName,SEO_D,PDF,htmlURL,gid_collection,publishTime,addTime from DocumentSearch where ( documentname Contains @matchString or documentname match @matchString ) and VisitLevel ='' and release='true' order by score desc, publishTime desc");

}

else

{

levelPara = isLevel.Split(',');

//strSql.Append("select between @begin to @end * from V_DocumentSearch where ( documentname^100 Contains @matchString or Content^50 Contains @matchString or documentname^100 match @matchString or Content^50 match @matchString ) and (");

strSql.Append("select between @begin to @end ID,UNIID,DocumentName,SEO_D,PDF,htmlURL,gid_collection,publishTime,addTime from DocumentSearch where ( documentname Contains @matchString or documentname match @matchString ) and (");

for (int i = 0; i < levelPara.Length; i++)

{

strSql.Append(" VisitLevel=@VisitLevel" + i + " or ");

}

strSql.Remove(strSql.Length - 3, 2);

strSql.Append(" or VisitLevel='') and release='true' order by score desc, publishTime desc ");

}

//}

adapter.SelectCommand = new HubbleCommand(strSql.ToString(), conn);

adapter.SelectCommand.Parameters.Add("@begin", (pagesize - 1) * pageindex);

adapter.SelectCommand.Parameters.Add("@end", pagesize * pageindex - 1);

adapter.SelectCommand.Parameters.Add("@matchString", matchString);

if (!string.IsNullOrEmpty(isLevel))

{

for (int i = 0; i < isLevel.Split(',').Length; i++)

{

adapter.SelectCommand.Parameters.Add("@VisitLevel" + i, isLevel.Split(',')[i].Replace("'", ""));

}

}

adapter.SelectCommand.CacheTimeout = CacheTimeout;

ds = new System.Data.DataSet();

//adapter.Fill(ds);

HubbleCommand cmd = adapter.SelectCommand;

ds = cmd.Query(CacheTimeout);

//titleWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Title", docids, int.MaxValue);

//contentWordsPositions = cmd.GetWordsPositions(wordssplitbyspace, "News", "Content", docids, int.MaxValue);

}

Count = ds.Tables[0].MinimumCapacity;

List<EArticle> result = new List<EArticle>();

foreach (System.Data.DataRow row in ds.Tables[0].Rows)

{

EArticle document = new EArticle();

document.ID = int.Parse(row["ID"].ToString());

document.UNIID = row["UNIID"].ToString();

document.Name = row["DocumentName"].ToString();

document.SEO_D = row["SEO_D"].ToString();

document.PDF = row["PDF"].ToString();

document.htmlURL = row["htmlURL"].ToString();

document.gid_collection = row["gid_collection"].ToString();

document.TitleHighLighter = row["DocumentName"].ToString();

if (!string.IsNullOrEmpty(row["publishTime"].ToString().Trim()))

{

document.PublishTime = Convert.ToDateTime(row["publishTime"].ToString());

}

else

{

document.PublishTime = Convert.ToDateTime(row["AddTime"].ToString());

}

SimpleHTMLFormatter simpleHTMLFormatter =

new SimpleHTMLFormatter("<font color=\"red\">", "</font>");

Highlighter titleHighlighter;

Highlighter contentHighlighter;

titleHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

contentHighlighter =

new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer());

titleHighlighter.FragmentSize = 100;

contentHighlighter.FragmentSize = 100;

string lightname = titleHighlighter.GetBestFragment((key.Split('_')[0]).ToString(), document.Name);

if (string.IsNullOrEmpty(lightname))

{

document.TitleHighLighter = document.Name;

}

else

{

document.TitleHighLighter = lightname;

}

result.Add(document);

}

sw.Stop();

return result;

}

}

}

posted @ 2016-12-20 09:38 画个逗号给明天 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值