diff --git a/zulia-server/src/main/java/io/zulia/server/index/ShardReader.java b/zulia-server/src/main/java/io/zulia/server/index/ShardReader.java index 53adc826..817514e9 100644 --- a/zulia-server/src/main/java/io/zulia/server/index/ShardReader.java +++ b/zulia-server/src/main/java/io/zulia/server/index/ShardReader.java @@ -175,6 +175,7 @@ public ZuliaQuery.ShardQueryResponse queryShard(Query query, Map collector; boolean sorting = (sortRequest != null) && !sortRequest.getFieldSortList().isEmpty(); + if (sorting) { collector = getSortingCollector(sortRequest, hasMoreAmount, after); } @@ -427,7 +428,7 @@ private TopDocsCollector getSortingCollector(ZuliaQuery.SortRequest sortReque ZuliaIndex.FieldConfig.FieldType sortFieldType = indexConfig.getFieldTypeForSortField(sortField); if (ZuliaConstants.SCORE_FIELD.equals(sortField)) { - sortFields.add(new SortField(null, SortField.Type.SCORE, reverse)); + sortFields.add(new SortField(null, SortField.Type.SCORE, !reverse)); } else if (FieldTypeUtil.isNumericOrDateFieldType(sortFieldType)) { diff --git a/zulia-server/src/test/java/io/zulia/server/test/node/StartStopTest.java b/zulia-server/src/test/java/io/zulia/server/test/node/StartStopTest.java index 98551235..4a9fa46e 100644 --- a/zulia-server/src/test/java/io/zulia/server/test/node/StartStopTest.java +++ b/zulia-server/src/test/java/io/zulia/server/test/node/StartStopTest.java @@ -125,21 +125,31 @@ else if (half) { // 2/5 of input @Test(dependsOnMethods = "index") public void sortScore() throws Exception { - Query q = new Query(FACET_TEST_INDEX, "issn:1234*", 10); + Query q = new Query(FACET_TEST_INDEX, "issn:\"1234-1234\" OR country:US", 10); q.addFieldSort(ZuliaConstants.SCORE_FIELD, ASCENDING); QueryResult queryResult = zuliaWorkPool.query(q); + double lowScore = -1; + double highScore = -1; for (ZuliaQuery.ScoredResult result : queryResult.getResults()) { Assert.assertTrue(result.getScore() > 0); + if (lowScore < 0) { + lowScore = result.getScore(); + } } - q = new Query(FACET_TEST_INDEX, "issn:1234*", 10); + q = new Query(FACET_TEST_INDEX, "issn:\"1234-1234\" OR country:US", 10); q.addFieldSort(ZuliaConstants.SCORE_FIELD, DESCENDING); queryResult = zuliaWorkPool.query(q); for (ZuliaQuery.ScoredResult result : queryResult.getResults()) { Assert.assertTrue(result.getScore() > 0); + if (highScore < 0) { + highScore = result.getScore(); + } } + + Assert.assertTrue(highScore > lowScore); } @Test(dependsOnMethods = "sortScore")