#8 - Add MongoDB text search example.

The sample reads the Spring IO blog Atom feed and performs text search on it.

We use manual index creation and query via MongoTemplate as well as automatic index creation and derived queries via repositories.

Original pull request: #10.
This commit is contained in:
Christoph Strobl
2014-08-27 14:53:29 +02:00
committed by Oliver Gierke
parent 4246700be0
commit 09317bc6de
12 changed files with 602 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
# Spring Data MongoDB - Text Search Examples
This project contains samples of text search specific features of Spring Data Mongodb.
## Support for Text Index
Define text index structures manually (like below) or use `@TextIndexed` to mark content to be indexed for full text search.
```java
TextIndexDefinition textIndex = new TextIndexDefinitionBuilder()
.onField("title", 3F)
.onField("content", 2F)
.onField("categories")
.build();
template.indexOps(BlogPost.class).ensureIndex(textIndex);
```
## Support for full text repository queries
Use derived finder methods to search for terms and phrases.
```java
interface BlogPostRepository extends CrudRepository<BlogPost, String> {
// page through results for full text query
Page<BlogPost> findBy(TextCriteria criteria, Pageable page);
// find all matching documents and sort by relevance
List<BlogPost> findAllByOrderByScoreDesc(TextCriteria criteria);
}
```