Skip to content

Commit 22c6f48

Browse files
committed
docs: updated README and added QBE example
1 parent b718747 commit 22c6f48

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ The `EntityStream` is injected into the `PeopleService` using `@Autowired`. We c
314314
#### 👭 Entity Meta-model
315315

316316
To produce more elaborate queries, you're provided with a generated metamodel, which is a class with the same name as your model but ending with a dollar sign. In the
317-
example below, our entity model is `Person` therefore we get a metamodel named `Person$`. With the meta-model you have access to the operations related to the
318-
underlying search engine field. For example, in the example we have an `age` property which is an integer. Therefore our metamodel has an `AGE` property which has
317+
example below, our entity model is `Person` therefore we get a metamodel named `Person$`. With the metamodel you have access to the operations related to the
318+
underlying search engine field. For example, in the example we have an `age` property which is an integer. Therefore, our metamodel has an `AGE` property which has
319319
numeric operations we can use with the stream's `filter` method such as `between`.
320320

321321
```java
@@ -331,6 +331,42 @@ public Iterable<Person> findByAgeBetween(int minAge, int maxAge) {
331331

332332
In this example we also make use of the Streams `sorted` method to declare that our stream will be sorted by the `Person$.AGE` in `ASC`ending order.
333333

334+
Check out the full set of tests for [EntityStreams](https://github.com/redis/redis-om-spring/tree/main/redis-om-spring/src/test/java/com/redis/om/spring/search/stream)
335+
336+
### 👯‍️ Querying by Example (QBE)
337+
338+
Query by Example (QBE) is a user-friendly querying technique with a simple interface. It allows dynamic query creation
339+
and does not require you to write queries that contain field names. In fact, Query by Example does not require you to
340+
write queries by using store-specific query languages at all.
341+
342+
#### QBE Usage
343+
344+
The Query by Example API consists of four parts:
345+
* **Probe**: The actual example of a domain object with populated fields.
346+
* **ExampleMatcher**: The `ExampleMatcher` carries details on how to match particular fields. It can be reused across multiple `Examples`.
347+
* **Example**: An Example consists of the probe and the ExampleMatcher. It is used to create the query.
348+
* **FetchableFluentQuery**: A `FetchableFluentQuery` offers a fluent API, that allows further customization of a query derived from an `Example`.
349+
Using the fluent API lets you specify ordering projection and result processing for your query.
350+
351+
Query by Example is well suited for several use cases:
352+
353+
* Querying your data store with a set of static or dynamic constraints.
354+
* Frequent refactoring of the domain objects without worrying about breaking existing queries.
355+
* Working independently of the underlying data store API.
356+
357+
For example, if you have an `@Document` or `@RedisHash` annotated entity you can create an instance, partially populate its
358+
properties, create an `Example` from it, and used the `findAll` method to query for similar entities:
359+
360+
```java
361+
MyDoc template = new MyDoc();
362+
template.setTitle("hello world");
363+
template.setTag(Set.of("artigo"));
364+
365+
Example<MyDoc> example = Example.of(template, ExampleMatcher.matchingAny());
366+
367+
Iterable<MyDoc> allMatches = repository.findAll(example);
368+
```
369+
334370
## 💻 Maven configuration
335371

336372
### Official Releases
@@ -360,7 +396,7 @@ inherited from the parent poms):
360396
<path>
361397
<groupId>org.springframework.boot</groupId>
362398
<artifactId>spring-boot-configuration-processor</artifactId>
363-
<version>3.0.6</version>
399+
<version>3.1.2</version>
364400
</path>
365401
<path>
366402
<groupId>org.projectlombok</groupId>
@@ -370,7 +406,7 @@ inherited from the parent poms):
370406
<path>
371407
<groupId>com.redis.om</groupId>
372408
<artifactId>redis-om-spring</artifactId>
373-
<version>0.8.2</version>
409+
<version>0.8.6</version>
374410
</path>
375411
</annotationProcessorPaths>
376412
</configuration>
@@ -416,7 +452,7 @@ repositories {
416452
### Dependency
417453
```groovy
418454
ext {
419-
redisOmVersion = '0.8.3-SNAPSHOT'
455+
redisOmVersion = '0.8.7-SNAPSHOT'
420456
}
421457
422458
dependencies {
@@ -512,7 +548,7 @@ Redis OM uses the [MIT license][license-url].
512548
[badge-codeql-page]: https://github.com/redis/redis-om-spring/actions/workflows/codeql-analysis.yml
513549
[license-image]: https://img.shields.io/github/license/redis/redis-om-spring
514550
[license-url]: LICENSE
515-
[sdr-badge-releases]: https://img.shields.io/maven-central/v/org.springframework.data/spring-data-redis/3.0.1
551+
[sdr-badge-releases]: https://img.shields.io/maven-central/v/org.springframework.data/spring-data-redis/3.1.2
516552
[discord-shield]: https://img.shields.io/discord/697882427875393627?style=social&logo=discord
517553
[twitch-shield]: https://img.shields.io/twitch/status/redisinc?style=social
518554
[twitter-shield]: https://img.shields.io/twitter/follow/redisinc?style=social

0 commit comments

Comments
 (0)