You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Eirik Lygre (JIRA)" <ji...@apache.org> on 2012/10/10 14:43:02 UTC

[jira] [Created] (SOLR-3926) solrj should support better way of finding active sorts

Eirik Lygre created SOLR-3926:
---------------------------------

             Summary: 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-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":

{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. An example implementation is shown below (here as a utility method living outside SolrQuery; the rewrite should be trivial)

{code}
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;
}
{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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Hoss Man (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13504276#comment-13504276 ] 

Hoss Man commented on SOLR-3926:
--------------------------------

Eirik:

Thanks for bring this up and working on improving things -- I think the direction your patch is is taking looks really good, but i have a few comments that i think we should try to address before committing...

1) the javadocs for the new methods should clarify that when they refer to "field" that can actually be any sortable value (ie: field names, function, "score", etc...)

2) we should add javadocs to the deprecated methods explaining why they have been deprecated (ie: what limitations they have) with \{@link\} tags pointing out the corresponding new methods

3) I don't actually see any advantage in deprecating/removing the "public String getSortField()" since it's read only ... we should just document that it returns the serialized value of the "sort" param and that for programatic access the new methods are available

Lastly: I'm really not a fan of having "setSorts" and "getSorts" use "Map<String, ORDER>" in their APIs ... (I know, it was yonik's idea on the mailing list ... i cringed when i read that).  Even if we're using LinkedHashMap unde the covers it seems like it would be far to easy for a naive user to let a HashMap make it's way to setSorts and then not understand why the final order isn't what they want.

I think it would make a _lot_ more sense to introduce a new tiny little immutable "SortClause" class that just models the String+ORDER pair, and have all of these methods take/return List<SortClause>.  (It would also help simplify the javadocs for all these methods, because only the SortClause class would need to explain what the legal values are for the String, w/o cut/pasting on each of SolrQuery methods).

What do you think?
                
> 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, 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Updated] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
     [ 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

This is a patch to implement SolrQuery.getSortFieldMap(), a better way to introspect a SolrQuery for sort information. The patch contains javadoc for the method, and a new unit test that verifies the implementation.
                
> 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
>         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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Updated] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
     [ 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

Renaming and a minor optimization of the private function serializeSorts(). 
                
> 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, 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Comment Edited] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13496137#comment-13496137 ] 

Eirik Lygre edited comment on SOLR-3926 at 11/13/12 12:36 PM:
--------------------------------------------------------------

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 ([~yonik@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}

                
      was (Author: elygre):
    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 ([~yonik@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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Updated] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
     [ 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

This patch implements the API as discussed above. The patch contains javadoc and unit tests, and was built against http://svn.apache.org/repos/asf/lucene/dev/branches/branch_4x.

This patch solves the original requirements that led to this issue (introspection of active sorts), and hopefully also the requirements of the Solr project (as represented by [~yonik@apache.org] and [~hossman]).
                
> 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, 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<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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13498352#comment-13498352 ] 

Eirik Lygre commented on SOLR-3926:
-----------------------------------

Things that seem simple sometimes are. Sometimes they're not :-)

First, I've found a bug in the current implementation of removeSortField() (not from my patch, but in the release). It works as follows:

- addSortField() concatinates the "sort" parameter, using a comma with no whitespace. Four fields would be "a asc,b asc,c asc,d asc"
- getSortFields() now returns a string array free from whitespace: [ "a asc", "b asc", "c asc", "d asc" ]
- removeSortField("c", ASC) first creates the partial string to remove, e.g. "c asc", then joins all getSortFields() not equal() the string, yielding [ "a asc", "b asc", "d asc" ]
- However, removeSortField() uses join with whitespace, creating "a asc, b asc, d asc"
- getSortFields() now returns [ "a asc", " b asc", " d asc"], with a space at the beginning of the last two elements
- removeSortField("b", ASC) will now fail, since the partial string "b asc" is not equal() the element " b asc"

The problem can be shown in this (new) test case:

{code}
public void testSolrQuerySortRemove() {
  SolrQuery q = new SolrQuery("dog");
  q.addSortField("price", SolrQuery.ORDER.asc);
  q.addSortField("date", SolrQuery.ORDER.desc);
  q.addSortField("qty", SolrQuery.ORDER.desc);
  q.removeSortField("date", SolrQuery.ORDER.desc);
  Assert.assertEquals(2, q.getSortFields().length);
  q.removeSortField("qty", SolrQuery.ORDER.desc);
  q.removeSortField("price", SolrQuery.ORDER.asc);
  Assert.assertEquals(null, q.getSortFields());
}
{code}

The easiest (and also most robust) fix would be to use a white-space aware expression in getSortFields(), e.g. replacing {{s.split(",")}} with {{s.split(", *")}}, and reuse getSortField() inside removeSortField():

{code}
public String[] getSortFields() {
  String s = getSortField();
  if (s==null) return null;
  return s.trim().split(", *");
}

public SolrQuery removeSortField(String field, ORDER order) {
  String[] sorts = getSortFields();
  if (sorts != null) {
    String removeSort = toSortString(field, order);
    String s = join(sorts, ", ", removeSort);
    if (s.length()==0) s=null;
    this.set(CommonParams.SORT, s);
  }
  return this;
}
{code}

I can include this fix in my patch under this jira, but I guess there might also be a desire for either a separate jira or a separate patch, or both. I don't know the Solr project culture on this, so I'm asking Otis and Yonik for advice. What do you guys think?

Second, on the bigger suggestion from Yonik (to work on symbolic form rather than the serialized string), this will change some semantics, in that it is today possible to combine the use of .set("sort", "<somesortspec>") with addSortField(), removeSortField(), etc, and this will probably not be possible with the other api. It *may* get better, but it *will* change behaviour. My suggestion would be to apply this patch first, then think the other one properly through, including discussions on the list. Again, what do you guys think?

                
> 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Otis Gospodnetic (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13495847#comment-13495847 ] 

Otis Gospodnetic commented on SOLR-3926:
----------------------------------------

Seems useful and the patch is very small, straight-forward, and clean.
                
> 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Yonik Seeley (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13504303#comment-13504303 ] 

Yonik Seeley commented on SOLR-3926:
------------------------------------

bq. Lastly: I'm really not a fan of having "setSorts" and "getSorts" use "Map<String, ORDER>" in their APIs ... (I know, it was yonik's idea on the mailing list ... i cringed when i read that).

I was just running with what seemed to be the implied requirement (which appeared to be random access-by-name to the sort criteria).  Thinking about it a second longer though, I can't see any obvious use cases for that.  List<SortClause> does seem more natural.
                
> 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, 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13505483#comment-13505483 ] 

Eirik Lygre commented on SOLR-3926:
-----------------------------------

I'll take the blame for guiding Yonik down the Map-path; at the time (while parsing the sort-field), returning a LinkedHashMap was an easy way to achieve the business objectives. Then, as the idea developed, it became less so. Anyway, that's why we review, right?

Here is an extended view of my current implementation. It will probably not be like this, ref questions below :-)

{code}
public String getSortField();

public SolrQuery setSorts(List<SortClause> value);
public SolrQuery clearSorts();
public List<SortClause> getSorts();
public SolrQuery setSort(SortClause sortClause);
public SolrQuery addSort(SortClause sortClause);
public SolrQuery addOrUpdateSort(SortClause sortClause);
public SolrQuery removeSort(String itemName);

public static class SortClause {
  public static SortClause create (String item, ORDER order);
  public static SortClause create (String item, String order)
  public static SortClause asc (String item);
  public static SortClause desc (String item);
  public String getItem();
  public ORDER getOrder();
}
{code}

Some questions, illustrated by code examples. Some questions relate to apis shown above, and are REMOVE? questions; some questions relate to apis *not* shown above, and are ADD? questions. Note that some of the examples use stuff from other

{code}
// Usage, per the api above
query.setSort(SolrQuery.SortClause.desc("rating"));
query.setSort(SolrQuery.SortClause.create("rating", SolrQuery.ORDER.desc));
query.setSort(SolrQuery.SortClause.create("rating", SortQuery.ORDER.valueOf("desc")));
query.setSort(SolrQuery.SortClause.create("rating", "asc"));
query.remove("rating");
{code}


I want to retain query.removeSort(String), because that's really the use case (remove sort based on item name, ignoring ordering). I'm not really sure about query.removeSort(SortClause), which does in fact only use the item name, but it would be symmetrical to the add-functions.

{code}
// Q1: Should we REMOVE query.removeSort (String)
query.addSort(new SolrQuery.SortClause("rating", SolrQuery.ORDER.desc));
query.addSort(new SolrQuery.SortClause("price", SolrQuery.ORDER.asc));
query.removeSort("rating");

// Q2: Should we ADD query.removeSort(SortClause)?
query.addSort(new SolrQuery.SortClause("rating", SolrQuery.ORDER.desc));
query.addSort(new SolrQuery.SortClause("price", SolrQuery.ORDER.asc));
query.removeSort(new SolrQuery.SortClause("price", SolrQuery.ORDER.desc));	// Remove irregardless of order
{code}


We might build convenience functions query.xxxSort (String, order) and query.xxxSort (String,String) as shown below. It would make usage simpler, but come with a footprint. The SortClause.asc(), .desc() and .create() factory functions described below make this less needed, I think:

{code}
// Q3: Should we ADD convenience functions query.xxxSort (String, order)
query.addSort("price", SolrQuery.ORDER.asc);

// Q4: Should we ADD convenience functions query.xxxSort (String, String)
query.addSort("price", "asc");
{code}


The api currently has convenience functions for creating SortClause. The functions asc() and desc() make it easier (and more compact) to create SortClause. The create() functions are there for symmetry (always use static methods instead of constructors). The constructors aren't public, but maybe they should be?

{code}
// Q5: Should we REMOVE asc() and desc() convenience factory methods:
query.setSort(SolrQuery.SortClause.desc("rating"));
query.setSort(SolrQuery.SortClause.asc("rating"));

// Q6: Should we REMOVE create(String,ORDER) convenience factory method (use constructor instead)
query.setSort(SolrQuery.SortClause.create("rating", SolrQuery.ORDER.desc));
query.setSort(SolrQuery.SortClause.create("rating", SolrQuery.ORDER.valueOf("desc")));

// Q7:Should we REMOVE create(String,ORDER) convenience factory method (Complements Q5, when the order is in fact a string)
query.setSort(SolrQuery.SortClause.create("rating", "desc"));

// Q8: Should we ADD a simple constructor, typically instead of Q5-Q7?
query.setSort(new SolrQuery.SortClause("rating", SolrQuery.ORDER.desc));
query.setSort(new SolrQuery.SortClause("rating", SolrQuery.ORDER.valueOf("desc")));
{code}

A couple of other items:

Q9: Currently, SortClause is an inner class of SolrQuery. Let me know if this is an issue
Q10: What the heck do we call "the thing to sort". I don't want to call it a "field", since it can be many other things. I've chosen to call it an "item", but is there another, better name?
Q11: Should we have SortClause.hashCode() and SortClause.equals()?
                
> 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, 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Updated] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
     [ 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<String, ORDER> value);
SolrQuery clearSorts();
Map<String, ORDER> 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<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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Yonik Seeley (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13495854#comment-13495854 ] 

Yonik Seeley commented on SOLR-3926:
------------------------------------

Splitting on whitespace isn't likely to work to well with everything we can put in the field list these days (functions, augmenters, etc).
Why not keep sort information in the client code in symbolic form (i.e. not a serialized string), manipulate it there, and then set to the SolrQuery right before submitting it?
                
> 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Commented] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
    [ 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 ([~yonik@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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Updated] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eirik Lygre updated SOLR-3926:
------------------------------

    Description: 
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}

  was:
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. An example implementation is shown below (here as a utility method living outside SolrQuery; the rewrite should be trivial)

{code}
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;
}
{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}

    
> 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
>
> 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Comment Edited] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Otis Gospodnetic (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13495847#comment-13495847 ] 

Otis Gospodnetic edited comment on SOLR-3926 at 11/13/12 1:56 AM:
------------------------------------------------------------------

+1
Seems useful and the patch is very small, straight-forward, and clean.
                
      was (Author: otis):
    Seems useful and the patch is very small, straight-forward, and clean.
                  
> 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Updated] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Eirik Lygre (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eirik Lygre updated SOLR-3926:
------------------------------

    Affects Version/s:     (was: 4.0-BETA)
                       4.0
    
> 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
>
> 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. An example implementation is shown below (here as a utility method living outside SolrQuery; the rewrite should be trivial)
> {code}
> 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;
> }
> {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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] [Updated] (SOLR-3926) solrj should support better way of finding active sorts

Posted by "Otis Gospodnetic (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Otis Gospodnetic updated SOLR-3926:
-----------------------------------

    Fix Version/s: 4.1
    
> 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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org