private static LuceneResultNode ResponseSearch(IndexBase index, Query query, SearchNode snode, int maxhit) { var searcher = new IndexSearcher(index.Directory, true); try { int maxHit = maxhit; if (maxHit == 0) { maxHit = SettingCache.MaxHit; } var node = new LuceneResultNode(); var flag = false; TopDocs docs = null; int allhit = 0; if (snode.ShowNav == 1) { node.Types = new Dictionary <int, int>(7); for (var j = 1; j <= snode.TotalTypes; j++) { var filter = new ContainFilter(new Term("type", j.ToString())); var docss = searcher.Search(query, filter, maxHit); if (j == snode.VodType) { docs = docss; flag = true; } if (docss.totalHits > 0) { int hit = docss.scoreDocs.Length; node.Types[j] = hit; allhit += hit; } } } if (!flag) { if (snode.VodType == 0) { if (allhit == 0) { if (maxhit == 0) { allhit = 500; } else { allhit = maxhit; } } docs = searcher.Search(query, null, allhit); } else { var filter = new ContainFilter(new Term("type", snode.VodType.ToString())); docs = searcher.Search(query, filter, maxHit); } } int all = docs.scoreDocs.Length; if (SettingCache.IsStatAct && all > 0 && snode.IsStat) { ThreadPool.QueueUserWorkItem(state => LuceneDictionary.Instance.AddNode(snode.Key, all, snode.Pindex)); } //if (all > maxHit) // all = maxHit; int i = (snode.Start - 1) * snode.Limit; if (snode.IsNoPaging) { i = 0; snode.Limit = all; } int page = snode.Limit; if (page > all) { page = all; } var result = new List <string>(page); while (i < all && result.Count < snode.Limit) { var doc = searcher.Doc(docs.scoreDocs[i].doc); string value = doc.Get(snode.IndexValue); result.Add(value); i++; } node.Result = result; node.AllCount = all; return(node); } finally { searcher.Close(); } }
/// <summary> /// LuceneNet节目预告分页输出 /// </summary> private string CreateParadeSmarkPageList(LuceneResultNode result, LiveSearchFilter filter, bool isEx) { var vkey = new VideoNodeKey(filter.platform, 0, filter.auth); var parades = from parade in result.Result select ChannelLiveItemsCache.Instance.Items[int.Parse(parade)]; var query = from parade in parades group parade by parade.ChannelID; var list = query.ToList(); //var groupquery = query.Skip(filter.c * (filter.s - 1)).Take(filter.c); //var count = groupquery.Count(); var index = (filter.s - 1) * filter.c; var max = index + filter.c; if (max > list.Count) max = list.Count; var count = max - index; var xml = new XElement("vlist"); xml.Add(new XElement("count", count)); xml.Add(new XElement("page_count", PageUtils.PageCount(count, filter.c))); xml.Add(new XElement("countInPage", filter.c)); xml.Add(new XElement("page", filter.s)); for (var i = index; i < max; i++) { var group = list[i]; var v = VideoResponseUtils.CustomLiveListRes(LiveListCache.Instance.Dictionary[group.Key], filter, 0, isEx); var paraderoot = new XElement("parade_list"); foreach (var key in group) { paraderoot.Add(VideoResponseUtils.LiveListSearchParade(key, filter)); } v.Add(paraderoot); xml.Add(v); } return xml.ToString(SaveOptions.DisableFormatting); }
/// <summary> /// LuceneNet分页输出 /// </summary> private string CreateSmarkPageList(LuceneResultNode result, LiveSearchFilter filter, bool isEx) { var key = new VideoNodeKey(filter.platform, 0, filter.auth); var xml = new XElement("vlist"); xml.Add(new XElement("count", result.AllCount)); xml.Add(new XElement("page_count", PageUtils.PageCount(result.AllCount, filter.c))); xml.Add(new XElement("countInPage", filter.c)); xml.Add(new XElement("page", filter.s)); xml.Add(from v in result.Result select VideoResponseUtils.CustomLiveListRes(LiveListCache.Instance.Dictionary[int.Parse(v)], filter, 0, isEx)); return xml.ToString(SaveOptions.DisableFormatting); }
/// <summary> /// LuceneNet分页输出 /// </summary> private static string CreateSmarkPageList(LuceneResultNode result, ListFilter filter, VideoPars pars, bool isEx) { var xml = new XElement("vlist"); xml.Add(new XElement("count", result.AllCount)); xml.Add(new XElement("page_count", PageUtils.PageCount(result.AllCount, filter.c))); xml.Add(new XElement("countInPage", filter.c)); xml.Add(new XElement("page", filter.s)); if (filter.shownav == 1) { xml.Add(new XElement("nav", from type in result.Types select new XElement("type", new XAttribute("id", type.Key), new XAttribute("name", BoxTypeCache.Instance.Items[type.Key].Language[filter.lang].Title), new XAttribute("count", type.Value) ))); } xml.Add(from v in result.Result select pars.ResponseFun(ListCache.Instance.Dictionary[int.Parse(v)], filter, isEx)); return xml.ToString(SaveOptions.DisableFormatting); }
/// <summary> /// LuceneNet分页输出 /// </summary> private static string CreateSmarkPageList(LuceneResultNode result, RelevanceFilter filter, VideoPars pars, bool isEx) { var xml = new XElement("vlist"); var count = result.AllCount - 1; if (count < 0) count = 0; xml.Add(new XElement("count", count)); //xml.Add(new XElement("page_count", PageUtils.PageCount(result.AllCount, filter.c))); //xml.Add(new XElement("countInPage", filter.c)); //xml.Add(new XElement("page", filter.s)); for (var i = 1; i < result.AllCount; i++) { xml.Add(pars.ResponseFun(ListCache.Instance.Dictionary[int.Parse(result.Result[i])], filter, isEx)); } return xml.ToString(SaveOptions.DisableFormatting); }
private static LuceneResultNode ResponseSearch(IndexBase index, Query query, SearchNode snode, int maxhit) { var searcher = new IndexSearcher(index.Directory, true); try { int maxHit = maxhit; if (maxHit == 0) maxHit = SettingCache.MaxHit; var node = new LuceneResultNode(); var flag = false; TopDocs docs = null; int allhit = 0; if (snode.ShowNav == 1) { node.Types = new Dictionary<int, int>(7); for (var j = 1; j <= snode.TotalTypes; j++) { var filter = new ContainFilter(new Term("type", j.ToString())); var docss = searcher.Search(query, filter, maxHit); if (j == snode.VodType) { docs = docss; flag = true; } if (docss.totalHits > 0) { int hit = docss.scoreDocs.Length; node.Types[j] = hit; allhit += hit; } } } if (!flag) { if (snode.VodType == 0) { if (allhit == 0) { if (maxhit == 0) allhit = 500; else allhit = maxhit; } docs = searcher.Search(query, null, allhit); } else { var filter = new ContainFilter(new Term("type", snode.VodType.ToString())); docs = searcher.Search(query, filter, maxHit); } } int all = docs.scoreDocs.Length; if (SettingCache.IsStatAct && all > 0 && snode.IsStat) ThreadPool.QueueUserWorkItem(state => LuceneDictionary.Instance.AddNode(snode.Key, all, snode.Pindex)); //if (all > maxHit) // all = maxHit; int i = (snode.Start - 1) * snode.Limit; if (snode.IsNoPaging) { i = 0; snode.Limit = all; } int page = snode.Limit; if (page > all) page = all; var result = new List<string>(page); while (i < all && result.Count < snode.Limit) { var doc = searcher.Doc(docs.scoreDocs[i].doc); string value = doc.Get(snode.IndexValue); result.Add(value); i++; } node.Result = result; node.AllCount = all; return node; } finally { searcher.Close(); } }