My wrapper for python's dict, which uses whoosh to keep a text index of key-value pairs on disk instead of keeping them in memory, does not seem to be able to able to retrieve values added this way:
myDictObject[myStringList[0]] = myStringList[1]
After doing this, the following fails (I get an exception saying there are zero results):
myDictObject[myStringList[0]]
Simply adding strings and retrieving them works:
myDictObject[myString] = myString2
myDictObject[myString] #will return myString2
Here is the __getitem__(self,key)
and __setitem__(self,key,value)
code:
def __getitem__(self,key):
self.writerToggleClose()
with self.ix.searcher() as searcher:
self.result = searcher.search( Term('keystring',unicode(key)), limit = 1 )
if self.bool_only:
if len(self.result) == 0:
return False
else:
return True
else:
return str( self.result[0]['valuestring'] ) #return, for the top result, the value for the given key
def __setitem__(self,key,value):
self.writerToggleOpen()
self.writer.add_document(keystring = unicode(key), valuestring = unicode(value))
The wrapper module can be found here: https://github.com/hashimmm/whoosh-dict
The funny thing is, if I open the index I created (using this wrapper object) and use the .keys(self)
method to list the keys or __iter__(self)
to list values, the values I inserted are listed correctly. They simply seem to be unsearchable.
Any idea what I'm doing wrong? A lot of things, perhaps, but I got no idea.
Update:
I've written lettuce test cases and added them to the git repository. If you have both lettuce and whoosh for python, feel free to simply clone and run. And if you can explain why this problem occurs, please do tell.