Hello,
First of all here is my dependency : "org.springframework.boot:spring-boot-starter-data-mongodb-reactive:2.6.1"
Here is my query:
// Pageable: Page request [number: 0, size 5, sort: updateTime: DESC]
template.find(
TextQuery.queryText(TextCriteria().matchingAny(search)).sortByScore()
.addCriteria(Account::owner isEqualTo owner).with(pageable),
Account::class.java
).also { println(it) }
However when I print the query I get this:
Query: {
"$text" : { "$search" : "ema"},
"owner" : { "$oid" : "1234567898"}
},
Fields: { "score" : { "$meta" : "textScore"} },
Sort: {
"score" : { "$meta" : "textScore"},
"updateTime" : -1
}
the pageable sort is put at the end and therefore not doing anything. How can I sort by score and by the pageable ?
Comment From: snicoll
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.
Comment From: yoobi
This does feel like a bug, when looking at the source code you can clearly see that using sortByScore()
ignores the order of sort and puts it in front of the Sort
@Override
public Document getSortObject() {
if (this.sortByScore) {
Document sort = new Document();
sort.put(getScoreFieldName(), META_TEXT_SCORE);
sort.putAll(super.getSortObject());
return sort;
}
return super.getSortObject();
}
Comment From: snicoll
@yoobi bug against Spring Data MongoDB should not be raised here, but in their issue tracker.
Comment From: yoobi
Oh! I've been browsing though different github at once and created this issue in the wrong repo. My bad !