A Java Client Library for RediSearch
This project contains a Java library abstracting the API of the RediSearch Redis module, that implements a powerful in-memory search engine inside Redis.
See http://redisearch.io for installation instructions of the module.
Initializing the client:
import io.redisearch.client.Client;
import io.redisearch.Document;
import io.redisearch.SearchResult;
import io.redisearch.Query;
import io.redisearch.Schema;
...
Client client = new Client("testung", "localhost", 6379);
Defining a schema for an index and creating it:
Schema sc = new Schema()
.addTextField("title", 5.0)
.addTextField("body", 1.0)
.addNumericField("price");
client.createIndex(sc, Client.IndexOptions.Default());
Adding documents to the index:
Map<String, Object> fields = new HashMap<>();
fields.put("title", "hello world");
fields.put("body", "lorem ipsum");
fields.put("price", 1337);
client.addDocument("doc1", fields);
Searching the index:
// Creating a complex query
Query q = new Query("hello world")
.addFilter(new Query.NumericFilter("price", 0, 1000))
.limit(0,5);
// actual search
SearchResult res = client.search(q);
- Geo filtering
- Exact matching
- Union matching
- Stemming in 17 languages
- Deleting and updating documents on the fly
- And much more... See http://redisearch.io for more details.