vnc-dungnh / lucene-silverstripe-plugin

Automatically exported from code.google.com/p/lucene-silverstripe-plugin
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Don't cache results. Or clear the cache when the index is updated #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Steps to reproduce the problem:
- Run in Dev mode
- Add a new document containing a unique search term
- Search for the unique search term
- Delete the document
- Repeat the search
- Get the following error:

[User Error] Uncaught Zend_Search_Lucene_Exception: Document id is out of the 
range.
GET /silverstripe/home/ZendSearchLuceneForm?Search=test2&action_results=
Line 1108 in C:\Inetpub\wwwroot\silverstripe\lucene\code\Zend\Search\Lucene.php

The error happens because in Dev mode, cached search results are used, but the 
cache is not cleared when indexes are updated.

ZendSearchLuceneWrapper::find caches the search in the session using 
SessionSearchCache.

The simplest fix is to simply disable cacheing.  In 
ZendSearchLuceneWrapper.php, in the find() function, comment out or delete...

      $hits = (Director::isDev() ? SessionSearchCache::getCached($query) : false);
        if ( ! $hits ) {

...and...

                SessionSearchCache::cache($query, $hits);

...and the closing brace...

        }

Maybe this is a feature that's still under development, which is why it's only 
active in Dev mode.  However, this is a hurdle for other developers working in 
Dev mode, who may hit the error then drop the module or waste time trying to 
debug it.  Better to leave SessionSearchCache in a branch, or call a static 
function in _config.php that enables the feature.

Alternatively, a fix would be to clear the cache whenever the index is updated.

Original issue reported on code.google.com by julian.p...@incharge.co.uk on 5 Jul 2012 at 9:02

GoogleCodeExporter commented 8 years ago
Thanks for posting the fix for this issue. There doesn't seem to be any major 
benefit to caching the index file in the session while in dev mode and not on 
live. It also obviously confuses us developers :)

I second the idea of flushing the session cache when the index is updated if 
there is a major performance benefit of caching the index within the session.

Original comment by LKasz...@gmail.com on 15 Aug 2012 at 3:16