Skip to content

Commit a6923c9

Browse files
author
Andrew Brookins
committed
Rewrites
1 parent 457dd0c commit a6923c9

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

README.md

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,17 @@ except ResponseError
9494
Use an instance of `IndexDefinition` to define a search index. You only need
9595
to do this when you create an index.
9696

97-
Index definitions follow Hashes in your Redis databases. The *prefix* list
98-
you give to `IndexDefinition` tells RediSearch which Hash keys to add to that
99-
index.
97+
RediSearch indexes follow Hashes in your Redis databases by watching *key
98+
prefixes*. If a Hash whose key starts with one of the search index's
99+
configured key prefixes is added, updated, or deleted from Redis, RediSearch
100+
will make those changes in the index. You configure a search index's key
101+
prefixes using the `prefix` parameter of the `IndexDefinition` initializer.
100102

101103
**NOTE**: Once you create an index, RediSearch will continuously index these
102-
*keys when their Hashes change.
104+
keys when their Hashes change.
103105

104-
An `IndexDefinition` also takes a *schema*. The schema specifies which fields
105-
to index from within the Hashes that the index follows. The field types are:
106+
`IndexDefinition` also takes a *schema*. The schema specifies which fields to
107+
index from within the Hashes that the index follows. The field types are:
106108

107109
* TextField
108110
* TagField
@@ -125,7 +127,7 @@ SCHEMA = (
125127
TextField("body")
126128
)
127129

128-
client = Client("myIndex")
130+
client = Client("my-index")
129131

130132
definition = IndexDefinition(prefix=['blog:'])
131133

@@ -166,15 +168,17 @@ client.add_document(
166168

167169
### Querying
168170

169-
Use the `search()` method to query a RediSearch index.
171+
#### Basic queries
170172

171-
Without specifying a field, your query will perform a full-text search
172-
across all `TEXT` fields in the index.
173+
Use the `search()` method to perform basic full-text and field-specific
174+
searches. This method doesn't take many of the options available to the
175+
RediSearch `FT.SEARCH` command -- read the section on building complex
176+
queries later in this document for information on how to use those.
173177

174178
```py
175-
# Full-text search
176179
res = client.search("evil wizards")
177180
```
181+
#### Result objects
178182

179183
Results are wrapped in a `Result` object that includes the number of results
180184
and a list of matching documents.
@@ -186,17 +190,31 @@ and a list of matching documents.
186190
"Wizard Story 2: Evil Wizards Strike Back"
187191
```
188192

189-
You can use the `Query` object to build complex queries. For an explanation of
190-
these options, see the [RediSearch documentation](https://oss.redislabs.com/redisearch/Commands/#ftsearch)
191-
for the `FT.SEARCH` command.
193+
#### Building complex queries
194+
195+
You can use the `Query` object to build complex queries:
192196

193197
```py
194198
q = Query("evil wizards").verbatim().no_content().with_scores().paging(0, 5)
195199
res = client.search(q)
196200
```
197201

198-
The string you pass into the `search()` method or `Query()` initializer has
199-
the full range of query syntax available in RediSearch.
202+
For an explanation of these options, see the [RediSearch
203+
documentation](https://oss.redislabs.com/redisearch/Commands/#ftsearch) for
204+
the `FT.SEARCH` command.
205+
206+
#### Query syntax
207+
208+
The default behavior of queries is to run a full-text search across all
209+
`TEXT` fields in the index for the intersection of all terms in the query.
210+
211+
So the example given in the "Basic queries" section of this README,
212+
`client.search("evil wizards")`, run a full-text search for the intersection
213+
of "evil" and "wizard" in all `TEXT` fields.
214+
215+
Many more types of queries are possible, however! The string you pass into
216+
the `search()` method or `Query()` initializer has the full range of query
217+
syntax available in RediSearch.
200218

201219
For example, a full-text search against a specific `TEXT` field in the index
202220
looks like this:
@@ -216,7 +234,6 @@ To learn more, see the [RediSearch
216234
documentation](https://oss.redislabs.com/redisearch/Query_Syntax/) on query
217235
syntax.
218236

219-
220237
### Aggregations
221238

222239
This library contains a programmatic interface to run [aggregation
@@ -248,8 +265,8 @@ result = client.aggregate(request)
248265

249266
#### A redis-cli equivalent query
250267

251-
The complete aggregation query given as an example in this document looks
252-
like the following when entered using the redis-cli as native Redis commands:
268+
The aggregation query just given is equivalent to the following
269+
`FT.AGGREGATE` command entered directly into the redis-cli:
253270

254271
```sql
255272
FT.AGGREGATE books-idx *
@@ -325,16 +342,14 @@ AggregateRequest('*').group_by([], reducers.max("@num_published"))
325342
```
326343

327344
**NOTE**: Aggregation queries require at least one `group_by()` method call.
328-
As just mentioned, use `group_by([], ...` to run a reducer function over all
329-
results (in other words, to avoid grouping the results).
330345

331346
#### Sorting and limiting
332347

333348
Using an `AggregateRequest` instance, you can sort with the `sort_by()` method
334349
and limit with the `limit()` method.
335350

336351
For example, finding the average rating of books published each year, sorting
337-
by the average rating for the year, and taking the first ten:
352+
by the average rating for the year, and returning only the first ten results:
338353

339354
```py
340355
from redisearch import Client
@@ -351,11 +366,14 @@ request = AggregateRequest('*').group_by(
351366
c.aggregate(request)
352367
```
353368

369+
**NOTE**: The first option to `limit()` is a zero-based offset, and the second
370+
option is the number of results to return.
371+
354372
#### Filtering
355373

356-
Filtering is a way to reject results of an aggregation after your reducer functions run.
357-
For example, calculating the average rating of books published each year and only
358-
returning years with an average rating higher than 3:
374+
Use filtering to reject results of an aggregation query after your reducer
375+
functions run. For example, calculating the average rating of books published
376+
each year and only returning years with an average rating higher than 3:
359377

360378
```py
361379
from redisearch.aggregation import AggregateRequest, Asc

0 commit comments

Comments
 (0)