views:

517

answers:

1

Hi,
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.

example

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

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

  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. reindex
  3. verify that the index contains the changes for these two products.
  4. 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.

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.

A: 

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

Raj
would doing an IISreset not clear it? Or is it because it's persisted in a file, I have to open and close the IndexSearcher as then the file gets rewritten somehow?
Lanceomagnifico
I just checked where the IndexSearchers are being used - they are recreated for every query. There aren't any Close() methods used - they are just left to close when out of scope.
Lanceomagnifico