This is the third day of my participation in the August More Text Challenge

RediSearch is a high-performance full-text search engine that runs as a Redis Module on a Redis server.

features

RediSearch features the following:

  • Document – based multi-field full-text index
  • High performance incremental index
  • Document sorting (manually provided by the user at index time)
  • Autocomplete suggestions (with fuzzy prefix suggestions)
  • Precise phrase search
  • Stem-based query extensions in many languages
  • Support for custom functions for query extensions and scoring
  • Limit your search to specific document fields
  • Digital filters and ranges
  • Complex Boolean queries that use AND or NOT operators between subqueries
  • Optional query clause
  • Prefix-based search
  • Field weight Settings are supported
  • Use Redis’s own geography command for geographic filtering
  • Unicode support (utF-8 character set required)
  • Retrieve the full document content or just the ID
  • Partial updates and conditional document updates are supported
  • Supports document deletion and update with index garbage collection

performance

For ElasticSearch, you can index 5.6 million Wikipedia documents (about 5.3GB) and search the indexed data set with two words. The comparison diagram is as follows:

Index generation time:

Search performance comparison:

The installation

Rapid deployment via Docker

 docker run -p 6379:6379 redislabs/redisearch:latest
Copy the code

use

Use redis- CLI to perform related operations on RediSearch.

Create indexes and fields

127.0.0.1:6379> ft. Create myidx schema title text weight 5.0 text OKCopy the code

Where “myidx” is the name of the index, which contains two fields “title” and “desc”, and “weight” is the weight. The default value is 1.0.

Add the content to the index

127.0.0.1:6379> ft. Add myidx doc1 1.0 fields title "He urged her to study English" desc "good idea" OKCopy the code

Doc1 indicates the document ID (doCID), and 1.0 indicates the score.

Based on key queries

127.0.0.1:6379> ft.search myidx "english" limit 0 10
1) (integer) 1
2) "doc1"
3) 1) "title"
   2) "He urged her to study English"
   3) "desc"
   4) "good idea"
Copy the code

It can be seen that we use the keyword “English” in the title field to query a data that meets the query conditions.

Chinese search

First we need to add a Chinese data to the index, execute the following command:

127.0.0.1:6379> ft. Add myidx doc2 1.0 language "Chinese" fields title" Java 14 was officially released on March 17, 2020, but many companies are still using Java 7 or Java 8" OKCopy the code

Note: The language code must be set to Chinese, that is, “Language” Chinese “. The default is English. If you do not set the language code, Chinese query cannot be supported (the result cannot be found).

Delete index data

127.0.0.1:6379> ft. Del myidx doc1 (integer) 1Copy the code

We can delete data by using the index plus the document ID.

Remove the index

We can drop the entire index using the “ft. Drop” keyword:

127.0.0.1: > 6379 ft. Drop myidx OKCopy the code

Client library support

Support for most languages, see Clients Library