Search in sources :

Example 1 with TextCriteria

use of org.springframework.data.mongodb.core.query.TextCriteria in project ocvn by devgateway.

the class GenericOCDSController method textSearchQuery.

/**
     * Creates a mongodb query for searching based on text index, sorts the results by score
     *
     * @param request
     * @return
     */
protected Query textSearchQuery(final TextSearchRequest request) {
    PageRequest pageRequest = new PageRequest(request.getPageNumber(), request.getPageSize());
    Query query = null;
    if (request.getText() == null) {
        query = new Query();
    } else {
        query = TextQuery.queryText(new TextCriteria().matching(request.getText())).sortByScore();
    }
    query.with(pageRequest);
    return query;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) TextQuery(org.springframework.data.mongodb.core.query.TextQuery) Query(org.springframework.data.mongodb.core.query.Query) TextCriteria(org.springframework.data.mongodb.core.query.TextCriteria)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)1 Query (org.springframework.data.mongodb.core.query.Query)1 TextCriteria (org.springframework.data.mongodb.core.query.TextCriteria)1 TextQuery (org.springframework.data.mongodb.core.query.TextQuery)1