Files
spring-data-examples/mongodb/text-search
Oliver Gierke 9a5c270ec2 #139 - Switched to embedded MongoDB for integration tests.
Removed MongoDB dependency by adding Flapdoodle embedded MongoDB. That allows us to get rid of the utility module we had in place for the MongoDB samples guarding the tests to only run when a MongoDB instance is running.

Tweaked Travis setup to not require the MongoDB service anymore.
2015-10-29 17:14:38 +01:00
..

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.

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.

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);
}