RediSearch pour la recherche en texte intégral
Mettez en œuvre de puissantes fonctions de recherche en texte intégral sur les données Redis afin d’enrichir vos applications.
RediSearch pour la recherche en texte intégral est une leçon Redis Caching & Messaging (Pub/Sub, Streams) gratuite sur CoddyKit. Ceci est la leçon 2 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Redis Caching & Messaging (Pub/Sub, Streams), et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Redis Caching & Messaging (Pub/Sub, Streams) comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
Unlock Powerful Search
Welcome! In this lesson, we'll dive into RediSearch, a powerful Redis module. It transforms Redis into a robust, real-time search engine.
RediSearch allows you to perform fast, complex full-text searches directly on your Redis data, enhancing your application's features significantly.
RediSearch: A Redis Module
RediSearch isn't part of Redis's core functionality; it's an add-on module. Redis modules extend Redis with new data types and commands.
Think of it as adding a specialized search engine feature directly into your Redis instance, making it incredibly efficient for search operations.
Creating Your First Index
Before you can search, you need to define an index. An index tells RediSearch which fields in your data (typically Redis Hashes) are searchable and how.
The FT.CREATE command is used to set up this schema. Let's create an index named myProductIndex with title and description text fields.
FT.CREATE myProductIndex SCHEMA title TEXT WEIGHT 5.0 description TEXTAdding Documents to the Index
Once your index is defined, you can start adding documents to it. RediSearch indexes Redis Hashes, so you'll first store your data as a Hash, then add it to the index using FT.ADD.
The score (e.g., 1.0) influences relevance ranking.
HSET product:1 title "RediSearch Guide" description "A comprehensive guide to full-text search with Redis modules."
HSET product:2 title "Redis Caching Strategies" description "Learn advanced caching patterns using Redis."
FT.ADD myProductIndex product:1 1.0 FIELDS title "RediSearch Guide" description "A comprehensive guide to full-text search with Redis modules."
FT.ADD myProductIndex product:2 1.0 FIELDS title "Redis Caching Strategies" description "Learn advanced caching patterns using Redis."Performing Basic Searches
Now that we have data indexed, let's perform a simple full-text search using the FT.SEARCH command.
You just specify the index name and your query term. RediSearch will look for the term across all indexed text fields.
FT.SEARCH myProductIndex "search"
FT.SEARCH myProductIndex "Redis"Field-Specific Searches
Sometimes you need to search only within a specific field. RediSearch allows you to target your queries using the @field:term syntax.
This helps you get more precise results, for example, by searching only in the title field.
FT.SEARCH myProductIndex "@title:Redis"
FT.SEARCH myProductIndex "@description:guide"Prefix and Phrase Searches
RediSearch supports advanced query syntax for more flexible searches. You can use prefix searches (e.g., red* for anything starting with 'red') or search for exact phrases.
Exact phrases are enclosed in double quotes.
FT.SEARCH myProductIndex "red*"
FT.SEARCH myProductIndex "\"full-text search\""Using Tag Fields for Filtering
For exact filtering, like categorizing items, RediSearch offers TAG fields. These are optimized for checking exact matches rather than full-text relevance.
Let's add a category tag field and demonstrate how to query it. We'll need a new index or to alter an existing one, but for simplicity, imagine it's part of myProductIndex.
FT.CREATE booksIdx SCHEMA title TEXT author TAG
FT.ADD booksIdx book:1 1.0 FIELDS title "Redis Essentials" author "John Doe, Jane Smith"
FT.ADD booksIdx book:2 1.0 FIELDS title "Advanced Redis" author "Jane Smith"
FT.SEARCH booksIdx "@author:{John Doe}"
FT.SEARCH booksIdx "@author:{Jane Smith|John Doe}"Quick Check
You want to create a RediSearch index named articles with two fields:
headline: a text field for full-text search.topic: a tag field for exact topic filtering.
Which command correctly creates this index?
RediSearch: Powerful Search in Redis
In this lesson, you learned how RediSearch extends Redis with powerful full-text search capabilities.
- We covered creating an index with a schema using
FT.CREATE. - You saw how to add documents with
FT.ADDand perform basic searches usingFT.SEARCH. - We explored field-specific queries, prefix searches, phrase searches, and the use of TAG fields for exact filtering.
RediSearch is a fantastic tool for adding robust search features directly to your Redis applications, making data retrieval faster and more flexible!
Apprends Redis Caching & Messaging (Pub/Sub, Streams) avec un tuteur IA — gratuit
Écris et exécute du vrai code dans ton navigateur, obtiens de l'aide instantanée d'un tuteur IA disponible 24h/24, et reprends là où tu t'es arrêté sur le web ou dans l'app.
- Cours
- 12
- Leçons
- 48
Questions Fréquemment Posées
La leçon « RediSearch pour la recherche en texte intégral » est-elle gratuite ?
Oui — le texte complet de « RediSearch pour la recherche en texte intégral » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Redis Caching & Messaging (Pub/Sub, Streams), passe à CoddyKit PRO. Le cours Redis Caching & Messaging (Pub/Sub, Streams) comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « RediSearch pour la recherche en texte intégral » ?
Mettez en œuvre de puissantes fonctions de recherche en texte intégral sur les données Redis afin d’enrichir vos applications. Tu pratiques Redis Caching & Messaging (Pub/Sub, Streams) avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Redis Caching & Messaging (Pub/Sub, Streams) ?
Aucune expérience préalable n'est requise. Redis Caching & Messaging (Pub/Sub, Streams) sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 2 sur 4.
Combien de temps prend la leçon « RediSearch pour la recherche en texte intégral » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Redis Caching & Messaging (Pub/Sub, Streams) ?
Oui. Chaque leçon Redis Caching & Messaging (Pub/Sub, Streams) inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- Présentation des modules Redis
- RediSearch pour la recherche en texte intégral
- Notions fondamentales de RedisJSON et RedisGraph
- Séries temporelles avec RedisTimeSeries