[ 
https://issues.apache.org/jira/browse/SOLR-11132?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Hoss Man updated SOLR-11132:
----------------------------
    Attachment: SOLR-11132.patch

Thanks Jason, your patch is great!

While reviewing, and looking for any other places that should use this method I 
noticed...

* AbstractEnumField didn't follow this pattern and in fact had a bug in it when 
dealing with sortMissingFirst or sortMissingLast
** So I beefed up the enum tests and fixed that bug by leveraging your new 
method
* the "Sorting" class had some very old, and very similar (but less "schema 
aware") helper methods similar to what we're dealing with here specifically for 
Strings and Text (using SortedSetSortField).
** I've marked that class deprecated, and refactored the new method we've added 
here so existing usages of the "Sorting" helper methods can use the simpler API 
we're adding here.
** The only other usage that couldn't easily be refactored is some _very_ 
old/crufty code in "TestSort" which doesn't pay any attention to the schema at 
all -- so I created a minimal helper method in that test class to keep it 
functionaly w/o depending on the deprecated code.
* I also added javadocs for the new FieldType methods, and tweaked the param 
ordering/names (to try and be consistent with the param ordering/names in the 
SortField constructor).

I think this is good to go?  Anybody have concerns?

(NOTE: Once this is backported to 7x, we should be able to immedaitely delete 
Sorting.java from master)


> Refactor common getSortField logic in various FieldTypes
> --------------------------------------------------------
>
>                 Key: SOLR-11132
>                 URL: https://issues.apache.org/jira/browse/SOLR-11132
>             Project: Solr
>          Issue Type: Improvement
>      Security Level: Public(Default Security Level. Issues are Public) 
>            Reporter: Hoss Man
>            Assignee: Hoss Man
>         Attachments: SOLR-11132.patch, SOLR-11132.patch
>
>
> This pattern exists a lot w/ some minor fluxuations in copy/paste variation...
> {code}
>   @Override
>   public SortField getSortField(SchemaField field, boolean top) {
>     field.checkSortability();
>     Object missingValue = null;
>     boolean sortMissingLast = field.sortMissingLast();
>     boolean sortMissingFirst = field.sortMissingFirst();
>     if (sortMissingLast) {
>       missingValue = top ? SOMECLASS.MIN_VALUE : SOMECLASS.MAX_VALUE;
>     } else if (sortMissingFirst) {
>       missingValue = top ? SOMECLASS.MAX_VALUE : SOMECLASS.MIN_VALUE;
>     }
>     SortField sf = new SortField(field.getName(), SortField.Type.SOMETYPE, 
> top);
>     sf.setMissingValue(missingValue);
>     return sf;
>   }
> {code}
> We should refactor it into a helper method along the lines of...
> {code}
>   @Override
>   public static SortField getSortField(SchemaField field, boolean top, 
> SortField.Type sortType, 
>                                        Object missingLow, Object missingHigh) 
> {
>     field.checkSortability();
>     Object missingValue = null;
>     boolean sortMissingLast = field.sortMissingLast();
>     boolean sortMissingFirst = field.sortMissingFirst();
>     if (sortMissingLast) {
>       missingValue = top ? missingLow : missingHigh;
>     } else if (sortMissingFirst) {
>       missingValue = top ? missingHigh : missingLow;
>     }
>     SortField sf = new SortField(field.getName(), sortType, top);
>     sf.setMissingValue(missingValue);
>     return sf;
>   }
> {code}
> So it can be re-used via...
> {code}
>   @Override
>   public SortField getSortField(SchemaField field, boolean top) {
>     return getSortField(field, top, SortField.Type.SOMETIME, 
>                         SOMECLASS.MIN_VALUE, SOMECLASS.MAX_VALUE);
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to