[ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13496137#comment-13496137 ]
Eirik Lygre commented on SOLR-3926: ----------------------------------- So, the patch solves my problem :-), and I'm not sure what the other use cases really are, so i'll be looking at input from others ([~yo...@apache.org], [~otis]) in order to understand the requirements. My Solr skills do not extend to functions, augmenters, etc -- at least not yet! Also, to aid the discussion, this is what we got today: * SolrQuery stores the sort field as a comma-separated string of "field direction" * SolrQuery.getSortField() returns the full string, e.g. "price asc, date desc, qty desc" * SolrQuery.getSortFields() yields [ "price asc", " date desc", " qty desc" ], including extraneous whitespace Can you provide a couple of examples of how that would/should work with the api, extending my examples below. Then, I'll see if I feel qualified, and if you guys promise to guide with qa, I'll do my best. {code} q.addSortField("price", SolrQuery.ORDER.asc); q.addSortField("date", SolrQuery.ORDER.desc); q.addSortField("qty", SolrQuery.ORDER.desc); q.removeSortField("date", SolrQuery.ORDER.desc); {code} > solrj should support better way of finding active sorts > ------------------------------------------------------- > > Key: SOLR-3926 > URL: https://issues.apache.org/jira/browse/SOLR-3926 > Project: Solr > Issue Type: Improvement > Components: clients - java > Affects Versions: 4.0 > Reporter: Eirik Lygre > Priority: Minor > Fix For: 4.1 > > Attachments: SOLR-3926.patch > > > 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": > {code} > 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(); > {code} > 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. This > will make introspection of the current sort setup much easier. > {code} > public Map<String, ORDER> getSortFieldMap() { > String[] actualSortFields = 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.trim().split(" "); > sortFieldMap.put(fieldSpec[0], ORDER.valueOf(fieldSpec[1])); > } > return Collections.unmodifiableMap(sortFieldMap); > } > {code} > For what it's worth, this is possible client code: > {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)); > } > {code} -- 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: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org