Table of contents
1.
Introduction
2.
RediSearch
2.1.
History
2.2.
Working
3.
Quick Start Guide for RediSearch
3.1.
Redis cloud
3.2.
Running with Dockers
3.3.
Building and running from source
3.4.
Creating an index with some fields and weights (default weight is 1.0)
3.5.
Adding documents to the index 
3.6.
Searching the index
3.7.
Dropping the index 
3.8.
Adding and getting Auto-complete suggestions
4.
Frequently Asked Questions
4.1.
What is the Redis module?
4.2.
Is Redis open source?
4.3.
Can Redis replace MySQL?
4.4.
Is Redis search fast?
4.5.
How many keys can Redis store?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

Quick start with Search Redis

Author Apoorv
0 upvote

Introduction

Redis is an in-memory data structure store that may be used as a database, cache, message broker, and streaming engine. It is open source (BSD licensed). Strings, hashes, lists, sets, sorted sets with range searches, bitmaps, hyperloglogs, geographic indexes, and streams are all available in Redis.

RediSearch

RediSearch is a strong and powerful indexing, querying, and full-text search engine for the Redis, available on the premises and as a managed service in the cloud.

Source: WPBullet

History

Users have come to demand the most relevant results for the search phrases they enter as search engines have become more refined. Redis then developed RediSearch, a full-text search engine that uses the Redis Modules API to enhance Redis with some new commands and capabilities, in order to adequately fulfill customers' needs and expectations.

Our developers then decided to model Inverted Indexes using a custom data structure rather than Redis' default data type to enable more efficient data packing. RediSearch allows modules to designate and then locate data on Redis string keys by modeling an inverted index, which holds a map between words or keywords to the respective documents in which they appear. This is a straightforward procedure that produces significant benefits.

Working

RediSearch additionally uses a combination of Delta Encoding and Variant Encoding to encode entries, reducing the amount of space necessary for indexes and allowing for faster decompression and index traversal. RediSearch offers a variety of unique capabilities as a result of this meticulous structure, ranging from speedy indexing and multi-language compatibility to exact phrase search and a sophisticated auto-suggest engine. To understand more about RediSearch's extensive capabilities, please read our ebook.

When giving search results, it's vital to note that RediSearch does not use any automatic methods to judge content quality. Instead, users can provide each indexed document with their own personalized quality scores, which RediSearch then combines with  tf-idf scoring of each word to rank search results. Nonetheless, we're constantly trying to improve RediSearch, so new relevance ranking algorithms are likely to appear in the future.
 

Source:Redis.com

RediSearch can also store documents, index existing Redis data, support numeric range filtering of results, execute queries using a chained-iterator-based approach, provide stemming for over 15 languages using the Snowball stemming library, auto-complete search terms, and accommodate Fuzzy Suggestions, in addition to being fast and memory efficient. Furthermore, if an index is too huge, RediSearch can be expanded out and partitioned across numerous machines.

Quick Start Guide for RediSearch

Let's get started with RediSearch.

Redis cloud

All Redis Cloud managed services support RediSearch. Redis Cloud Essentials provides a 30MB managed database for free.

Running with Dockers

docker run -p 6379:6379 redislabs/redisearch:latest

Building and running from source

  • First, clone the git repo and then make sure not to omit the --recursive option, to properly clone the submodule
git clone --recursive https://github.com/RediSearch/RediSearch.git
cd RediSearch

 

  • Then install some dependencies:

For macOS:

make setup

 

For Linux:

sudo make setup

 

  • After this step try to build:
make build

 

  • Finally, run Redis with RediSearch:
make run

Creating an index with some fields and weights (default weight is 1.0)

127.0.0.1:6379> FT.CREATE myIdx ON HASH PREFIX 1 doc: SCHEMA title TEXT WEIGHT 5.0 body TEXT url TEXT
OK

Adding documents to the index 

127.0.0.1:6379> hset doc:1 title "hello world" body "lorem ipsum" url "http://redis.io" 
(integer) 3

Searching the index

127.0.0.1:6379> FT.SEARCH myIdx "hello world" LIMIT 0 10
1) (integer) 1
2) "doc:1"
3) 1) "title"
   2) "hello world"
   3) "body"
   4) "lorem ipsum"
   5) "url"
   6) "http://redis.io"


Note: Input is expected to be valid utf-8 or ASCII. The engine cannot handle wide-character Unicode at the moment

Dropping the index 

To drop a particular index in Redis search we can use this command:

127.0.0.1:6379> FT.DROPINDEX myIdx 
OK

Adding and getting Auto-complete suggestions

127.0.0.1:6379> FT.SUGADD autocomplete "hello world" 100
OK
127.0.0.1:6379> FT.SUGGET autocomplete "he"
1) "hello world"

Frequently Asked Questions

What is the Redis module?

Redis modules are the dynamic libraries that can be loaded into Redis using the MODULE LOAD command or during startup. Redis provides a C API in the form of a single Redis module C header file.

Is Redis open source?

Yes, Redis Search is open source.

Can Redis replace MySQL?

Redis isn't a replacement for a relational (e.g. MySQL) or document-based (e.g. MongoDB) database because it has limited ability to construct associations between data objects.

Is Redis search fast?

Despite the much higher size and the number of documents, looking for web pages or other content on the web is much faster than searching on our local computer.

How many keys can Redis store?

Redis can handle up to 2^32 keys and was tested in practice to handle at least 250 million keys per instance.

Conclusion

In this article, we studied RediSearch in detail. We saw its uses and key concepts. We hope that this blog has helped you enhance your knowledge of RediSearch.

After reading about the Redis Search, are you not feeling excited to read/explore more articles on the topic of Redis? Don't worry; Coding Ninjas has you covered. To learn, see Redis Configuration, Introduction to Data Types in Redis from Code studio. 

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc., you must look at the problems, interview experiences, and interview bundle for placement preparations. 

Nevertheless, you may consider our paid courses to give your career an edge over others! 

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

 

Live masterclass