lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eirik Lygre (JIRA)" <>
Subject [jira] [Created] (SOLR-3926) solrj should support better way of finding active sorts
Date Wed, 10 Oct 2012 12:43:02 GMT
Eirik Lygre created SOLR-3926:

             Summary: solrj should support better way of finding active sorts
                 Key: SOLR-3926
             Project: Solr
          Issue Type: Improvement
          Components: clients - java
    Affects Versions: 4.0-BETA
            Reporter: Eirik Lygre
            Priority: Minor

The Solrj api uses ortogonal concepts for setting/removing and getting sort information. Setting/removing
uses a combination of (name,order), while getters return a String "name order":

public SolrQuery setSortField(String field, ORDER order);
public SolrQuery addSortField(String field, ORDER order);
public SolrQuery removeSortField(String field, ORDER order);
public String[] getSortFields();
public String getSortField();

If you want to use the current sort information to present a list of active sorts, with the
possibility to remove then, you need to manually parse the string(s) returned from getSortFields,
to recreate the information required by removeSortField(). Not difficult, but not convenient
either :-)

Therefore this suggestion: Add a new method {{public Map<String,ORDER> getSortFieldMap();}}
which returns an ordered map of active sort fields. An example implementation is shown below
(here as a utility method living outside SolrQuery; the rewrite should be trivial)

public Map<String, ORDER> getSortFieldMap(SolrQuery query) {
    String[] actualSortFields = query.getSortFields();
    if (actualSortFields == null || actualSortFields.length == 0)
        return Collections.emptyMap();

    Map<String, ORDER> sortFieldMap = new LinkedHashMap<String, ORDER>();
    for (String sortField : actualSortFields) {
        String[] fieldSpec = sortField.split(" ");
        sortFieldMap.put(fieldSpec[0], ORDER.valueOf(fieldSpec[1]));

    return sortFieldMap;

For what it's worth, this is possible client code:

System.out.println("Active sorts");

Map<String, ORDER> fieldMap = getSortFieldMap(query);
for (String field : fieldMap.keySet()) {
   System.out.println("- " + field + "; dir=" + fieldMap.get(field));

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message