Skip to content

Commit

Permalink
#911 fix streaming sort (#912)
Browse files Browse the repository at this point in the history
#911 fix streaming sort.
  • Loading branch information
adam-collins authored Aug 9, 2024
1 parent dd8d3ce commit a40934b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repositories {
}

group = 'au.org.ala'
version = '3.5.0-SNAPSHOT'
version = '3.5.1-SNAPSHOT'


boolean inplace = false
Expand Down
30 changes: 26 additions & 4 deletions src/main/java/au/org/ala/biocache/dao/SolrIndexDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1175,17 +1175,39 @@ private ModifiableSolrParams buildSearchExpr(SolrQuery query) {
}
}
}

if (StringUtils.isNotEmpty(query.getFields())) {
solrParams.set("fl", StringUtils.join(fieldMappingUtil.translateFieldArray(query.getFields().split(",")), ","));
} else {
solrParams.set("fl", "id");
}

// The sort field does not need to be present in the field list.
if (StringUtils.isEmpty(query.getSortField())) {
solrParams.set("sort", "id asc");
} else {
// The sort field is required, sometimes. Testing suggests that this depends on the solrClient class.
// 1. use the query specified sort, without checking if it is in the list of fields
// 2. use the first non-multivalue field
// 3. use "id asc" and append "id" to the fl if it is missing
//
// Handle the error for some solrClient classes when the default query sort is "score asc" by excluding it
if (StringUtils.isNotEmpty(query.getSortField()) && !"score asc".equals(query.getSortField())) {
solrParams.set("sort", query.getSortField());
} else {
String [] fl = solrParams.get("fl").split(",");
String nonMultivalueField = null;
for (String field : fl) {
IndexFieldDTO f = indexFieldMap.get(field);
if (f != null && !f.isMultivalue()) {
nonMultivalueField = f.getName();
break;
}
}
if (nonMultivalueField != null) {
solrParams.set("sort", nonMultivalueField + " asc");
} else {
solrParams.set("sort", "id asc");

// append "id" to field list
solrParams.set("fl", solrParams.get("fl") + ",id");
}
}

String qt = "/export";
Expand Down

0 comments on commit a40934b

Please sign in to comment.