我心中的核心组件(可插拔的AOP)~第十四回 全文检索架构~终于设计了一个自己满意的Lucene架构

回到目录

我架构的以lucene为技术的全文检索分为lucene检索模块,索引文件生成器和WEB检索测试三个部分组成

结构如下:

image

lucene模块它由通过检索项和几个具体检索业务子项目组成

通过功能项目结构为:

image

其中的一个子项目结构为

image

子项目只负责自己业务的实现,createIndexFile这个类型主要实现的是建立索引,而FieldKeys类型主要是设置表字段

在WEB层测试时可以通过这段代码进行调用


public class HomeController : ControllerBase
   {
       Web.Helper.UIHelper ui;

       public ActionResult Index(string keyword, string categoryName, int? page)
       {
           string _keyword = (keyword ?? string.Empty).Trim();
           System.Collections.Specialized.NameValueCollection nv = new System.Collections.Specialized.NameValueCollection();
           nv.Add("keyword", _keyword);
           ui = new Web.Helper.UIHelper(Request.Url.ToString(), nv);
           ViewData["Message"] = "欢?迎-使1用? ASP.NET MVC!";
           SearchResult result = GetDataFromIndex(new QueryTerm { KeyWord = _keyword, CategoryName = categoryName, PageSize = 1 });
           ViewData["result"] = result;
           ViewData["page"] = ui.GetPage(page ?? 1, 10, result.Total);
           return View();
       }

而从索引文件反序列化的代码被我抽象到controller的基类中,如下

  
public class ControllerBase : Controller
    {
        /// <summary>
        /// 调÷用?WIN API方?法¨
        /// 非?托D管ü资ê源′
        /// </summary>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <param name="def"></param>
        /// <param name="retVal"></param>
        /// <param name="size"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        /// <summary>
        /// 得?到?索÷引y文?件t路·径?
        /// </summary>
        /// <param name="configPath"></param>
        /// <returns></returns>
        protected string GetIndexPath(string configPath)
        {
            StringBuilder sbPath = new StringBuilder(500);
            GetPrivateProfileString("Index", "Path", "", sbPath, 500, configPath);

            return sbPath.ToString();
        }

        /// <summary>
        /// 从ó索÷引y文?件t中D重?到?数y据Y,?根ù据Y关?键ü字?
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        protected virtual SearchResult GetDataFromIndex(QueryTerm queryTerm)
        {
            QueryTerm term = new QueryTerm();
            term.KeyWord = queryTerm.KeyWord;
            term.PageIndex = queryTerm.PageSize;
            term.CategoryName = queryTerm.CategoryName;
            term.PageSize = 10;
             Search searcher = new Search(this.GetIndexPath(ConfigurationManager.AppSettings["Res_Item_IndexDocumentsPath"]), term);
            return searcher.GetSearchResult();
        }
    }
}

 回到目录

 
posted @ 2012-02-18 23:38  张占岭  阅读(1735)  评论(3编辑  收藏  举报