lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hoss Man (JIRA)" <j...@apache.org>
Subject [jira] [Created] (SOLR-11132) Refactor common getSortField logic in various FieldTypes
Date Thu, 20 Jul 2017 22:44:00 GMT
Hoss Man created SOLR-11132:
-------------------------------

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


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


Mime
View raw message