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

Refactor common getSortField logic in various FieldTypes

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 7.1, 8.0
    • None
    • 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
          10 kB
          Jason Gerlowski
        2. SOLR-11132.patch
          23 kB
          Chris M. Hostetter

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            hossman Chris M. Hostetter
            hossman Chris M. Hostetter
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment