thomasmueller commented on code in PR #2540:
URL: https://github.com/apache/jackrabbit-oak/pull/2540#discussion_r2444898175
##########
oak-core/src/main/java/org/apache/jackrabbit/oak/query/UnionQueryImpl.java:
##########
@@ -527,4 +544,41 @@ public Optional<Long> getLimit() {
public Optional<Long> getOffset() {
return offset;
}
+
+ /**
+ * @param query the query to check.
+ * @return true if the query contains a jcr:score column, false otherwise.
+ */
+ private static boolean isScorePresent(Query query) {
+ return query.getColumnIndex("jcr:score") != -1;
+ }
+
+ /**
+ * @return a comparator to sort results by jcr:score in descending order.
+ * Precondition: {@link #isScorePresent(Query)} is true.
+ */
+ private Comparator<ResultRowImpl> createScoreBasedComparator() {
+ return new Comparator<ResultRowImpl>() {
+ @Override
+ public int compare(ResultRowImpl left, ResultRowImpl right) {
+ return Double.compare(getScoreFromRow(right),
getScoreFromRow(left));
+ }
+ };
+ }
+
+ /**
+ * @param row the result row
+ * @return the jcr:score as a Double
+ * Precondition: {@link #isScorePresent(Query)} must be true. If the row
lacks a jcr:score, 0.0 is returned and
+ * the issue is logged.
+ */
+ private Double getScoreFromRow(ResultRowImpl row) {
Review Comment:
Nitpick: Double can be "null" which is not what we want here.
```suggestion
private double getScoreFromRow(ResultRowImpl row) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]