コード例 #1
0
ファイル: AxIndexer.cs プロジェクト: liusj666/AxNew
        /// <summary>
        /// 删除文件的索引
        /// </summary>
        /// <param>文件标识符</param>
        /// <param>人员权限</param>
        /// <returns></returns>
        public bool DeleteIndex(string fileId)
        {
            AbstractFileBase fileBase = new TextFileInfo();

            fileBase.FileId = fileId;

            IIndexManager indexManager = new IndexManagerFactory().Create();

            return(indexManager.DeleteIndex(fileBase));
        }
コード例 #2
0
ファイル: AxIndexer.cs プロジェクト: liusj666/AxNew
        /// <summary>
        /// 查询索引
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param>人员权限</param>
        /// <returns></returns
        public ResultSet SearchIndex(string key, int pageNum, string userHandle, string lastFileId, string nextFileId)
        {
            LibHandle handle = LibHandleCache.Default.GetCurrentHandle(userHandle) as LibHandle;
            //页大小
            int           pageSize          = 8;
            IHightLighter hightLighter      = new HightLighterFactory().Create();
            IIndexManager indexManager      = new IndexManagerFactory().Create();
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("content", key);
            SearchResult result = null;

            if (string.IsNullOrEmpty(lastFileId) && string.IsNullOrEmpty(nextFileId))//第一次查询
            {
                result = (SearchResult)indexManager.SearchIndex(dic, pageNum, pageSize, handle);
            }
            else if (string.IsNullOrEmpty(lastFileId))//上一页
            {
                result = (SearchResult)indexManager.SearchPrevIndex(dic, pageNum, pageSize, handle, nextFileId);
            }
            else if (string.IsNullOrEmpty(nextFileId))//下一页
            {
                result = (SearchResult)indexManager.SearchNextIndex(dic, pageNum, pageSize, handle, lastFileId);
            }
            ResultSet resultSet = new ResultSet();

            resultSet.SearchTime   = result.SearchTime;
            resultSet.PageNum      = pageNum;
            resultSet.ResultsCount = result.TotalHits;
            resultSet.PageCount    = (resultSet.ResultsCount - 1) / pageSize + 1;
            DirLinkAddress dirlink;

            foreach (var item in result.Docs)
            {
                AbstractFileBase fileBase = hightLighter.InitHightLight(dic, item);
                FileInfoItem     info     = new FileInfoItem()
                {
                    FileId   = fileBase.FileId,
                    Contents = fileBase.Content
                };
                dirlink       = new DirLinkAddress(fileBase.FileId);
                info.FileName = dirlink.DocName;
                info.DirId    = dirlink.DirID;
                info.DirType  = dirlink.DirType;
                info.Path     = dirlink.DirNameLink;
                resultSet.FileInfoItems.Add(info);
            }
            if (resultSet.FileInfoItems.Count == 0)
            {
                return(null);
            }
            return(resultSet);
        }
コード例 #3
0
ファイル: AxIndexer.cs プロジェクト: liusj666/AxNew
        /// <summary>
        /// 根据文件创建索引
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        //private bool CreateIndex(string fileName)
        //{
        //    if (File.Exists(fileName))
        //    {
        //        LibDataAccess dataAccess = new LibDataAccess();

        //        FileInfo info = new FileInfo(fileName);
        //        AbstractFileBase fileBase = new TextFileInfo();
        //        #region 根据文件路径查找
        //        string sql = string.Format("select DOCID from DMDOCUMENT where SAVEPATH = {0}", LibStringBuilder.GetQuotString(fileName));
        //        fileBase.FileId = dataAccess.ExecuteScalar(sql).ToString();
        //        object ret = dataAccess.ExecuteScalar(string.Format("select ISFULLINDEX from DMDOCUMENT where DOCID = {0}", LibStringBuilder.GetQuotString(fileBase.FileId)));
        //        if (LibSysUtils.ToInt32(ret) == 1)
        //        {
        //            return true;
        //        }
        //        #endregion
        //        //fileBase.FileName = info.Name;
        //        //fileBase.FilePath = info.DirectoryName;
        //        //fileBase.UpLoadPersonId = "zhangsan";
        //        //fileBase.CreateTime = DateTime.Now.ToString();
        //        fileBase.Content = ReadContent(fileName, info.Extension.Trim());

        //        IIndexManager indexManager = new IndexManagerFactory().Create();
        //        return indexManager.CreateIndex(fileBase);
        //    }
        //    if (Directory.Exists(fileName))
        //    {
        //        foreach (var item in new DirectoryInfo(fileName).GetFiles())
        //        {
        //            CreateIndex(item.FullName);
        //        }
        //        foreach (var item in new DirectoryInfo(fileName).GetDirectories())
        //        {
        //            CreateIndex(item.FullName);
        //        }
        //    }
        //    return true;
        //}

        /// <summary>
        /// 为文件添加索引
        /// </summary>
        /// <param>文件标识符</param>
        /// <param>人员权限</param>
        /// <returns></returns>
        public bool AddIndex(string fileId)
        {
            AbstractFileBase fileBase = new TextFileInfo();

            fileBase.FileId = fileId;
            #region 根据文件ID查找文件路径
            DirLinkAddress dirlink  = new DirLinkAddress(fileId);
            string         fileName = dirlink.GetDocFullPath(-1);
            #endregion
            //fileBase.FileName = info.Name;
            //fileBase.FilePath = info.DirectoryName;
            //fileBase.UpLoadPersonId = "zhangsan";
            //fileBase.CreateTime = DateTime.Now.ToString();
            fileBase.Content = ReadContent(fileName, dirlink.DocType);

            IIndexManager indexManager = new IndexManagerFactory().Create();
            return(indexManager.CreateIndex(fileBase));
        }