Пример #1
0
        /// <summary>
        /// 添加数据更新索引任务
        /// </summary>
        /// <param name="job"></param>
        public void AddJobs(IndexData job)
        {
            if (threadIndexUpData == null)
            {
                StartUpDataIndex();
            }
            string strLog = string.Format(@"
                            添加任务 - 数据:{0},类型:{1}。", job.Data.knowledgeGUID.ToString(), job.JobType.ToString());

            //logger.Debug(strLog);
            jobs.Enqueue(job);
        }
Пример #2
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <returns></returns>
 public bool Delete(string keyvalue)
 {
     #region 创建索引
     //创建索引
     var       updateEntity = _knowledgeRepository.FindEntity(keyvalue);
     IndexData indexData    = new IndexData();
     indexData.JobType = JobType.Remove;
     indexData.Data    = updateEntity;
     var indexManage = IndexManager.GetInstance();
     indexManage.AddJobs(indexData);
     #endregion
     return(_knowledgeRepository.Delete(t => t.knowledgeGUID == keyvalue));
 }
Пример #3
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public bool SubmitForm(KnowledgeInfoEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                //修改
                entity.knowledgeGUID = keyValue;
                entity.UpdateDate    = DateTime.Now;
                _knowledgeRepository.Update(entity);

                #region 创建索引
                //创建索引
                var       updateEntity = _knowledgeRepository.FindEntity(keyValue);
                IndexData indexData    = new IndexData();
                indexData.JobType = JobType.Up;
                indexData.Data    = updateEntity;
                var indexManage = IndexManager.GetInstance();
                indexManage.AddJobs(indexData);
                #endregion

                return(true);
            }
            else
            {
                entity.CreateById    = OperatorProvider.Provider.Current().UserId;
                entity.CreateBy      = OperatorProvider.Provider.Current().UserName;
                entity.CreateDate    = DateTime.Now;
                entity.UpdateDate    = DateTime.Now;
                entity.knowledgeGUID = Guid.NewGuid().ToString();
                entity.ViewCount     = 1;
                #region 创建索引
                //创建索引
                IndexData indexData = new IndexData();
                indexData.JobType = JobType.New;
                indexData.Data    = entity;
                var indexManage = IndexManager.GetInstance();
                indexManage.AddJobs(indexData);
                #endregion
                return(_knowledgeRepository.Insert(entity));
            }
        }
Пример #4
0
        /// <summary>
        /// 处理实际数据
        /// </summary>
        /// <param name="writer"></param>
        private void ProcessJobs()
        {
            Regex r = new Regex("<img.[^>]+[>]+", RegexOptions.ExplicitCapture);
            KnowledgeInfoEntity dataManager = new KnowledgeInfoEntity();

            while (jobs.Count != 0)
            {
                IndexData job      = jobs.Dequeue();
                string    IndexDic = __SearchAppIndexPath;
                //创建索引目录
                if (!System.IO.Directory.Exists(IndexDic))
                {
                    System.IO.Directory.CreateDirectory(IndexDic);
                }
                FSDirectory directory = FSDirectory.Open(new DirectoryInfo(IndexDic), new NativeFSLockFactory());
                bool        isUpdate  = IndexReader.IndexExists(directory);
                //logger.Debug("索引库存在状态" + isUpdate);
                if (isUpdate)
                {
                    //如果索引目录被锁定(比如索引过程中程序异常退出),则首先解锁
                    if (IndexWriter.IsLocked(directory))
                    {
                        //logger.Debug("开始解锁索引库");
                        IndexWriter.Unlock(directory);
                        //logger.Debug("解锁索引库完成");
                    }
                }
                IndexWriter writer = new IndexWriter(directory, new PanGuAnalyzer(), !isUpdate, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED);


                writer.DeleteDocuments(new Term("knowledgeGUID", job.Data.knowledgeGUID.ToString()));
                //如果是“添加任务”再添加,
                if (job.JobType == JobType.Up || job.JobType == JobType.New)
                {
                    KnowledgeInfoEntity data = job.Data;
                    /*去除为NULL数据*/
                    if (string.IsNullOrEmpty(data.Title))
                    {
                        data.Title = string.Empty;
                    }
                    if (string.IsNullOrEmpty(data.ContentNoHtml))
                    {
                        data.ContentNoHtml = string.Empty;
                    }
                    if (string.IsNullOrEmpty(data.Summary))
                    {
                        data.Summary = string.Empty;
                    }
                    if (string.IsNullOrEmpty(data.CreateBy))
                    {
                        data.CreateBy = string.Empty;
                    }

                    Document document = new Document();
                    document.Add(new Field("knowledgeGUID", data.knowledgeGUID.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    document.Add(new Field("Title", data.Title, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    document.Add(new Field("ContentNoHtml", r.Replace(data.ContentNoHtml, ""), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    document.Add(new Field("Summary", data.Summary, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    document.Add(new Field("CreateBy", data.CreateBy, Field.Store.YES, Field.Index.NOT_ANALYZED));
                    document.Add(new Field("UpdateDate", data.UpdateDate.Value.ToString("yyyy-MM-dd"), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    document.Add(new Field("ViewCount", data.ViewCount.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    document.Add(new Field("DataType", data.DataType, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    writer.AddDocument(document);
                    //logger.Debug("索引" + job.Data.DataGUID.ToString() + "完毕");
                }
                writer.Close();
                directory.Close();//不要忘了Close,否则索引结果搜不到
            }
        }