You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/003-create-index.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ This is where RediSearch module is helping, and why it as been created.
85
85
86
86
RediSearch simplifies a lot this by offering a simple and automatic way to create secondary indices on Redis Hashes. (more datastructure will eventually come)
Using RediSearch if you want to query on a field, you must index the fields. Let's start by indexing the following fields in of our movies:
91
91
@@ -117,7 +117,7 @@ Before running some queries let's look at the command in detail:
117
117
*`idx:movie` : the name of the index
118
118
*`ON hash` : the type of structure to be indexed. *Note that in RediSearch 2.0 only hash structure are supported, this is parameter will allow RediSearch to index other structure in the future*
119
119
*`PREFIX 1 "movie:"` : the prefix of the keys that should be indexed. This is a list, so since we want to only index movie:* keys the number is 1. Suppose you want to index movies and tv_show that have the same fields, you can use: `PREFIX 2 "movie:" "tv_show:"`
120
-
*`SCHEMA ...`: define the schema, the fields and their type, to index, as you can see in the command, we are using TEXT, NUMERIC and TAG, and SORTABLE parameters.
120
+
*`SCHEMA ...`: define the schema, the fields and their type, to index, as you can see in the command, we are using [TEXT](https://oss.redislabs.com/redisearch/Query_Syntax/#a_few_query_examples), [NUMERIC](https://oss.redislabs.com/redisearch/Query_Syntax/#numeric_filters_in_query) and [TAG](https://oss.redislabs.com/redisearch/Query_Syntax/#tag_filters), and [SORTABLE](https://oss.redislabs.com/redisearch/Sorting/) parameters.
121
121
122
122
You can find information about the [FT.CREATE](https://oss.redislabs.com/redisearch/Commands/#ftcreate) command in the [documentation](https://oss.redislabs.com/redisearch/Commands/#ftcreate).
Copy file name to clipboardExpand all lines: docs/004-query-data.md
+32-18Lines changed: 32 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,10 @@ The database contains few movies, and an index, it is not possible to execute so
4
4
5
5
## Queries
6
6
7
-
**Example : *All the movies that contains the string "`star`"***
7
+
**Example : *All the movies that contains the string "`war`"***
8
8
9
9
```
10
-
> FT.SEARCH idx:movie "star"
10
+
> FT.SEARCH idx:movie "war"
11
11
12
12
1) (integer) 2
13
13
2) "movie:11005"
@@ -26,14 +26,14 @@ The database contains few movies, and an index, it is not possible to execute so
26
26
27
27
The FT.SEARCH commands returns the list of result starting with the number of results, then the list of elements (keys & fields).
28
28
29
-
This example uses a simple query string `"star"`, this will return all the movies that *contain*the word star in a textfield of the index.
29
+
As you can see the movie *Star Wars: Episode V - The Empire Strikes Back* is found, even though you used only the word “war” to match “Wars” in the title. This is because the title has been indexed as text, so the field is [tokenized](https://oss.redislabs.com/redisearch/Escaping/) and [stemmed](https://oss.redislabs.com/redisearch/Stemming/).
30
30
31
31
Later when looking in more details on the query syntax you will learn more the search capabilities.
32
32
33
33
It is also possible to limit the list of fields returned by the query using the `RETURN` parameter, let's run the same query, and return only the title and release_year:
34
34
35
35
```
36
-
> FT.SEARCH idx:movie "star" RETURN 2 title release_year
36
+
> FT.SEARCH idx:movie "war" RETURN 2 title release_year
37
37
38
38
1) (integer) 2
39
39
2) "movie:11005"
@@ -53,17 +53,16 @@ This query does not specific any "field" and still return some movie, this is be
53
53
If you need to do a query on a specific field you can specify it using the `@field:` syntax, for example:
54
54
55
55
```
56
-
> FT.SEARCH idx:movie "@title:star" RETURN 2 title release_year
56
+
> FT.SEARCH idx:movie "@title:war" RETURN 2 title release_year
57
57
```
58
58
59
-
60
59
---
61
-
**Example : *All the movies that contains the string "`star` but NOT the `jedi` one"***
60
+
**Example : *All the movies that contains the string "`war` but NOT the `jedi` one"***
62
61
63
62
Adding the string `-jedi` (minus) will ask the query engine to not return the values that contain `jedi`.
64
63
65
64
```
66
-
> FT.SEARCH idx:movie "star -jedi" RETURN 2 title release_year
65
+
> FT.SEARCH idx:movie "war -jedi" RETURN 2 title release_year
67
66
68
67
1) (integer) 1
69
68
2) "movie:11002"
@@ -73,6 +72,21 @@ Adding the string `-jedi` (minus) will ask the query engine to not return the va
73
72
4) "1980"
74
73
```
75
74
75
+
---
76
+
**Example : *All the movies that contains the string "`gdfather` using fuzzy search"***
77
+
78
+
As you can see the word godfather is wrongly spelled, it is possible using a [fuzzy matching](https://oss.redislabs.com/redisearch/Query_Syntax/#fuzzy_matching). Fuzzy matches are performed based on [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) (LD).
79
+
80
+
```
81
+
> FT.SEARCH idx:movie " %gdfather% " RETURN 2 title release_year
82
+
83
+
1) (integer) 1
84
+
2) "movie:11003"
85
+
3) 1) "title"
86
+
2) "The Godfather"
87
+
3) "release_year"
88
+
4) "1972"
89
+
```
76
90
77
91
---
78
92
**Example : *All `Thriller` movies"***
@@ -93,7 +107,6 @@ The syntax to query a TAG field is @field_name:{value}
93
107
94
108
```
95
109
96
-
97
110
---
98
111
**Example : *All `Thriller` or `Action` movies"***
> FT.SEARCH idx:movie "@release_year:[1970 1980]" RETURN 2 title release_year
158
173
159
174
1) (integer) 2
@@ -176,7 +191,6 @@ To exclude a value prepend it with `(` in the FILTER or query string, for exampl
176
191
> FT.SEARCH idx:movie "@release_year:[1970 (1980]" RETURN 2 title release_year
177
192
```
178
193
179
-
180
194
---
181
195
## Insert, Update, Delete and Expire Documents
182
196
@@ -188,25 +202,25 @@ As part of this tutorial you have:
188
202
189
203
When creating the index, using the `idx:movie ON hash PREFIX 1 "movie:"` parameter you are asking the indexing engine to look at all existing keys and index them.
190
204
191
-
Also any new information that match this pattern/type, will be indexed.
205
+
Also new information that match this pattern/type, will be indexed.
192
206
193
-
Let's count the number of movie and then add a new one, and count again:
207
+
Let's count the number of movies, add a new one, and count again:
194
208
195
209
```
196
210
> FT.SEARCH idx:movie "*" LIMIT 0 0
211
+
197
212
1) (integer) 4
198
213
199
214
200
215
> HSET movie:11033 title "Tomorrow Never Dies" plot "James Bond sets out to stop a media mogul's plan to induce war between China and the U.K in order to obtain exclusive global media coverage." release_year 1997 genre "Action" rating 6.5 votes 177732 imdb_id tt0120347
201
216
202
217
> FT.SEARCH idx:movie "*" LIMIT 0 0
218
+
203
219
1) (integer) 5
204
220
205
221
```
206
222
207
-
The new movie has been indexed.
208
-
209
-
You can also search on any of the indexed fields:
223
+
The new movie has been indexed. You can also search on any of the indexed fields:
210
224
211
225
```
212
226
> FT.SEARCH idx:movie "never" RETURN 2 title release_year
@@ -219,7 +233,7 @@ You can also search on any of the indexed fields:
219
233
4) "1997"
220
234
```
221
235
222
-
Let**update** one of the field, and search for `007`
236
+
Now you**update** one of the field, and search for `007`
223
237
224
238
```
225
239
> HSET movie:11033 title "Tomorrow Never Dies - 007"
@@ -235,7 +249,7 @@ Let **update** one of the field, and search for `007`
235
249
4) "1997"
236
250
```
237
251
238
-
When you *delete* the has the index is also updated, and the same happends when you are using expiration (TTL-Time To Live).
252
+
When you *delete* the hash, the index is also updated, and the same happens the the key is expired (TTL-Time To Live).
239
253
240
254
For example put a 20 sedonds expiration time to the James Bond movie:
241
255
@@ -253,7 +267,7 @@ You can run the following query, and you will see after 20 seconds the document
253
267
254
268
```
255
269
256
-
> Note: When you are using Redis as your primary database you are not necessary using the TTL to delet record. However, if the data your are storing and indexing are transient, for example a caching layer at the top of another datastore or Web service, query user sessions content, ... This is often qualified as a "Ephemeral Search" use case: lighweight, fast and expiration.
270
+
> Note: When you are using Redis as your primary database you are not necessary using the TTL to delet record. However, if the data your are storing and indexing are transient, for example a caching layer at the top of another datastore or Web service, query user sessions content, ... This is often qualified as a "[Ephemeral Search](https://redislabs.com/blog/the-case-for-ephemeral-search/)" use case: lighweight, fast and expiration.
Copy file name to clipboardExpand all lines: docs/007-query-movies.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,7 +211,7 @@ TAG is the structure to use when you want to do exact match condition on string/
211
211
</b></i>
212
212
</summary>
213
213
214
-
This is very similar to the previous query, you can pass a list of value with the `|` to represent the OR.
214
+
This is similar to the previous query, you can pass a list of value with the `|` to represent the OR.
215
215
216
216
217
217
```
@@ -289,9 +289,9 @@ In this query it will be twao condition with a OR (`|`).
289
289
290
290
Summary
291
291
292
-
*A fieldless query will apply to all TEXT fields and will use the words and their base form (stemming)
292
+
*Fieldless queries apply to all TEXT fields and use the words and their base form (stemming)
293
293
* To apply a condition to a specific field you must use the `@field:` notation
294
-
* Multiple conditions are "intersection" (AND condition)
294
+
* Multiple conditions are "intersection" (AND condition), to do an "union" (OR condition), you have to use the "`|`" character.
295
295
296
296
----
297
297
### Sort
@@ -319,18 +319,19 @@ A very common use case when querying data is to sort the data on a specific fiel
319
319
4) "Mechanic: Resurrection"
320
320
```
321
321
322
-
The first line contains the number of documents (`186`) that matche the query condition, the the list of movies.
322
+
The first line contains the number of documents (`186`) that match the query condition.
323
323
324
-
The FT.SEARCH command by default returns the first 10 documents, you will see in the next query how to paginate.
324
+
The FT.SEARCH command, by default, returns the first ten documents. You will see in the next query how to paginate.
325
325
326
+
You can only use one SORTBY in an FT.SEARCH query, if you want to sort on multiple fields, for example sorting movies by `genre` ascending and `release_year` descending, you have to use an FT.AGGREGATE, this is covered in the [next section](008-aggregation.md).
326
327
328
+
Note: The field used in the [SORTBY](https://oss.redislabs.com/redisearch/Sorting/#specifying_sortby) should be part of the index schema and defined as SORTABLE.
327
329
---
328
330
</details>
329
331
330
332
----
331
333
### Paginate
332
334
333
-
334
335
<details>
335
336
<summary>
336
337
<i><b>Query all the `Action` movies, sorted by release year from the oldest to the most recent one, returning the record by batch of 100 movies</b></i>
0 commit comments