Apache Lucene open-source search software
SOLR-7409: Sort datimport handlers in the admin UI
Shawn Heisey62b73edde109
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 59b0b1beb10..2d9b9b809e0 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -308,6 +308,10 @@ Other Changesin solr/server/solr/configsets instead of example and harden error checking / validationlogic. (hossman, Timothy Potter)+* SOLR-7409: When there are multiple dataimport handlers defined, the admin UI+ was listing them in a random order. Now they are sorted in a natural order+ that handles numbers properly. (Jellyfrog via Shawn Heisey)+================== 5.1.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this releasediff --git a/solr/licenses/javacscript-natural-sort-NOTICE.txt b/solr/licenses/javacscript-natural-sort-NOTICE.txtnew file mode 100644index 00000000000..576048b0045--- /dev/null+++ b/solr/licenses/javacscript-natural-sort-NOTICE.txt@@ -0,0 +1,5 @@+javascript-natural-sort is a javascript library for sorting data with embedded+numbers naturally, the way a human would expect.+https://github.com/jarinudom/naturalSort.js++javascript-natural-sort is licensed under the MIT license.\ No newline at end of filediff --git a/solr/licenses/javascript-natural-sort-LICENSE-MIT.txt b/solr/licenses/javascript-natural-sort-LICENSE-MIT.txtnew file mode 100644index 00000000000..e7a4eb16287--- /dev/null+++ b/solr/licenses/javascript-natural-sort-LICENSE-MIT.txt@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2011 Jim Palmer and other contributors++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.\ No newline at end of filediff --git a/solr/webapp/web/js/lib/naturalSort.js b/solr/webapp/web/js/lib/naturalSort.jsnew file mode 100644index 00000000000..896233a1182--- /dev/null+++ b/solr/webapp/web/js/lib/naturalSort.js@@ -0,0 +1,85 @@+/*++naturalSort.js+- by Jim Palmer and other contributors++The MIT License (MIT)++Copyright (c) 2011 Jim Palmer and other contributors++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.++*/++# naturalSort.js 0.7.0+# https://github.com/jarinudom/naturalSort.js+# (c) 2011 Jim Palmer and other contributors+# naturalSort.js may be freely distributed under the MIT license.+window.naturalSort = (a, b) ->+ re = /(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/g+ sre = /(^[ ]*|[ ]*$)/g+ dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/+ hre = /^0x[0-9a-f]+$/i+ ore = /^0/+ i = (s) ->+ naturalSort.insensitive and ('' + s).toLowerCase() or '' + s++ # convert all to strings strip whitespace+ x = i(a).replace(sre, '') or ''+ y = i(b).replace(sre, '') or ''++ # chunk/tokenize+ xN = x.replace(re, '\u0000$1\u0000').replace(/\0$/, '').replace(/^\0/, '').split('\u0000')+ yN = y.replace(re, '\u0000$1\u0000').replace(/\0$/, '').replace(/^\0/, '').split('\u0000')++ # numeric, hex or date detection+ xD = parseInt(x.match(hre), 16) or (xN.length isnt 1 and x.match(dre) and Date.parse(x))+ yD = parseInt(y.match(hre), 16) or xD and y.match(dre) and Date.parse(y) or null+ oFxNcL = undefined+ oFyNcL = undefined++ # first try and sort Hex codes or Dates+ if yD+ return -1 if xD < yD+ return 1 if xD > yD++ # natural sorting through split numeric strings and default strings+ cLoc = 0+ numS = Math.max(xN.length, yN.length)++ while cLoc < numS+ # find floats not starting with '0', string or 0 if not defined (Clint Priest)+ oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0+ oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0++ # handle numeric vs string comparison - number < string - (Kyle Adams)+ if isNaN(oFxNcL) != isNaN(oFyNcL)+ return (if (isNaN(oFxNcL)) then 1 else -1)++ # Rely on string comparison of different types - i.e. '02' < 2 != '02' < '2'+ else if typeof oFxNcL != typeof oFyNcL+ oFxNcL += ''+ oFyNcL += ''++ return -1 if oFxNcL < oFyNcL+ return 1 if oFxNcL > oFyNcL++ cLoc++++ return 0diff --git a/solr/webapp/web/js/main.js b/solr/webapp/web/js/main.jsindex 65fbea6ee97..2a7c32a3d47 100644--- a/solr/webapp/web/js/main.js+++ b/solr/webapp/web/js/main.js@@ -32,6 +32,7 @@ require'lib/order!lib/ZeroClipboard','lib/order!lib/d3','lib/order!lib/chosen',+ 'lib/order!lib/naturalSort','lib/order!scripts/app','lib/order!scripts/analysis',diff --git a/solr/webapp/web/js/scripts/dataimport.js b/solr/webapp/web/js/scripts/dataimport.jsindex 10244f32114..ef2b896b4c0 100644--- a/solr/webapp/web/js/scripts/dataimport.js+++ b/solr/webapp/web/js/scripts/dataimport.js@@ -45,7 +45,7 @@ sammy.binddataimport_handlers.push( key );}}- params.callback( dataimport_handlers );+ params.callback( dataimport_handlers.sort(naturalSort) );},error : function( xhr, text_status, error_thrown){