I have a simple redisearch index which I create in Python with:
>>> from redisearch import Client, TextField
>>> c = Client('common_words')
>>> c.create_index((TextField('body'),))
b'OK'
>>> c.add_document('ibiza', body='kevin paul dad')
b'OK'
>>> c.add_document('england', body='kevin dad')
b'OK'
>>> c.add_document('bank', body='kevin robber')
b'OK'
I can then search a particular word, which works great:
>>> c.search('kevin')
Result{3 total, docs:
[Document {'id': 'bank', 'payload': None, 'body': 'kevin robber'},
Document {'id': 'england', 'payload': None, 'body': 'kevin dad'},
Document {'id': 'ibiza', 'payload': None, 'body': 'kevin paul dad'}
]}
Is there a quick way to pull a list of words along with the occurence? I'm aiming for a result like:
{ Result{4 total, counts:
[ Word { 'word': 'kevin', 'count': 3},
Word { 'word': 'dad', 'count': 2 },
Word { 'word': 'paul', 'count': 1 },
Word { 'word': 'robber', 'count': 1 } ] }
I've looked at this example of how to make a word-count using nltk
and zincrby
but wondered if there was already a way to get this natively from redisearch
.