lucene .net在哪里缓存搜索结果?

时间:2021-07-29 03:04:52

I'm trying to figure out where Lucene stores the cached query results, and how it's configured to do so - and how long it caches for.

This is for an ASP.NET 3.5 solution.

I'm getting this problem:
If I run a search and sort the result by a particular product field, it seems to work the very first time each search and sort combination is used. If I then go in and change some product attributes, reindex and run the same search and sort, I get the products returned in the same order as the very first result.

我试图找出Lucene存储缓存查询结果的位置,以及如何配置它以及它缓存多长时间。这适用于ASP.NET 3.5解决方案。我遇到了这个问题:如果我运行搜索并按特定产品字段对结果进行排序,它似乎在第一次使用每个搜索和排序组合时都有效。如果我然后进入并更改一些产品属性,重新索引并运行相同的搜索和排序,我会按照与第一个结果相同的顺序返回产品。

example

Product A is named: foo
Product B is named: bar

For the first search, sort by name desc. This results in:

产品A命名为:foo产品B命名为:bar对于第一次搜索,按名称desc排序。这导致:

  1. Product A
  2. Product B


Now mix up the data a bit:

现在混淆数据:

  1. Change names to:
    Product A named: bar
    Product B named: foo
  2. 将名称更改为:产品A命名:bar产品B命名为:foo

  3. reindex
  4. verify that the index contains the changes for these two products.
  5. 验证索引是否包含这两个产品的更改。

  6. search

Result:

  1. Product A
  2. Product B

Since I changed the alphabetical order of the names, I expected:

由于我更改了名称的字母顺序,我预计:

  1. Product B
  2. Product A

So I think that Lucene is caching the search results. (Which, btw, is a very good thing.) I just need to know where/how to clear these results. I've tried deleting the index files and doing an IISreset to clear the memory, but it seems to have no effect. So I'm thinking there is another set of Lucene files outside of the indexes that Lucene uses for caching.

所以我认为Lucene正在缓存搜索结果。 (顺便说一句,顺便说一句,这是一件非常好的事情。)我只需要知道在哪里/如何清除这些结果。我已经尝试删除索引文件并执行IISreset来清除内存,但它似乎没有任何效果。所以我认为Lucene用于缓存的索引之外还有另一组Lucene文件。

EDIT

I just found out that you must create the index for field you wish to sort on as un-tokenized. I had the field as tokenized, so sorting didn't work.

我刚刚发现你必须为你想要排序的字段创建索引作为非标记化。我将字段标记为已标记,因此排序不起作用。

1 个解决方案

#1


Lucene.net has a simple mechanism for caching, by using QueryFilters. You need to close and and re open an IndexSearcher when a change is made to your index and you want to reflect the changes of it

Lucene.net使用QueryFilters有一个简单的缓存机制。当您对索引进行更改并希望反映其更改时,您需要关闭并重新打开IndexSearcher

#1


Lucene.net has a simple mechanism for caching, by using QueryFilters. You need to close and and re open an IndexSearcher when a change is made to your index and you want to reflect the changes of it

Lucene.net使用QueryFilters有一个简单的缓存机制。当您对索引进行更改并希望反映其更改时,您需要关闭并重新打开IndexSearcher