Skip to content

Commit

Permalink
Whoosh backend now explicitly closes searchers in an attempt to use f…
Browse files Browse the repository at this point in the history
…ewer file handles.
  • Loading branch information
toastdriven committed Dec 20, 2010
1 parent a26a5c7 commit 81a803f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 9 additions & 1 deletion haystack/backends/whoosh_backend.py
Expand Up @@ -305,6 +305,8 @@ def search(self, query_string, sort_by=None, start_offset=0, end_offset=None,
if len(registered_models) > 0:
narrow_queries.add('%s:(%s)' % (DJANGO_CT, ' OR '.join(registered_models)))

narrow_searcher = None

if narrow_queries is not None:
# Potentially expensive? I don't see another way to do it in Whoosh...
narrow_searcher = self.index.searcher()
Expand Down Expand Up @@ -367,7 +369,13 @@ def search(self, query_string, sort_by=None, start_offset=0, end_offset=None,
'spelling_suggestion': None,
}

return self._process_results(raw_page, highlight=highlight, query_string=query_string, spelling_query=spelling_query)
results = self._process_results(raw_page, highlight=highlight, query_string=query_string, spelling_query=spelling_query)
searcher.close()

if hasattr(narrow_searcher, 'close'):
narrow_searcher.close()

return results
else:
if getattr(settings, 'HAYSTACK_INCLUDE_SPELLING', False):
if spelling_query:
Expand Down
2 changes: 0 additions & 2 deletions tests/run_all_tests.sh
Expand Up @@ -12,8 +12,6 @@ django-admin.py test solr_tests --settings=solr_settings
echo ""

echo "** WHOOSH **"
# For Mac OS X and because Whoosh creates a large number of files...
ulimit -n 2000
django-admin.py test whoosh_tests --settings=whoosh_settings
echo ""

Expand Down

0 comments on commit 81a803f

Please sign in to comment.