Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-11132

Refactor common getSortField logic in various FieldTypes

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.1, master (8.0)
    • Component/s: None
    • Security Level: Public (Default Security Level. Issues are Public)
    • Labels:
      None

      Description

      This pattern exists a lot w/ some minor fluxuations in copy/paste variation...

        @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;
        }
      

      We should refactor it into a helper method along the lines of...

        @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;
        }
      

      So it can be re-used via...

        @Override
        public SortField getSortField(SchemaField field, boolean top) {
          return getSortField(field, top, SortField.Type.SOMETIME, 
                              SOMECLASS.MIN_VALUE, SOMECLASS.MAX_VALUE);
        }
      

        Attachments

        1. SOLR-11132.patch
          23 kB
          Hoss Man
        2. SOLR-11132.patch
          10 kB
          Jason Gerlowski

          Issue Links

            Activity

              People

              • Assignee:
                hossman Hoss Man
                Reporter:
                hossman Hoss Man
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: