Exemplo n.º 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;
     }
 }
Exemplo n.º 2
0
 public static void DeleteVideo(LiveVideoNode video, IndexBase index)
 {
     var terms = new List<Term>(video.Items.Count + 1);
     terms.Add(new Term(LiveEpgNode.ChannelId, video.Main.ChannelID.ToString()));
     foreach (var parade in video.Items)
     {
         terms.Add(new Term(LiveEpgNode.ParadeId, parade.ID.ToString()));
     }
     index.DeleteDocument(terms.ToArray());
 }
Exemplo n.º 3
0
 public static void InsertVideo(LiveVideoNode video, IndexBase index)
 {
     var builder = new StringBuilder();
     foreach (var authnode in video.PlatForms)
     {
         builder.Append(VideoNodeKeyArray.Instance.Items[VideoNodeKeyArray.Instance.FindKey(authnode.PlatformName, 0, authnode.Licence)]);
         builder.Append(SplitArray.DH);
     }
     if (builder.Length < 2)
         return; 
     var nodes = CreateNewNode(video, builder.ToString());
     index.InsertIndex(nodes);
 }
Exemplo n.º 4
0
        public static void AddTag(TagNode tag, string dimension, IndexBase index)
        {
            var builder = new StringBuilder();
            //Dictionary<int, string[]> fbcodes = new Dictionary<int, string[]>(tag.Channels.Keys.Count);
            foreach (var plat in tag.Channels.Keys)
            {
                var indexx = VideoNodeKeyArray.Instance.Items[VideoNodeKeyArray.Instance.FindKey(plat.PlatForm, 0, plat.Auth)];
                builder.Append(indexx);
                builder.Append(SplitArray.DH);
                //IEnumerable<string> fbcode = null;
                //var query = tag.Channels[plat].Select(v => ListCache.Instance.Dictionary[v].ForbiddenAreas);
                //foreach (var q in query)
                //{
                //    if (fbcode == null)
                //        fbcode = q;
                //    else
                //        fbcode = fbcode.Intersect(q);
                //}
                //fbcodes[indexx] = fbcode.ToArray();
            }
            if (builder.Length < 2)
                return;
            var node = new IndexNode();
            var indexnames = new List<KeyValuePair<string, string>>(3);
            var name = new KeyValuePair<string, string>(EpgIndexNode.Name, tag.Language[CustomArray.LanguageArray[0]].Title);
            var cnname = new KeyValuePair<string, string>(EpgIndexNode.CnName, string.Format("{0}{1}", tag.Language[CustomArray.LanguageArray[0]].Title, SplitArray.IndexCnName));
            var pindex = new KeyValuePair<string, string>(EpgIndexNode.PlatformIndex, string.Format("{0}{1}", builder.Remove(builder.Length - 1, 1), SplitArray.IndexFlag));
            //foreach (var fbcode in fbcodes)
            //{
            //    var fb = new KeyValuePair<string, string>(string.Format("{0}{1}", EpgIndexNode.ForbiddenCode, fbcode.Key), string.Format("{0},{1}", string.Join(",", ForbiddenAreaCache.Instance.ForbiddenNames.Except(fbcode.Value).ToArray()), SplitArray.IndexFlag));
            //    indexnames.Add(fb);
            //}
            indexnames.Add(name);
            indexnames.Add(cnname);
            indexnames.Add(pindex);

            var indexvalues = new List<KeyValuePair<string, string>>(2);
            var vid = new KeyValuePair<string, string>(EpgIndexNode.IndexValue, tag.Language[CustomArray.LanguageArray[0]].Title);
            var dimen = new KeyValuePair<string, string>(EpgIndexNode.Flags, dimension);
            indexvalues.Add(vid);
            indexvalues.Add(dimen);

            node.IndexNames = indexnames;
            node.IndexValues = indexvalues;

            LuceneNetUtils.AddIndex(node, index);
        }
Exemplo n.º 5
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;
     }
 }
Exemplo n.º 6
0
        public static void AddVideo(VideoNode video, IndexBase indexBase)
        {
            var builder = new StringBuilder();
            foreach (var authnode in video.PlatForms)
            {
                if (authnode.SearchTypeIndexList.Contains(video.Type))
                {
                    builder.Append(VideoNodeKeyArray.Instance.Items[VideoNodeKeyArray.Instance.FindKey(authnode.PlatformName, 0, authnode.Licence)]);
                    builder.Append(SplitArray.DH);
                }
            }
            if (builder.Length < 2)
                return;
            
            var node = new IndexNode();
            var indexnames = new List<KeyValuePair<string, string>>(10);
            var name = new KeyValuePair<string, string>(EpgIndexNode.Name, video.Language[CustomArray.LanguageArray[0]].ChannelName);
            var cnname = new KeyValuePair<string, string>(EpgIndexNode.CnName, string.Format("{0}{1}", video.Language[CustomArray.LanguageArray[0]].ChannelName, SplitArray.IndexCnName));
            var flag = video.Flags.FormatListToStr(SplitArray.Line, 16);
            var catalog = new KeyValuePair<string, string>(EpgIndexNode.Catalog, string.Format("{0}{1}", video.Language[CustomArray.LanguageArray[0]].CatalogTags, SplitArray.IndexFlag));
            var area = new KeyValuePair<string, string>(EpgIndexNode.Area, string.Format("{0}{1}", video.Language[CustomArray.LanguageArray[0]].AreaTags, SplitArray.IndexFlag));
            var year = new KeyValuePair<string, string>(EpgIndexNode.Year, string.Format("{0}{1}", video.YearTags, SplitArray.IndexFlag));
            var act = new KeyValuePair<string, string>(EpgIndexNode.Act, string.Format("{0}{1}", video.BKInfo.Actors, SplitArray.IndexFlag));
            var director = new KeyValuePair<string, string>(EpgIndexNode.Director, string.Format("{0}{1}", video.BKInfo.Directors, SplitArray.IndexFlag));
            var flags = new KeyValuePair<string, string>(EpgIndexNode.Flags, flag);
            var pindex = new KeyValuePair<string, string>(EpgIndexNode.PlatformIndex, string.Format("{0}{1}", builder.Remove(builder.Length - 1, 1), SplitArray.IndexFlag));
            var fbcode = new KeyValuePair<string, string>(EpgIndexNode.ForbiddenCode, string.Format("{0},{1}", string.Join(",", ForbiddenAreaCache.Instance.ForbiddenNames.Except(video.ForbiddenAreas).ToArray()), SplitArray.IndexFlag));
            indexnames.Add(name);
            indexnames.Add(cnname);
            indexnames.Add(catalog);
            indexnames.Add(area);
            indexnames.Add(year);
            indexnames.Add(act);
            indexnames.Add(director);
            indexnames.Add(flags);
            indexnames.Add(pindex);
            indexnames.Add(fbcode);

            var indexvalues = new List<KeyValuePair<string, string>>(6);
            var vid = new KeyValuePair<string, string>(EpgIndexNode.IndexValue, video.Main.ChannelID.ToString());
            var vipflag = new KeyValuePair<string, string>(EpgIndexNode.VipFlag, video.Main.VipFlag.ToString());
            var tabletype = new KeyValuePair<string, string>(EpgIndexNode.TableType, video.Main.TableType.ToString());
            var screen = new KeyValuePair<string, string>(EpgIndexNode.Screen, video.Main.TableType == 1 ? "1" : "0");
            var group = new KeyValuePair<string, string>(EpgIndexNode.IsGroup, video.IsGroup ? "1" : "0");
            var type = new KeyValuePair<string, string>(EpgIndexNode.Type, video.Type.ToString());
            indexvalues.Add(vid);
            indexvalues.Add(vipflag);
            indexvalues.Add(tabletype);
            indexvalues.Add(screen);
            indexvalues.Add(group);
            indexvalues.Add(type);

            var indexnumerices = new List<KeyValuePair<string, int>>(3);
            var bitrate = new KeyValuePair<string, int>(EpgIndexNode.BitrateRange, video.Main.BitRate);
            var hight = new KeyValuePair<string, int>(EpgIndexNode.HightRange, video.Main.VideoHeight);
            var width = new KeyValuePair<string, int>(EpgIndexNode.WidthRange, video.Main.VideoWidth);
            indexnumerices.Add(bitrate);
            indexnumerices.Add(hight);
            indexnumerices.Add(width);

            node.IndexNames = indexnames;
            node.IndexValues = indexvalues;
            node.IndexNumerices = indexnumerices;

            LuceneNetUtils.AddIndex(node, indexBase);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 添加索引
 /// </summary>
 public static void AddIndex(List<IndexNode> nodes, IndexBase index)
 {
     foreach (var node in nodes)
         index.AddIndex(CreateDoucment(node));
 }
Exemplo n.º 8
0
 /// <summary>
 /// 添加索引
 /// </summary>
 public static void AddIndex(IndexNode node, IndexBase index)
 {
     index.AddIndex(CreateDoucment(node));
 }
Exemplo n.º 9
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();
     }
 }
Exemplo n.º 10
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();
            }
        }
Exemplo n.º 11
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;
     }
 }