81,111
社区成员
发帖
与我相关
我的任务
分享
Query query = prequery(type, q);
int sortname = 0;
sortname = (int)(type.Replace("-", "").Length / 2);
//排序 此处只能用一列排序
Sort st = new Sort();
SortField[] sf = new SortField[] {
new SortField("type"+sortname.ToString(),SortField.INT)
};
st.SetSort(sf);
log("type" + sortname.ToString());
DateTime start = DateTime.Now;
DateTime end;
//IndexSearcher _is = new IndexSearcher(path);
//StringBuilder sb = new StringBuilder();
//使用上次之缓存
CachingWrapperFilter filter = new CachingWrapperFilter(new QueryFilter(query));
Dictionary<string, int> dc = new Dictionary<string, int>();
//TopFieldDocs docs = _is.Search(query, null, 100000, st);
TopFieldDocs docs = _is.Search(query, filter, 100000, st);
end = DateTime.Now;
log("1 查出耗时 " + ((TimeSpan)(end - start)).TotalMilliseconds.ToString() + " ms !\r\n");
//docs.scoreDocs数组对应查出的文档,仅包括排序字段的值
for (int i = 0; i < docs.scoreDocs.Length; i++)
{
FieldDoc fieldDoc = (FieldDoc)docs.scoreDocs[i];
//fieldDoc.fields数组对应每个排序字段
for (int j = 0; j < fieldDoc.fields.Length; j++)
{
String sortValue = fieldDoc.fields[j].ToString();
if (dc.ContainsKey(sortValue))
dc[sortValue] += 1;
else
dc[sortValue] = 1;
}
}
end = DateTime.Now;
log("2 遍历统计耗时 " + ((TimeSpan)(end - start)).TotalMilliseconds.ToString() + " ms !\r\n");
DataTable d = new DataTable();
if (dc.Count > 0)
{
List<string> tp = new List<string>();
foreach (string k in dc.Keys)
{
if (k.Trim() != "")
tp.Add("'" + numAddGang(k) + "'");
}
//replace(type,'-','')
com.CommandText = "select name,type from mytype where type in (" + string.Join(",", tp.ToArray()) + ")";
log(com.CommandText);
//Utilities.die(com.CommandText);
d = GenericDataAccess.ExecuteSelectCommand(com);
d.Columns.Add("num", typeof(int));
foreach (DataRow dr in d.Rows)
{
if (dc.ContainsKey(dr["type"].ToString().Replace("-", "")))
dr["num"] = dc[dr["type"].ToString().Replace("-", "")];
}
d.DefaultView.Sort = "num desc";
d = d.DefaultView.ToTable();
}
return d;