Better error messages for accessing closed results

kudrom avatarkudrom created an issue

Hi, i've installed whoosh 2.5.1 with django on Linux. It works fine until i try to access the results with result[n] or result.fields(n). With python3 this is the traceback:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/kudrom/datos/django/lib/python3.3/site-packages/whoosh/searching.py", line 1030, in fields
    return self.searcher.stored_fields(self.top_n[n][1])
  File "/home/kudrom/datos/django/lib/python3.3/site-packages/whoosh/reading.py", line 667, in stored_fields
    sfs = self._perdoc.stored_fields(docnum)
  File "/home/kudrom/datos/django/lib/python3.3/site-packages/whoosh/codec/whoosh3.py", line 488, in stored_fields
    reader = self._cached_reader("_stored", STORED_COLUMN)
  File "/home/kudrom/datos/django/lib/python3.3/site-packages/whoosh/codec/whoosh3.py", line 411, in _cached_reader
    reader = self.column_reader(fieldname, column)
  File "/home/kudrom/datos/django/lib/python3.3/site-packages/whoosh/codec/whoosh3.py", line 398, in column_reader
    self._colfiles[fieldname] = self._get_column_file(fieldname)
  File "/home/kudrom/datos/django/lib/python3.3/site-packages/whoosh/codec/whoosh3.py", line 393, in _get_column_file
    colfile = self._storage.open_file(filename)
  File "/home/kudrom/datos/django/lib/python3.3/site-packages/whoosh/filedb/filestore.py", line 329, in open_file
    return self.a.open_file(name, *args, **kwargs)
  File "/home/kudrom/datos/django/lib/python3.3/site-packages/whoosh/filedb/compound.py", line 99, in open_file
    if self._source:
AttributeError: 'CompoundStorage' object has no attribute '_source'

With python2 this is the traceback:

Traceback (most recent call last):
  File "<console>", line 2, in <module>
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/searching.py", line 1495, in __getitem__
    if fieldname in self.fields():
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/searching.py", line 1386, in fields
    self._fields = self.searcher.stored_fields(self.docnum)
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/reading.py", line 667, in stored_fields
    sfs = self._perdoc.stored_fields(docnum)
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/codec/whoosh3.py", line 488, in stored_fields
    reader = self._cached_reader("_stored", STORED_COLUMN)
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/codec/whoosh3.py", line 411, in _cached_reader
    reader = self.column_reader(fieldname, column)
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/codec/whoosh3.py", line 398, in column_reader
    self._colfiles[fieldname] = self._get_column_file(fieldname)
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/codec/whoosh3.py", line 393, in _get_column_file
    colfile = self._storage.open_file(filename)
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/filedb/filestore.py", line 329, in open_file
    return self.a.open_file(name, *args, **kwargs)
  File "/home/kudrom/datos/django2/lib/python2.7/site-packages/whoosh/filedb/compound.py", line 99, in open_file
    if self._source:
ValueError: mmap closed or invalid

The code is:

ix = open_dir(settings.INDEX)
qp = QueryParser("title", schema=ix.schema)
q = qp.parse(request.GET.get('q'))
with ix.searcher() as searcher:
     results = searcher.search(q)
**results[0]**

Bye

Comments (5)

  1. Matt Chaput

    Sorry again if the above wasn't clear, what you need to do is this:

    with ix.searcher() as searcher:
         results = searcher.search(q)
         results[0]
    

    That is, access the results object before the searcher is closed (at the end of the with block). Cheers!

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.