Skip to content

Commit

Permalink
enhance test case for score sorting
Browse files Browse the repository at this point in the history
fix backward logic
  • Loading branch information
mdavis95 committed Nov 20, 2019
1 parent 51bfeb4 commit 501249b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public ZuliaQuery.ShardQueryResponse queryShard(Query query, Map<String, ZuliaBa
TopDocsCollector<?> collector;

boolean sorting = (sortRequest != null) && !sortRequest.getFieldSortList().isEmpty();

if (sorting) {
collector = getSortingCollector(sortRequest, hasMoreAmount, after);
}
Expand Down Expand Up @@ -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)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 501249b

Please sign in to comment.