1riot.tag2('riot-solr-range-select', '<h5 if="{!opts.label_placeholder}"> {opts.label} </h5> <select if="{showLow()}" onchange="{parseEvent(setLow)}"> <option if="{opts.label_placeholder}" __selected="{getLow()===\'*\'}" disabled>{min_prefix}{opts.label} </option> <option each="{option in getLowOptions()}" value="{getNumber(option)}" __selected="{getNumber(getLow())===getNumber(option)}" __disabled="{getNumber(option)>getHigh() && getHigh() != \'*\'}"> {option} </option> </select> <select if="{showHigh()}" onchange="{parseEvent(setHigh)}"> <option if="{opts.label_placeholder}" __selected="{getHigh()===\'*\'}" disabled>{max_prefix}{opts.label} </option> <option each="{option in getHighOptions()}" value="{getNumber(option)}" __selected="{getNumber(getHigh())===getNumber(option)}" __disabled="{getNumber(option)<getLow() && getLow() != \'*\'}"> {option} </option> </select>', '', 'data-facetid="{instance.id}"', function(opts) { 2 this.mixin('RiotSolrConnection'); 3 this.getFacetDefinition = function() { 4 for(var f in this.RiotSolrFacets) { 5 if(this.RiotSolrFacets[f].definition.data.field === this.opts.facet_field) { 6 return this.RiotSolrFacets[f]; 7 } 8 } 9 return false; 10 }; 11 (function ($, tag) { 12 var facetOpts = tag.getFacetDefinition(), 13 rsOpts = facetOpts.definition.settings.settings.riot_solr; 14 if(typeof rsOpts !== 'undefined') { 15 if(typeof rsOpts.facet_label !== 'undefined') { 16 opts.label = rsOpts.facet_label; 17 } 18 else { 19 opts.label = facetOpts.definition.settings_global.settings['riotjs_label']; 20 } 21 if(typeof facetOpts.definition.settings.settings.label_placeholder !== 'undefined') { 22 opts.label_placeholder = facetOpts.definition.settings.settings.label_placeholder; 23 } 24 else { 25 opts.label_placeholder = 0; 26 } 27 } 28 29 tag.instance = new AjaxSolr.RiotSolrFacetRanges({ 30 id: 'RiotSolrFacetRanges-' + facetOpts.field, 31 field: facetOpts.field, 32 label: opts.label, 33 observable: tag, 34 'stats': 'true', 35 'stats.field': facetOpts.field 36 }); 37 38 if (!opts.hide_prefix) { 39 tag.min_prefix = 'Min '; 40 tag.max_prefix = 'Max '; 41 } 42 43 tag.showLow = function(){ 44 if (facetOpts.definition.settings.settings.expose_min){ 45 return true; 46 } 47 return false; 48 }; 49 50 tag.showHigh = function(){ 51 if (facetOpts.definition.settings.settings.expose_max){ 52 return true; 53 } 54 return false; 55 }; 56 57 tag.getLowOptions = function (){ 58 var mo; 59 if(facetOpts.definition.settings.settings.min_opts) { 60 mo = facetOpts.definition.settings.settings.min_opts; 61 if(!tag.minOpts) { 62 tag.minOpts = mo.split(/\r?\n/); 63 } 64 } 65 return tag.minOpts; 66 }; 67 68 tag.getHighOptions = function (){ 69 var mo; 70 if(facetOpts.definition.settings.settings.max_opts) { 71 mo = facetOpts.definition.settings.settings.max_opts; 72 if(!tag.maxOpts) { 73 tag.maxOpts = mo.split(/\r?\n/); 74 } 75 } 76 return tag.maxOpts; 77 }; 78 79 tag.getLow = function (){ 80 return getWidgetRange()[0]; 81 }; 82 83 tag.getHigh = function (){ 84 return getWidgetRange()[1]; 85 }; 86 87 function getWidgetRange(){ 88 var fq = getFq(); 89 if(!fq){ 90 return ['*', '*']; 91 } 92 else{ 93 return parseFq(fq); 94 } 95 } 96 97 function getFq(){ 98 var r = new RegExp('^-?' + tag.RiotSolrManager.regexEscape(tag.instance.getTag()) + '.*:.*'); 99 var fq = tag.RiotSolrManager.store.find('fq', r); 100 if(!fq){ 101 return false;
102 } 103 return tag.RiotSolrManager.store.params['fq'][fq.toString()].val() 104 } 105 106 function parseFq(str){ 107 try{ 108 return str.split(':') 109 .pop() 110 .replace(/[\[\]']+/g,'') 111 .toLowerCase() 112 .split(' to '); 113 } 114 catch(err){ 115 return ['*', '*']; 116 } 117 } 118 119 tag.parseEvent = function(setter){ 120 return function(e){ 121 setter(e.target.value); 122 } 123 }; 124 125 tag.setLow = function (value){ 126 var range = [value, tag.getHigh()] 127 setWidgetRange(range); 128 }; 129 130 tag.setHigh = function (value){ 131 var range = [tag.getLow(), value] 132 setWidgetRange(range); 133 }; 134 135 function setWidgetRange(arr){ 136 var min = arr[0] === "*" ? getRangeMin() : arr[0]; 137 var max = arr[1] === "*" ? getRangeMax() : arr[1]; 138 var range = '[' + min.toString() + ' TO ' + max.toString() + ']'; 139 if (tag.instance['set'].call(tag.instance, range)) { 140 tag.instance.doRequest(); 141 } 142 } 143 144 function getRangeMin(){ 145 try { 146 return tag.instance.manager.response.stats.stats_fields[tag.instance['stats.field']].min; 147 } 148 catch (e) { 149 return '*'; 150 } 151 } 152 153 function getRangeMax(){ 154 try { 155 return tag.instance.manager.response.stats.stats_fields[tag.instance['stats.field']].max; 156 } 157 catch (e) { 158 return '*'; 159 } 160 } 161 162 tag.on('RiotSolrFacetRangesUpdate', function (results) { 163 if (results.field === facetOpts.field && results.widget === 'RiotSolrFacetRanges') { 164 tag.update(); 165 } 166 }); 167 168 tag.opts.manager.observable.on('RiotSolrAddWidgets', function (manager) { 169 manager.addWidget(tag.instance); 170 }); 171 172 tag.getNumber = function(i) { 173 if (typeof i === 'number') { 174 return i; 175 } 176 if (!i) { 177 return 0; 178 } 179 return parseFloat(i.replace(/[^0-9.]/g, "")) 180 } 181 })(jQuery, this); 182});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.