Exemplo n.º 1
0
        public static void BuildIndexThread <T>(IEnumerable <EntryDataModel <T> > entryDataModelList) where T : class, new()
        {
            try
            {
                if (entryDataModelList != null && entryDataModelList.Count() > 0)
                {
                    m_logger.Debug(string.Format("{0} BuildIndex开始", DateTime.Now));

                    List <Task> taskList    = new List <Task>();
                    TaskFactory taskFactory = new TaskFactory();
                    m_cts = new CancellationTokenSource();
                    int i = 1;
                    foreach (var entryDataModel in entryDataModelList)
                    {
                        IndexBuilderPerThread <T> prerThread = null;
                        if (entryDataModel.DataListFunc != null)
                        {
                            prerThread = new IndexBuilderPerThread <T>(entryDataModel.DataListFunc, entryDataModel.FieldModelList, i.ToString("000"), m_cts);
                        }
                        else
                        {
                            prerThread = new IndexBuilderPerThread <T>(entryDataModel.DataList, entryDataModel.FieldModelList, i.ToString("000"), m_cts);
                        }
                        m_pathSuffixList.Add(i.ToString("000"));
                        taskList.Add(taskFactory.StartNew(prerThread.Process));                        //开启一个线程   里面创建索引
                        i++;
                    }
                    taskList.Add(taskFactory.ContinueWhenAll(taskList.ToArray(), MergeIndex <T>));
                    Task.WaitAll(taskList.ToArray());
                    m_logger.Debug(string.Format("BuildIndex{0}", m_cts.IsCancellationRequested ? "失败" : "成功"));
                }
            }
            catch (Exception ex)
            {
                m_logger.Error("BuildIndex出现异常", ex);
            }
            finally
            {
                m_logger.Debug(string.Format("{0} BuildIndex结束", DateTime.Now));
            }
        }
Exemplo n.º 2
0
        public void Process()
        {
            try
            {
                m_currentThreadNum = Thread.CurrentThread.ManagedThreadId;
                m_logger.Debug(string.Format("ThreadNum={0}开始创建", m_currentThreadNum));
                ILuceneBulid <T> builder = new LuceneBulid <T>();
                bool             isFirst = true;
                if (!m_cts.IsCancellationRequested)
                {
                    IEnumerable <T> modelList = m_getDataListFunc != null?m_getDataListFunc() : null;

                    if (modelList == null)
                    {
                        modelList = m_dataList;
                    }
                    int count = modelList != null?modelList.Count() : 0;

                    if (count > 0)
                    {
                        builder.BuildIndex(modelList, m_fieldModelList, m_pathSuffix, isFirst);
                        m_logger.Debug(string.Format("ThreadNum={0}完成{1}条的创建", m_currentThreadNum, count));
                        isFirst = false;
                    }
                }
            }
            catch (Exception ex)
            {
                m_cts.Cancel();
                m_logger.Error(string.Format("ThreadNum={0}出现异常", m_currentThreadNum), ex);
            }
            finally
            {
                m_logger.Debug(string.Format("ThreadNum={0}完成创建", m_currentThreadNum));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据查询的field将keyword分词
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public List <string> AnalyzerKey(string fieldName, string keyword)
        {
            Analyzer    analyzer = new PanGuAnalyzer();
            QueryParser parser   = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, fieldName, analyzer);
            Query       query    = parser.Parse(CleanKeyword(keyword));

            if (query is TermQuery)
            {
                Term term = ((TermQuery)query).Term;
                return(new List <string> {
                    term.Text
                });
            }
            else if (query is PhraseQuery)
            {
                Term[] term = ((PhraseQuery)query).GetTerms();
                return(term.Select(t => t.Text).ToList());
            }
            else if (query is BooleanQuery)
            {
                BooleanClause[] clauses       = ((BooleanQuery)query).GetClauses();
                List <string>   analyzerWords = new List <string>();
                foreach (BooleanClause clause in clauses)
                {
                    Query childQuery = clause.Query;
                    if (childQuery is TermQuery)
                    {
                        Term term = ((TermQuery)childQuery).Term;
                        analyzerWords.Add(term.Text);
                    }
                    else if (childQuery is PhraseQuery)
                    {
                        Term[] term = ((PhraseQuery)childQuery).GetTerms();
                        analyzerWords.AddRange(term.Select(t => t.Text));
                    }
                }
                return(analyzerWords);
            }
            else
            {
                m_logger.Debug(string.Format("AnalyzerKey在解析keyword={0}的结果为new string[] { keyword } ", keyword));
                return(new List <string> {
                    keyword
                });
            }
        }
Exemplo n.º 4
0
        public void UpdateOrganisationDetails(long organisationId)
        {
            CustomLogger.Debug($"Loading organisation - OrganisationId({organisationId})");
            var organisation = dataRepository.Get <Organisation>(organisationId);

            CustomLogger.Debug($"Updating LastCheckedAgainstCompaniesHouse - OrganisationId({organisationId})");
            organisation.LastCheckedAgainstCompaniesHouse = VirtualDateTime.Now;
            dataRepository.SaveChanges();

            try
            {
                CustomLogger.Debug($"Calling CoHo API - OrganisationId({organisationId})");
                CompaniesHouseCompany organisationFromCompaniesHouse =
                    companiesHouseApi.GetCompany(organisation.CompanyNumber);

                try
                {
                    CustomLogger.Debug($"Updating SIC codes - OrganisationId({organisationId})");
                    UpdateSicCode(organisation, organisationFromCompaniesHouse);

                    CustomLogger.Debug($"Updating Address - OrganisationId({organisationId})");
                    UpdateAddress(organisation, organisationFromCompaniesHouse);

                    CustomLogger.Debug($"Updating Name - OrganisationId({organisationId})");
                    UpdateName(organisation, organisationFromCompaniesHouse);

                    CustomLogger.Debug($"Saving - OrganisationId({organisationId})");
                    dataRepository.SaveChanges();

                    CustomLogger.Debug($"Saved - OrganisationId({organisationId})");
                }
                catch (Exception ex)
                {
                    string message =
                        $"Update from Companies House: Failed to update database, organisation id = {organisationId}";
                    CustomLogger.Error(message, ex);
                }
            }
            catch (Exception ex)
            {
                string message =
                    $"Update from Companies House: Failed to get company data from companies house, organisation id = {organisationId}";
                CustomLogger.Error(message, ex);
            }
        }