Example usage for org.springframework.data.mongodb.core.query TextQuery TextQuery

List of usage examples for org.springframework.data.mongodb.core.query TextQuery TextQuery

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query TextQuery TextQuery.

Prototype

public TextQuery(TextCriteria criteria) 

Source Link

Document

Creates new TextQuery for given TextCriteria .

Usage

From source file:example.springdata.mongodb.textsearch.TextSearchTemplateTests.java

/**
 * Sort by relevance relying on the value marked with {@link org.springframework.data.mongodb.core.mapping.TextScore}.
 *//*from   w  w  w. j  a va 2 s .co  m*/
@Test
public void findAllBlogPostsByPhraseSortByScore() {

    TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingPhrase("release");

    TextQuery query = new TextQuery(criteria);
    query.setScoreFieldName("score");
    query.sortByScore();

    List<BlogPost> blogPosts = operations.find(query, BlogPost.class);

    printResult(blogPosts, criteria);
}