RediSearch для полнотекстового поиска
Реализуйте мощные возможности полнотекстового поиска по данным Redis для расширения функций приложения.
«RediSearch для полнотекстового поиска» — бесплатный урок Redis Caching & Messaging (Pub/Sub, Streams) на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Redis Caching & Messaging (Pub/Sub, Streams), и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Redis Caching & Messaging (Pub/Sub, Streams) содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
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!
Изучай Redis Caching & Messaging (Pub/Sub, Streams) с ИИ-репетитором — бесплатно
Пиши и запускай код прямо в браузере, получай мгновенную помощь от ИИ-репетитора 24/7 и продолжи учиться на сайте или в приложении.
- Курсы
- 12
- Уроки
- 48
Часто задаваемые вопросы
Урок «RediSearch для полнотекстового поиска» бесплатный?
Да — полный текст урока «RediSearch для полнотекстового поиска» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Redis Caching & Messaging (Pub/Sub, Streams), подпишись на CoddyKit PRO. Курс Redis Caching & Messaging (Pub/Sub, Streams) содержит 4 уроков всего.
Чему я научусь в уроке «RediSearch для полнотекстового поиска»?
Реализуйте мощные возможности полнотекстового поиска по данным Redis для расширения функций приложения. Ты практикуешь Redis Caching & Messaging (Pub/Sub, Streams) с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Redis Caching & Messaging (Pub/Sub, Streams)?
Предыдущий опыт не требуется. Redis Caching & Messaging (Pub/Sub, Streams) на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.
Сколько времени занимает урок «RediSearch для полнотекстового поиска»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Redis Caching & Messaging (Pub/Sub, Streams)?
Да. Каждый урок Redis Caching & Messaging (Pub/Sub, Streams) включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Обзор модулей Redis
- RediSearch для полнотекстового поиска
- Основы RedisJSON и RedisGraph
- Временные ряды с RedisTimeSeries