我心中的核心组件(可插拔的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 @   张占岭  阅读(1735)  评论(3编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示