Return-Path: X-Original-To: apmail-lucene-dev-archive@www.apache.org Delivered-To: apmail-lucene-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 189ECD7B0 for ; Wed, 21 Nov 2012 21:53:01 +0000 (UTC) Received: (qmail 79839 invoked by uid 500); 21 Nov 2012 21:52:59 -0000 Delivered-To: apmail-lucene-dev-archive@lucene.apache.org Received: (qmail 79749 invoked by uid 500); 21 Nov 2012 21:52:59 -0000 Mailing-List: contact dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list dev@lucene.apache.org Received: (qmail 79680 invoked by uid 99); 21 Nov 2012 21:52:59 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Nov 2012 21:52:59 +0000 Date: Wed, 21 Nov 2012 21:52:59 +0000 (UTC) From: "Eirik Lygre (JIRA)" To: dev@lucene.apache.org Message-ID: <1050324650.14351.1353534779488.JavaMail.jiratomcat@arcas> In-Reply-To: <264805267.19474.1349872982950.JavaMail.jiratomcat@arcas> Subject: [jira] [Updated] (SOLR-3926) solrj should support better way of finding active sorts MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Eirik Lygre updated SOLR-3926: ------------------------------ Attachment: SOLR-3926.patch Having published a couple of revisions on the dev mailing list, here is a proposed patch. It comprises the following: - Fixes to removeSortField() and getSortFields() (ref comments in this issue) - Deprecation of setSortField(), addSortField(), removeSortField(), getSortFields() and getSortField(), in favor of a map-based symbolic implementation - New symbolic sort api as shown below - Javadoc for the new api - Updated and new unit tests for all of the above {code} SolrQuery setSorts(Map value); SolrQuery clearSorts(); Map getSorts(); SolrQuery setSort(String field, ORDER order); SolrQuery addSort(String field, ORDER order); SolrQuery addOrUpdateSort(String field, ORDER order); SolrQuery removeSort(String field); {code} Based on the feedback to the initial patch, this revised patch is proposed for inclusion into the next release version (4.0.1) and above. > 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, 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 getSortFieldMap();}} which returns an ordered map of active sort fields. This will make introspection of the current sort setup much easier. > {code} > public Map getSortFieldMap() { > String[] actualSortFields = getSortFields(); > if (actualSortFields == null || actualSortFields.length == 0) > return Collections.emptyMap(); > Map sortFieldMap = new LinkedHashMap(); > 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 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-unsubscribe@lucene.apache.org For additional commands, e-mail: dev-help@lucene.apache.org