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

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

Introduction

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

Prototype

boolean sortByScore

To view the source code for org.springframework.data.mongodb.core.query TextQuery sortByScore.

Click Source Link

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}.
 *///w  ww.  j a v a 2s . c o  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);
}