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

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

Introduction

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

Prototype

public void setScoreFieldName(String fieldName) 

Source Link

Document

Set the fieldname used for scoring.

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