<tfoot id='4e9O5'></tfoot>

<small id='4e9O5'></small><noframes id='4e9O5'>

<legend id='4e9O5'><style id='4e9O5'><dir id='4e9O5'><q id='4e9O5'></q></dir></style></legend>

      <bdo id='4e9O5'></bdo><ul id='4e9O5'></ul>
    1. <i id='4e9O5'><tr id='4e9O5'><dt id='4e9O5'><q id='4e9O5'><span id='4e9O5'><b id='4e9O5'><form id='4e9O5'><ins id='4e9O5'></ins><ul id='4e9O5'></ul><sub id='4e9O5'></sub></form><legend id='4e9O5'></legend><bdo id='4e9O5'><pre id='4e9O5'><center id='4e9O5'></center></pre></bdo></b><th id='4e9O5'></th></span></q></dt></tr></i><div id='4e9O5'><tfoot id='4e9O5'></tfoot><dl id='4e9O5'><fieldset id='4e9O5'></fieldset></dl></div>

      在 ASP.NET MVC 站点中正确构建 Lucene.Net 使用

      时间:2023-09-14
      <tfoot id='pAefp'></tfoot>

      • <legend id='pAefp'><style id='pAefp'><dir id='pAefp'><q id='pAefp'></q></dir></style></legend>

        1. <i id='pAefp'><tr id='pAefp'><dt id='pAefp'><q id='pAefp'><span id='pAefp'><b id='pAefp'><form id='pAefp'><ins id='pAefp'></ins><ul id='pAefp'></ul><sub id='pAefp'></sub></form><legend id='pAefp'></legend><bdo id='pAefp'><pre id='pAefp'><center id='pAefp'></center></pre></bdo></b><th id='pAefp'></th></span></q></dt></tr></i><div id='pAefp'><tfoot id='pAefp'></tfoot><dl id='pAefp'><fieldset id='pAefp'></fieldset></dl></div>

            • <bdo id='pAefp'></bdo><ul id='pAefp'></ul>

              <small id='pAefp'></small><noframes id='pAefp'>

                  <tbody id='pAefp'></tbody>
                本文介绍了在 ASP.NET MVC 站点中正确构建 Lucene.Net 使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在构建一个 ASP.NET MVC 站点,我计划在其中使用 Lucene.Net.我已经设想了一种构建 Lucene 使用的方法,但不确定我计划的架构是否可行且高效.

                I'm building an ASP.NET MVC site where I plan to use Lucene.Net. I've envisioned a way to structure the usage of Lucene, but not sure whether my planned architecture is OK and efficient.

                • 关于 Global.asax 中的 Application_Start 事件:我检查文件系统上是否存在索引 - 如果不存在,我创建它并用从数据库.
                • 提交新内容时:我创建一个IndexWriter,填写一个文档,写入索引,最后处置IndexWriter.IndexWriters 没有被重用,因为我无法想象在 ASP.NET MVC 应用程序中这样做的好方法.
                • 编辑内容时:我重复提交新内容时的相同过程,只是我先删除旧内容,然后添加编辑内容.
                • 当用户搜索内容时:我检查 HttpRuntime.Cache 以查看用户在过去 5 分钟内是否已经搜索过这个词 - 如果有,我会返回这些结果;否则,我创建一个 IndexReader,构建并运行查询,将结果放入 HttpRuntime.Cache,返回给用户,最后处置 IndexReader.IndexReaders 再次没有被重用.
                • On Application_Start event in Global.asax: I check for the existence of the index on the file system - if it doesn't exist, I create it and fill it with documents extracted it from the database.
                • When new content is submitted: I create an IndexWriter, fill up a document, write to the index, and finally dispose of the IndexWriter. IndexWriters are not reused, as I can't imagine a good way to do that in an ASP.NET MVC application.
                • When content is edited: I repeat the same process as when new content is submitted, except that I first delete the old content and then add the edits.
                • When a user searches for content: I check HttpRuntime.Cache to see if a user has already searched for this term in the last 5 minutes - if they have, I return those results; otherwise, I create an IndexReader, build and run a query, put the results in HttpRuntime.Cache, return them to the user, and finally dispose of the IndexReader. Once again, IndexReaders aren't reused.
                • 这是一个好的结构吗 - 我该如何改进它?
                • 是否有任何性能/效率问题我应该注意?
                • 另外,不重用 IndexReaders 和 IndexWriters 是否有很大的代码味道?
                • Is that a good structure - how can I improve it?
                • Are there any performance/efficiency problems I should be aware of?
                • Also, is not reusing the IndexReaders and IndexWriters a huge code smell?

                推荐答案

                你所有三个问题的答案都是一样的:重用你的读者(也可能是你的作者).您可以使用 singleton 模式来执行此操作(即将您的阅读器/作者声明为公共静态).Lucene 的 FAQ 告诉你同样的事情:分享你的读者,因为第一个查询真的很慢.Lucene 会为您处理所有锁定,因此您确实没有理由不拥有共享阅读器.

                The answer to all three of your questions is the same: reuse your readers (and possibly your writers). You can use a singleton pattern to do this (i.e. declare your reader/writer as public static). Lucene's FAQ tells you the same thing: share your readers, because the first query is reaaalllyyyy slow. Lucene handles all the locking for you, so there is really no reason why you shouldn't have a shared reader.

                让你的作家留在身边可能是最简单的(使用 NRT 模型)从中获得读者.如果您很少写入索引,或者您对速度的需求不大,那么每次都打开您的 writer 可能是可以的.我就是这么做的.

                It's probably easiest to just keep your writer around and (using the NRT model) get the readers from that. If it's rare that you are writing to the index, or if you don't have a huge need for speed, then it's probably OK to open your writer each time instead. That is what I do.

                添加代码示例:

                public static IndexWriter writer = new IndexWriter(myDir);
                
                public JsonResult SearchForStuff(string query)
                {
                    IndexReader reader = writer.GetReader();
                    IndexSearcher search = new IndexSearcher(reader);
                    // do the search
                }
                

                这篇关于在 ASP.NET MVC 站点中正确构建 Lucene.Net 使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                <tfoot id='qnPRM'></tfoot>
                <i id='qnPRM'><tr id='qnPRM'><dt id='qnPRM'><q id='qnPRM'><span id='qnPRM'><b id='qnPRM'><form id='qnPRM'><ins id='qnPRM'></ins><ul id='qnPRM'></ul><sub id='qnPRM'></sub></form><legend id='qnPRM'></legend><bdo id='qnPRM'><pre id='qnPRM'><center id='qnPRM'></center></pre></bdo></b><th id='qnPRM'></th></span></q></dt></tr></i><div id='qnPRM'><tfoot id='qnPRM'></tfoot><dl id='qnPRM'><fieldset id='qnPRM'></fieldset></dl></div>

                1. <legend id='qnPRM'><style id='qnPRM'><dir id='qnPRM'><q id='qnPRM'></q></dir></style></legend>

                        <bdo id='qnPRM'></bdo><ul id='qnPRM'></ul>

                        <small id='qnPRM'></small><noframes id='qnPRM'>

                          <tbody id='qnPRM'></tbody>