Example #1
0
 public static LuceneResultNode SearchEx(IndexBase index, SearchNode node)
 {
     try
     {
         var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_29, node.Queries, node.Fields, node.Occurs, new PanGuAnalyzer(true));
         foreach (NumberRangeNode n in node.NumberRangeFiters)
         {
             query = new FilteredQuery(query, NumericRangeFilter.NewIntRange(n.FieldName, n.MinValue, n.MaxValue, true, true));
         }
         foreach (LongRangeNode lr in node.LongRnageFilters)
         {
             query = new FilteredQuery(query, NumericRangeFilter.NewLongRange(lr.FieldName, lr.MinValue, lr.MaxValue, true, true));
         }
         foreach (ContainFilterNode cf in node.ContainFilters)
         {
             query = new FilteredQuery(query, new ContainFilter(new Term(cf.FieldName, cf.Text)));
         }
         return ResponseSearch(index, query, node, 0);
     }
     catch (Lucene.Net.QueryParsers.ParseException)
     {
         return new LuceneResultNode() { AllCount = 0, Result = new List<string>() };
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
 public static LuceneResultNode SearchMaxHit(IndexBase index, SearchNode node, int maxHit)
 {
     try
     {
         var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_29, node.Queries, node.Fields, node.Occurs, new PanGuAnalyzer(true));
         foreach (ContainFilterNode cf in node.ContainFilters)
         {
             query = new FilteredQuery(query, new ContainFilter(new Term(cf.FieldName, cf.Text)));
         }
         return ResponseSearch(index, query, node, maxHit);
     }
     catch (Lucene.Net.QueryParsers.ParseException)
     {
         return new LuceneResultNode() { AllCount = 0, Result = new List<string>() };
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #3
0
 public static int PageList(IEnumerable<string> source, SearchNode filter, XElement root)
 {
     var index = (filter.Start - 1) * filter.Limit;
     var max = index + filter.Limit;
     int num = 0;
     using (var enumerator = source.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             if (index <= num && num < max)
             {
                 root.Add(new XElement("tag", enumerator.Current));
             }
             num++;
         }
     }
     return num;
 }
Example #4
0
 private static int ResponseDistinctSearch(IndexBase index, Query query, SearchNode snode, XElement root)
 {
     var searcher = new IndexSearcher(index.Directory, true);
     try
     {
         var docs = searcher.Search(query, null, SettingCache.MaxHit);
         IEnumerable<string> results;
         if (!snode.IsNoPaging)
         {
             results = docs.scoreDocs.Select(v => searcher.Doc(v.doc).Get(snode.IndexValue)).Distinct();
         }
         else
         {
             results = docs.scoreDocs.Select(v => LuceneNetUtils.FormatTraditionChinese(searcher.Doc(v.doc).Get(snode.IndexValue))).Distinct();
         }
         return LuceneNetUtils.PageList(results, snode, root);
     }
     finally
     {
         searcher.Close();
     }
 }
Example #5
0
 public static int DistinctSearch(IndexBase index, SearchNode node, XElement root)
 {
     try
     {
         var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_29, node.Queries, node.Fields, node.Occurs, new PanGuAnalyzer(true));
         foreach (ContainFilterNode cf in node.ContainFilters)
         {
             query = new FilteredQuery(query, new ContainFilter(new Term(cf.FieldName, cf.Text)));
         }
         return ResponseDistinctSearch(index, query, node, root);
     }
     catch (Lucene.Net.QueryParsers.ParseException)
     {
         return 0;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #6
0
        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();
            }
        }
Example #7
0
 /// <summary>
 /// 直播扩展搜索
 /// </summary>
 public static LuceneResultNode LiveSearchEx(LiveSearchFilter filter, string[] searchFields, string query, bool isNoPaging)
 {
     var fkey = new VideoNodeKey(filter.platform, 0, filter.auth);
     var containfilters = new List<ContainFilterNode>();
     var fbname = string.Empty;
     if (filter.forbidden)
     {
         filter.forbidden = VideoNodeKeyArray.Instance.Forbidden[fkey];
         if (filter.forbidden)
         {
             if (ForbiddenAreaCache.Instance.Items.ContainsKey(filter.fbcode))
             {
                 fbname = ForbiddenAreaCache.Instance.Items[filter.fbcode].ForbiddenAreaName;
             }
             else
             {
                 filter.forbidden = false;
             }
         }
     }
     if (filter.forbidden)
     {
         containfilters.Add(new ContainFilterNode() { FieldName = LiveEpgNode.ForbiddenCode, Text = fbname.ToLower() });
     }
     var pindx = VideoNodeKeyArray.Instance.Items[fkey].ToString();
     containfilters.Add(new ContainFilterNode() { FieldName = LiveEpgNode.PlatformIndex, Text = pindx });
     if (!string.IsNullOrEmpty(filter.flag))
     {
         containfilters.Add(new ContainFilterNode() { FieldName = LiveEpgNode.Flags, Text = VideoParsUtils.OrderAscFlags(filter.flag) });
     }
     if (filter.ver <= 1)
     {
         containfilters.Add(new ContainFilterNode() { FieldName = LiveEpgNode.TableType, Text = "0" });
     }
     else
     {
         containfilters.Add(new ContainFilterNode() { FieldName = LiveEpgNode.IsGroup, Text = "0" });
     }
     if (filter.forbidvip == 1)
     {
         containfilters.Add(new ContainFilterNode() { FieldName = LiveEpgNode.VipFlag, Text = "0" });
     }
     List<LongRangeNode> longs = new List<LongRangeNode>();
     if (filter.lastday != 0)
     {
         longs.Add(new LongRangeNode() { FieldName = LiveEpgNode.ParadeBeginTime, MinValue = 0, MaxValue = filter.lastday });
     }
     List<NumberRangeNode> rangenodes = new List<NumberRangeNode>();
     if (filter.bitratemin != 0 || filter.bitratemax != 0)
     {
         if (filter.bitratemax == 0) filter.bitratemax = int.MaxValue;
         rangenodes.Add(new NumberRangeNode() { FieldName = LiveEpgNode.BitrateRange, MinValue = filter.bitratemin, MaxValue = filter.bitratemax });
     }
     if (filter.hmin != 0 || filter.hmax != 0)
     {
         if (filter.hmax == 0) filter.hmax = int.MaxValue;
         rangenodes.Add(new NumberRangeNode() { FieldName = LiveEpgNode.HightRange, MinValue = filter.hmin, MaxValue = filter.hmax });
     }
     if (filter.wmin != 0 || filter.wmax != 0)
     {
         if (filter.wmax == 0) filter.wmax = int.MaxValue;
         rangenodes.Add(new NumberRangeNode() { FieldName = LiveEpgNode.WidthRange, MinValue = filter.wmin, MaxValue = filter.wmax });
     }
     SearchNode node = new SearchNode();
     node.Key = filter.k;
     node.Pindex = pindx;
     node.Queries = query;//Searcher.SegmentKeyWord(filter.k);
     node.Fields = searchFields;
     node.Occurs = LiveEpgNode.Occurs;
     node.LongRnageFilters = longs;
     node.ContainFilters = containfilters;
     node.NumberRangeFiters = rangenodes;
     node.Start = filter.s;
     node.Limit = filter.c;
     node.IsNoPaging = isNoPaging;
     node.IndexValue = LiveEpgNode.IndexValue;
     return Searcher.SearchEx(LiveEpgLuceneNet.Instance.IndexDic, node);
 }
Example #8
0
 /// <summary>
 /// 点播基本搜索
 /// </summary>
 public static LuceneResultNode Search(ListFilter filter, string[] fields, Lucene.Net.Search.BooleanClause.Occur[] occurs, string query, bool isStat)
 {
     var fkey = new VideoNodeKey(filter.platform, 0, filter.auth);
     var containfilters = new List<ContainFilterNode>();
     var fbname = string.Empty;
     if (filter.forbidden)
     {
         filter.forbidden = VideoNodeKeyArray.Instance.Forbidden[fkey];
         if (filter.forbidden)
         {
             if (ForbiddenAreaCache.Instance.Items.ContainsKey(filter.fbcode))
             {
                 fbname = ForbiddenAreaCache.Instance.Items[filter.fbcode].ForbiddenAreaName;
             }
             else
             {
                 filter.forbidden = false;
             }
         }
     }
     if (filter.forbidden)
     {
         containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.ForbiddenCode, Text = fbname.ToLower() });
     }
     var pindx = VideoNodeKeyArray.Instance.Items[fkey].ToString();
     containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.PlatformIndex, Text = pindx });
     if (!string.IsNullOrEmpty(filter.flag))
     {
         containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.Flags, Text = VideoParsUtils.OrderAscFlags(filter.flag) });
     }
     if (filter.ver <= 1)
     {
         containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.TableType, Text = "0" });
     }
     else
     {
         if (filter.screen == "v")
         {
             containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.IsGroup, Text = "0" });
         }
         else
         {
             containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.Screen, Text = "0" });
             containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.IsGroup, Text = "0" });
         }
     }
     //if (filter.type != 0)
     //{
     //    containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.Type, Text = filter.type.ToString() });
     //}
     var node = new SearchNode();
     node.Key = filter.k;
     node.Pindex = pindx;
     node.Queries = query;//Searcher.SegmentKeyWord(filter.k);
     node.Fields = fields;
     node.Occurs = occurs;
     //node.SortFields = EpgIndexNode.SortFields;
     node.ContainFilters = containfilters;
     node.LongRnageFilters = new List<LongRangeNode>();
     node.Start = filter.s;
     node.Limit = filter.c;
     node.IndexValue = EpgIndexNode.IndexValue;
     node.IsStat = isStat;
     node.VodType = filter.type;
     node.ShowNav = filter.shownav;
     node.TotalTypes = BoxTypeCache.Instance.Items.Count;
     return Searcher.Search(EpgLuceneNet.Instance.IndexDic, node);
 }
Example #9
0
 /// <summary>
 /// 点播扩展关联推荐
 /// </summary>
 public static LuceneResultNode RelevanceSearchEx(RelevanceFilter filter, string query, int maxHit)
 {
     var fkey = new VideoNodeKey(filter.platform, 0, filter.auth);
     var rangenodes = new List<NumberRangeNode>();
     var containfilters = new List<ContainFilterNode>();
     var fbname = string.Empty;
     if (filter.forbidden)
     {
         filter.forbidden = VideoNodeKeyArray.Instance.Forbidden[fkey];
         if (filter.forbidden)
         {
             if (ForbiddenAreaCache.Instance.Items.ContainsKey(filter.fbcode))
             {
                 fbname = ForbiddenAreaCache.Instance.Items[filter.fbcode].ForbiddenAreaName;
             }
             else
             {
                 filter.forbidden = false;
             }
         }
     }
     if (filter.forbidden)
     {
         containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.ForbiddenCode, Text = fbname.ToLower() });
     }
     var pindx = VideoNodeKeyArray.Instance.Items[fkey].ToString();
     containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.PlatformIndex, Text = pindx });
     if (filter.bitratemin != 0 || filter.bitratemax != 0)
     {
         if (filter.bitratemax == 0) filter.bitratemax = int.MaxValue;
         rangenodes.Add(new NumberRangeNode() { FieldName = EpgIndexNode.BitrateRange, MinValue = filter.bitratemin, MaxValue = filter.bitratemax });
     }
     if (filter.hmin != 0 || filter.hmax != 0)
     {
         if (filter.hmax == 0) filter.hmax = int.MaxValue;
         rangenodes.Add(new NumberRangeNode() { FieldName = EpgIndexNode.HightRange, MinValue = filter.hmin, MaxValue = filter.hmax });
     }
     if (filter.wmin != 0 || filter.wmax != 0)
     {
         if (filter.wmax == 0) filter.wmax = int.MaxValue;
         rangenodes.Add(new NumberRangeNode() { FieldName = EpgIndexNode.WidthRange, MinValue = filter.wmin, MaxValue = filter.wmax });
     }
     if (filter.forbidvip == 1)
     {
         containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.VipFlag, Text = "0" });
     }
     if (filter.ver > 1 && filter.screen != "v")
     {
         containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.Screen, Text = "0" });
     }
     var node = new SearchNode();
     node.Key = filter.vids;
     node.Pindex = pindx;
     node.Queries = query;//Searcher.SegmentKeyWord(filter.k);
     node.Fields = EpgIndexNode.RelevanceFields;
     node.Occurs = EpgIndexNode.RelevanceOccurs;
     //node.SortFields = EpgIndexNode.SortFields;
     node.ContainFilters = containfilters;
     node.NumberRangeFiters = rangenodes;
     node.Start = 1;
     node.Limit = maxHit;
     node.IndexValue = EpgIndexNode.IndexValue;
     return Searcher.SearchMaxHitEx(EpgLuceneNet.Instance.IndexDic, node, maxHit);
 }
Example #10
0
 /// <summary>
 /// 点播关联推荐
 /// </summary>
 public static LuceneResultNode RelevanceSearch(RelevanceFilter filter, string query, int maxHit)
 {
     var fkey = new VideoNodeKey(filter.platform, 0, filter.auth);
     var containfilters = new List<ContainFilterNode>();
     var fbname = string.Empty;
     if (filter.forbidden)
     {
         filter.forbidden = VideoNodeKeyArray.Instance.Forbidden[fkey];
         if (filter.forbidden)
         {
             if (ForbiddenAreaCache.Instance.Items.ContainsKey(filter.fbcode))
             {
                 fbname = ForbiddenAreaCache.Instance.Items[filter.fbcode].ForbiddenAreaName;
             }
             else
             {
                 filter.forbidden = false;
             }
         }
     }
     if (filter.forbidden)
     {
         containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.ForbiddenCode, Text = fbname.ToLower() });
     }
     var pindx = VideoNodeKeyArray.Instance.Items[fkey].ToString();
     containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.PlatformIndex, Text = pindx });
     if (filter.ver > 1 && filter.screen != "v")
     {
         containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.Screen, Text = "0" });
     }
     var node = new SearchNode();
     node.Key = filter.vids;
     node.Pindex = pindx;
     node.Queries = query;//Searcher.SegmentKeyWord(filter.k);
     node.Fields = EpgIndexNode.RelevanceFields;
     node.Occurs = EpgIndexNode.RelevanceOccurs;
     node.ContainFilters = containfilters;
     node.Start = 1;
     node.Limit = maxHit;
     node.IndexValue = EpgIndexNode.IndexValue;
     return Searcher.SearchMaxHit(EpgLuceneNet.Instance.IndexDic, node, maxHit);
 }
Example #11
0
 /// <summary>
 /// Tag搜索
 /// </summary>
 public static int TagSearch(TagSearchFilter filter, string[] fields, string query, XElement root)
 {
     var containfilters = new List<ContainFilterNode>();
     var pindx = VideoNodeKeyArray.Instance.Items[new VideoNodeKey(filter.platform, 0, filter.auth)].ToString();
     containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.Flags, Text = filter.dimension });
     containfilters.Add(new ContainFilterNode() { FieldName = EpgIndexNode.PlatformIndex, Text = pindx });
     //var fbname = string.Empty;
     //if (filter.forbidden)
     //{
     //    if (ForbiddenAreaCache.Instance.Items.ContainsKey(filter.fbcode))
     //    {
     //        fbname = ForbiddenAreaCache.Instance.Items[filter.fbcode].ForbiddenAreaName;
     //    }
     //    else
     //    {
     //        filter.forbidden = false;
     //    }
     //}
     //if (filter.forbidden)
     //{
     //    containfilters.Add(new ContainFilterNode() { FieldName = string.Format("{0}{1}", EpgIndexNode.ForbiddenCode, pindx), Text = fbname.ToLower() });
     //}
     var node = new SearchNode();
     if (filter.lang == CustomArray.LanguageArray[1])
         node.IsNoPaging = true;
     node.Key = filter.k;
     node.Pindex = pindx;
     node.Queries = query;
     node.Fields = fields;
     node.Occurs = EpgIndexNode.NameOccurs;
     node.Start = filter.s;
     node.Limit = filter.c;
     node.ContainFilters = containfilters;
     node.IndexValue = EpgIndexNode.IndexValue;
     return Searcher.DistinctSearch(TagLuceneNet.Instance.IndexDic, node, root);
 }