A golang library for constructing FT.SEARCH queries.
- Construct a query builder.
import "github.com/LunasphereEntertainment/redis-qb/builder" func main() { qb := &builder.QueryBuilder{} }
- Make your query!
query := qb.NewQuery("my_index_name")
The query contains chainable methods to fully construct your query.
- Text Search
will result in a query like:
query := qb.NewQuery("test").Equals("title", "hello world")
FT.SEARCH test @title:(hello world)
- Range search
will result in a query like:
query := qb.NewQuery("test").InRange("age", 18, 100)
FT.SEARCH test @age:[18 100]
- Not in that range?
query := qb.NewQuery("test").NotInRange("age", 18, 100)
FT.SEARCH test @age:-[18 100]
- What about grouping?
will create the below query:
query := qb.NewQuery("test").Equals("title", "kafka") query.CaptureGroup(builder.Or).Equals("test", "hello world")
FT.SEARCH test @title:(kafka) | (@test:(hello world))
Once you've completed the building of your complex query. Simply call .QueryString()
on the query object.
E.g.
query := qb.NewQuery("test").
Equals("title", "kafka").
QueryString()
Your query string is now runnable through your chosen Redis Search library.