Advanced pattern search in Redis
I want to use Redis to do some advanced pattern search on a dataset of ~250k words.
First time using Redis other than for caching, so still learning.
Search queries must meet the following conditions:
- Search for specific character(s) at specific positions.
- Limit results to matches within a specified string length.
I came up with two approaches, both of which partially worked.
-
Storing all words in a single SET This query
SSCAN words ?e*lgives me the correct results in 1/10 of a second (a single character, the character E, any characters, the character L)- central
- mental
- rental
- ...
However I found no way of modifying the query to limit the results to words with 3-5 characters for example. Except for doing this at application level.
-
Using Redisearch as secondary index on top of a HASH with two fields, "word" and "length"
This query FT.SEARCH words:idx "@word:el @length:[1 5]" is also very fast and works with length restrictings, but it's not possible to address a single character. The only wildcard here is * for any character(s).
Since this is such a basic thing I'm sure, there is a way to solve this. Any hints are welcome.
Please or to participate in this conversation.