예제 #1
0
        protected static List <Task <QueryContainer <CMFAQ> > > GetFAQTask(string q, int timeout, string domain = null)
        {
            Faq faq = new Faq();
            List <Task <QueryContainer <CMFAQ> > > taskList = new List <Task <QueryContainer <CMFAQ> > >();

            if (!string.IsNullOrEmpty(domain))
            {
                taskList.Add(TimedTask.CallWithTimeoutAsync(timeout, () => new Faq().Get(q, domain), null, null));
            }
            else
            {
                List <string> dList = faq.GetDomain();
                if (dList == null)
                {
                    return(taskList);
                }
                DomainMapUnit confine = GetConfigLimit("Library");
                if (confine != null && confine.FAQEX != null && confine.FAQEX.Count > 0)
                {
                    dList = dList.Except(confine.FAQEX).ToList <string>();
                }
                foreach (var d in dList)
                {
                    taskList.Add(TimedTask.CallWithTimeoutAsync(timeout, () => new Faq().Get(q, d), null, null));
                }
            }
            return(taskList);
        }
예제 #2
0
        private static DomainMapUnit GetConfigLimit(string key)
        {
            QueryLimit    qconfig = new QueryLimit().Get();
            DomainMapUnit confine = null;

            if (qconfig != null && qconfig.DomainMap.ContainsKey(key))
            {
                confine = qconfig.DomainMap[key];
            }
            return(confine);
        }
예제 #3
0
        public async Task <ExistAnswer> IsExistAnswer(string q)
        {
            CBase.Log.TimeWatchLog tlogTotal = new CBase.Log.TimeWatchLog();
            ExistAnswer            ea        = new ExistAnswer();

            ea.result     = false;
            ea.AnswerType = new List <string>();
            if (string.IsNullOrWhiteSpace(q))
            {
                ea.error = "问题参数为空,请传入问题参数";
                return(ea);
            }

            List <Task <bool> > tFaqList = null;

            try
            {
                DomainMapUnit confine = GetConfigLimit("Library");

                Domain.Intent intent = new Answer().GetIntent(q);

                Task <bool>         kb       = null;
                List <Task <bool> > taskList = new List <Task <bool> >();
                Task <bool>         tFaq_net = null;
                kb = Task.Run <bool>(() =>
                {
                    var isExistKB = new KB().IsExist(intent);
                    return(isExistKB);
                });
                //kb = TimedTask.CallWithTimeoutAsync(timeout, () => new KB().IsExist(intent), null, null);
                List <string> filterDomain = new List <string>();
                if (confine != null && confine.FAQEX != null && confine.FAQEX.Count > 0)
                {
                    filterDomain = confine.FAQEX;
                }
                tFaqList = GetFAQTaskExist(q, timeout, filterDomain);

                //tFaq_net = TimedTask.CallWithTimeoutAsync(timeout, () => new Faq_net().IsExist(q), null, null);
                tFaq_net = Task.Run <bool>(() =>
                {
                    return(new Faq_net().IsExist(q));
                });

                //Task<bool> sg = Task.Run<bool>(() =>
                //{
                //    int recStart = 0;
                //    int recCount = 0;
                //    InitPageParam(null, null, out recStart, out recCount);

                //    ClientInfo cinfo = new ClientInfo();
                //    if (confine == null || confine.SG == null || confine.SG.Count == 0)
                //    {
                //        QueryContainer<CMAnswer>  qcAnswer = TimedTask.CallActionWithTimeoutSync(timeout, () => new Answer().Get(q, recStart, recCount), q, cinfo);
                //        return qcAnswer != null && qcAnswer.MetaList != null && qcAnswer.MetaList.Count > 0;
                //    }
                //    else
                //    {
                //        foreach (string domain in confine.KB)
                //        {
                //            QueryContainer<CMAnswer> qcAnswer = TimedTask.CallActionWithTimeoutSync(timeout, () => new Answer(domain).Get(q, recStart, recCount,domain), q, cinfo);
                //            if(qcAnswer != null && qcAnswer.MetaList != null && qcAnswer.MetaList.Count > 0)
                //            {
                //                return true;
                //            }
                //        }
                //        return false;
                //    }

                //});

                //await Task.WhenAll(new Task<bool>[]{kb,faq,sg});
                //if (faq != null)
                //    taskList.Add(faq);

                taskList.AddRange(tFaqList);
                taskList.Add(tFaq_net);

                if (kb != null)
                {
                    taskList.Add(kb);
                }

                await Task.WhenAll(taskList);

                ea.TimeSpan = tlogTotal.Debug();
                tlogTotal.Write("IsExistAnswer");

                if (kb != null && kb.Result == true)
                {
                    ea.AnswerType.Add("kb");
                }
                if (GetFAQExist(tFaqList))
                {
                    ea.AnswerType.Add("faq");
                }
                if (tFaq_net != null && tFaq_net.Result == true)
                {
                    ea.AnswerType.Add("faqnet");
                }
                //记录有无答案日志
                try
                {
                    ClientInfo cinfo = new ClientInfo()
                    {
                        UserName = CommonHelper.GetUserName(),
                        IP       = CommonHelper.GetClientIP()
                    };
                    cinfo.Type = ea.AnswerType.Count == 0 ? ContentLogType.无答案 : ContentLogType.答案;
                    CommonFunc.WriteContentLog(cinfo, q);
                }
                catch (Exception ex)
                {
                    CBase.Log.Logger.Error(ex);
                }


                //if(sg.Result==true)
                //{
                //    ea.AnswerType.Add("sg");
                //}

                if (ea.AnswerType.Count > 0)
                {
                    ea.result = true;
                    return(ea);
                }
                else
                {
                    ea.result = false;
                    return(ea);
                }
            }
            catch (Exception e)
            {
                ea.error = "查询时出现错误:" + e.Message;
                return(ea);
            }
        }