110,538
社区成员
发帖
与我相关
我的任务
分享
public static void GetKeyWords(object o)
{
Param param=(Param)o;
int rowCount=0;
int rowIndex = 0;
Count = 3;
if (param.pageIndex < 1)
rowCount = dt.Rows.Count;
else
{
if (param.pageIndex == dt.Rows.Count / param.pageSize + 1)
rowCount = dt.Rows.Count % param.pageSize;
else
rowCount = param.pageSize * param.pageIndex;
rowIndex = (param.pageIndex - 1) * param.pageSize;
}
for (int x = rowIndex; x < rowCount;x++ )
{
string strTitle = dt.Rows[x][param.colTitle].ToString();
string strContent = dt.Rows[x][param.colContent].ToString();
string strKeyWords = dt.Rows[x][param.colKeyWords].ToString();
List<Tag> list = new List<Tag>();
int nCount = 0;
for (int i = 0; i < keyWordsList.Count; i++)//Title
{
if (nCount >= Count)
Type = TagType.Title;
else
Type = TagType.Content;
if (strTitle.Contains(keyWordsList[i]) && !strKeyWords.Contains(keyWordsList[i]))//title中存在某一个关键词
{
nCount++;
for (int j = 0; j < strTitle.Length; )
{
int index = strTitle.IndexOf(keyWordsList[i], j);
if (index >= 0)
{
//for (int n = i + 1; n < keyWordsList.Count; n++)
//{
// if (strTitle.IndexOf(keyWordsList[i] + keyWordsList[n]) > 0)
// {
// if (!keyWordsList.Contains(keyWordsList[i] + keyWordsList[n]))
// keyWordsList.Add(keyWordsList[i] + keyWordsList[n]);
// break;
// }
//}
Tag temp = new Tag();
temp.Name = keyWordsList[i];
EqualityComparer<Tag> eq = new EqualityComparer<Tag>();
eq.ComparerString.Add("Name");
if (list.Contains(temp, eq))
{
temp = list.SingleOrDefault(t => t.Name == keyWordsList[i]);
for (int n = 0; n < list.Count; n++)
{
if (list[n].Name == temp.Name)
{
list.RemoveAt(n);
}
}
temp.Count = temp.Count + 1;
temp.Index = index;
temp.Name = keyWordsList[i];
list.Add(temp);
}
else
{
temp.Count = 1;
temp.Name = keyWordsList[i];
temp.Index = index;
list.Add(temp);
}
}
if (index >= 0)
j = j + index + keyWordsList[i].Length;
else
break;
}
}
}
int length = 0;
if (Type == TagType.Title)//如果Title已经取完
{
var query = (from t in list orderby t.Count descending, t.Index ascending select t).ToList();
length = query.Count >= Count ? Count : query.Count;
for (int i = 0; i < length; i++)
{
if ((i == length - 1) && length >= Count)
{
SqlList.Add(string.Format("update {0} set {1}={1}+'{2}' where id={3}", param.tabName, param.colKeyWords, query[query.Count - (i + 1)].Name, dt.Rows[x]["id"]));
}
else
{
SqlList.Add(string.Format("update {0} set {1}={1}+'{2}'+',' where id={3}", param.tabName, param.colKeyWords, query[query.Count - (i + 1)].Name, dt.Rows[x]["id"]));
}
}
}
if (Type != TagType.Title)
{
for (int i = 0; i < keyWordsList.Count; i++)
{
if (strContent.Contains(keyWordsList[i]) && !strKeyWords.Contains(keyWordsList[i]))
{
for (int j = 0; j < strContent.Length; )
{
int index = strContent.IndexOf(keyWordsList[i], j);
if (index >= 0)
{
//for (int n = i + 1; n < keyWordsList.Count; n++)
//{
// if (strContent.IndexOf(keyWordsList[i] + keyWordsList[n]) >= 0)
// {
// if (!keyWordsList.Contains(keyWordsList[i] + keyWordsList[n]))
// keyWordsList.Add(keyWordsList[i] + keyWordsList[n]);
// break;
// }
//}
Tag temp = new Tag();
temp.Name = keyWordsList[i];
EqualityComparer<Tag> eq = new EqualityComparer<Tag>();
eq.ComparerString.Add("Name");
if (list.Contains(temp, eq))
{
temp = list.SingleOrDefault(t => t.Name == keyWordsList[i]);
for (int n = 0; n < list.Count; n++)
{
if (list[n].Name == temp.Name)
{
list.RemoveAt(n);
}
}
temp.Count = temp.Count + 1;
temp.Index = index;
temp.Name = keyWordsList[i];
list.Add(temp);
}
else
{
temp.Count = 1;
temp.Name = keyWordsList[i];
temp.Index = index;
list.Add(temp);
}
}
if (index >= 0)
j = j + index + keyWordsList[i].Length;
else
break;
}
}
}
}
if (Type == TagType.Content)//如果Title已经取完
{
var query = (from t in list orderby t.Count descending, t.Index ascending select t).ToList();
if (length == 0)
length = query.Count >= Count ? Count : query.Count;
else
length = Count - length;
for (int i = 0; i < length; i++)
{
if ((i == length - 1))
{
SqlList.Add(string.Format("update {0} set {1}={1}+'{2}' where id={3}", param.tabName, param.colKeyWords, query[query.Count - (i + 1)].Name, dt.Rows[x]["id"]));
}
else
{
SqlList.Add(string.Format("update {0} set {1}={1}+'{2}'+',' where id={3}", param.tabName, param.colKeyWords, query[query.Count - (i + 1)].Name, dt.Rows[x]["id"]));
}
}
}
}
}