<commit_before>define([
	"dijit/form/FilteringSelect","dojo/_base/declare",
	"dojo/store/JsonRest","dojo/_base/lang","dojo/when"
], function(
	FilteringSelect, declare, 
	Store,lang,when
){
	
	return declare([FilteringSelect], {
		apiServiceUrl: window.App.dataAPI,
		promptMessage:'Scientific name of the organism being annotated.',
		missingMessage:'Scientific Name must be provided.',
		placeHolder:'e.g. Bacillus Cereus',
		searchAttr: "taxon_id",
        resultFields: ["taxon_name","taxon_id","taxon_rank", "lineage_names"],
        rankAttrs: ["taxon_rank"],
        subStringAttrs: ["taxon_name"],
        intAttrs:["taxon_id"],
        rankList:["species","no rank","genus","subspecies","family","order","class","phylum","species group","suborder","varietas","species subgroup","subclass","subgenus","forma","superphylum","superkingdom","tribe","subfamily","subphylum"],
		//query: "?&select(taxon_name)",
		queryExpr: "*${0}*",
		pageSize: 25,
		highlightMatch: "all",
		autoComplete: false,
		store: null,
		constructor: function(){
			var _self=this;
			if (!this.store){
				this.store = new Store({target: this.apiServiceUrl + "/taxonomy/", idProperty: "taxon_id", headers: {accept: "application/json"}});
			}

			var orig = this.store.query;
			this.store.query = lang.hitch(this.store, function(query,options){
				console.log("query: ", query);
				console.log("Store Headers: ", _self.store.headers);
				var q = "?";
                var extraSearch=[];
                var qString=query[_self.searchAttr].toString().replace(/\*|\[|\]/g,'');

                var rankParts=[];
                _self.rankList.forEach(function(rank){
                    var re = new RegExp("(\\b)"+rank+"(\\b)","gi");
                    var newQString = qString.replace(re, "");
                    if (newQString != qString){
                        rankParts.push(rank);
                        qString= newQString.trim();
                    }
                });
                
                var queryParts= qString ? qString.split(/[ ,]+/) : [];

                rankParts.forEach(function(qPart){
                    _self.rankAttrs.forEach(function(item){
                        extraSearch.push('eq('+item + ',"' + qPart + '")');
                    });
                });

                queryParts.forEach(function(qPart){
                    _self.intAttrs.forEach(function(item){
                        if(!isNaN(qPart) && qPart){ //only if its a number
                            extraSearch.push("eq("+item + "," + qPart + ")");
                        }
                    });
                    _self.subStringAttrs.forEach(function(item){
                        extraSearch.push("eq("+item + "," + qPart + ")"); //for this attribute value an exact match valued more
                        extraSearch.push("eq("+item + ",*" + qPart + "*)");
                    });
                });
                if(queryParts.lenth){
                    _self.subStringAttrs.forEach(function(item){
                        extraSearch.push("eq("+item + ",*" + queryParts.join('*') + "*)");
                    });
                }

                q+="or("+extraSearch.join(',')+")";

				if (_self.queryFilter) {
					q+=_self.queryFilter
				}

				if (_self.resultFields && _self.resultFields.length>0) {
					q += "&select(" + _self.resultFields.join(",") + ")";
				}
                //var re = new RegExp("\\s+","gi");
                //q=q.replace(re,"+"); //hack appropriate web api handling spaces
				console.log("Q: ", q);
				return orig.apply(_self.store,[q,options]);
			});	
		},
        onChange: function(){
			var _self=this;
            var taxObj=_self.get("item");
            _self.set("displayedValue", _self.labelFunc(taxObj,null));
        },
		isValid: function(){
			return (!this.required || this.get('displayedValue') != "");
		},
		labelFunc: function(item, store){
			var label="[" + item.taxon_id + "] ["+item.taxon_rank+"] "  + item.taxon_name;
			return label;
		},

		_setDisplayedValueAttr: function(/*String*/ label, /*Boolean?*/ priorityChange){
			// summary:
			//		Hook so set('displayedValue', label) works.
			// description:
			//		Sets textbox to display label. Also performs reverse lookup
			//		to set the hidden value.  label should corresponding to item.searchAttr.

			if(label == null){ label = ''; }

			// This is called at initialization along with every custom setter.
			// Usually (or always?) the call can be ignored.   If it needs to be
			// processed then at least make sure that the XHR request doesn't trigger an onChange()
			// event, even if it returns after creation has finished
			if(!this._created){
				if(!("displayedValue" in this.params)){
					return;
				}
				priorityChange = false;
			}

			if (typeof text != 'undefined') {
				text = text.replace(/\ /g,"%20");
			}

			// Do a reverse lookup to map the specified displayedValue to the hidden value.<commit_msg>SOLR version with ranking qf parameter<commit_after>define([
	"dijit/form/FilteringSelect","dojo/_base/declare",
	"dojo/store/JsonRest","dojo/_base/lang","dojo/when"
], function(
	FilteringSelect, declare, 
	Store,lang,when
){
	
	return declare([FilteringSelect], {
		apiServiceUrl: window.App.dataAPI,
		promptMessage:'Scientific name of the organism being annotated.',
		missingMessage:'Scientific Name must be provided.',
		placeHolder:'e.g. Bacillus Cereus',
		searchAttr: "taxon_id",
        resultFields: ["taxon_name","taxon_id","taxon_rank", "lineage_names"],
        rankAttrs: ["taxon_rank"],
        subStringAttrs: ["taxon_name"],
        promoteAttrs: ["taxon_id^3","taxon_rank^2"],
        intAttrs:["taxon_id"],
        rankList:["species","no rank","genus","subspecies","family","order","class","phylum","species group","suborder","varietas","species subgroup","subclass","subgenus","forma","superphylum","superkingdom","tribe","subfamily","subphylum"],
		//query: "?&select(taxon_name)",
		queryExpr: "${0}",
		pageSize: 25,
		highlightMatch: "all",
		autoComplete: false,
		store: null,
        constructor:function(){
            this.constructorSOLR();
        },
        
		constructorSOLR: function(){
			var _self=this;
			if (!this.store){
				this.store = new Store({target: this.apiServiceUrl + "/taxonomy/", idProperty: "taxon_id", headers: {accept: "application/json", "content-type": "application/solrquery+x-www-form-urlencoded"}});
			}

			var orig = this.store.query;
			this.store.query = lang.hitch(this.store, function(query,options){
				console.log("query: ", query);
				console.log("Store Headers: ", _self.store.headers);
				var q = "?q=";
                var extraSearch=[];
                var qString=query[_self.searchAttr].toString().replace(/\.\*|\[|\]/g,'');

                var rankParts=[];
                _self.rankList.forEach(function(rank){
                    var re = new RegExp("(\\b)"+rank+"(\\b)","gi");
                    var newQString = qString.replace(re, "");
                    if (newQString != qString){
                        rankParts.push(rank);
                        qString= newQString.trim();
                    }
                });
                
                var queryParts= qString ? qString.split(/[ ,]+/) : [];

                rankParts.forEach(function(qPart){
                    _self.rankAttrs.forEach(function(item){
                        extraSearch.push('('+item + ':' + qPart + ')');
                    });
                });

                queryParts.forEach(function(qPart){
                    _self.intAttrs.forEach(function(item){
                        if(!isNaN(qPart) && qPart){ //only if its a number
                            extraSearch.push("("+item + ":" + qPart + ")");
                        }
                    });
                    _self.subStringAttrs.forEach(function(item){
                        if (qPart.length > 1){
                            extraSearch.push("("+item + ":" + qPart + ")"); //for this attribute value an exact match valued more
                            extraSearch.push("("+item + ":*" + qPart + "*)");
                        }
                    });
                });
                if(queryParts.length){
                    _self.subStringAttrs.forEach(function(item){
                        extraSearch.push("("+item + ":*" + queryParts.join('*') + "*)");
                    });
                }

                q+="("+extraSearch.join(' OR ')+")";

				if (_self.queryFilter) {
					q+=_self.queryFilter
				}

				if (_self.resultFields && _self.resultFields.length>0) {
					q += "&fl=" + _self.resultFields.join(",");
				}
				if (_self.promoteAttrs && _self.promoteAttrs.length>0) {
					q += '&qf="' + _self.promoteAttrs.join(" ")+'"';
				}
                //var re = new RegExp("\\s+","gi");
                //q=q.replace(re,"+"); //hack appropriate web api handling spaces
				console.log("Q: ", q);
				return orig.apply(_self.store,[q,options]);
			});	
		},
		constructorRQL: function(){
			var _self=this;
			if (!this.store){
				this.store = new Store({target: this.apiServiceUrl + "/taxonomy/", idProperty: "taxon_id", headers: {accept: "application/json"}});
			}

			var orig = this.store.query;
			this.store.query = lang.hitch(this.store, function(query,options){
				console.log("query: ", query);
				console.log("Store Headers: ", _self.store.headers);
				var q = "?";
                var extraSearch=[];
                var qString=query[_self.searchAttr].toString().replace(/\*|\[|\]/g,'');

                var rankParts=[];
                _self.rankList.forEach(function(rank){
                    var re = new RegExp("(\\b)"+rank+"(\\b)","gi");
                    var newQString = qString.replace(re, "");
                    if (newQString != qString){
                        rankParts.push(rank);
                        qString= newQString.trim();
                    }
                });
                
                var queryParts= qString ? qString.split(/[ ,]+/) : [];

                rankParts.forEach(function(qPart){
                    _self.rankAttrs.forEach(function(item){
                        extraSearch.push('eq('+item + ',"' + qPart + '")');
                    });
                });

                queryParts.forEach(function(qPart){
                    _self.intAttrs.forEach(function(item){
                        if(!isNaN(qPart) && qPart){ //only if its a number
                            extraSearch.push("eq("+item + "," + qPart + ")");
                        }
                    });
                    _self.subStringAttrs.forEach(function(item){
                        extraSearch.push("eq("+item + "," + qPart + ")"); //for this attribute value an exact match valued more
                        extraSearch.push("eq("+item + ",*" + qPart + "*)");
                    });
                });
                if(queryParts.length){
                    _self.subStringAttrs.forEach(function(item){
                        extraSearch.push("eq("+item + ",*" + queryParts.join('*') + "*)");
                    });
                }

                q+="or("+extraSearch.join(',')+")";

				if (_self.queryFilter) {
					q+=_self.queryFilter
				}

				if (_self.resultFields && _self.resultFields.length>0) {
					q += "&select(" + _self.resultFields.join(",") + ")";
				}
                //var re = new RegExp("\\s+","gi");
                //q=q.replace(re,"+"); //hack appropriate web api handling spaces
				console.log("Q: ", q);
				return orig.apply(_self.store,[q,options]);
			});	
		},
        onChange: function(){
			var _self=this;
            var taxObj=_self.get("item");
            _self.textbox.value=_self.labelFunc(taxObj,null);
            //_self.set("displayedValue", _self.labelFunc(taxObj,null));
        },
		isValid: function(){
			return (!this.required || this.get('displayedValue') != "");
		},
		labelFunc: function(item, store){
			var label="[" + item.taxon_id + "] ["+item.taxon_rank+"] "  + item.taxon_name;
			return label;
		},

		_setDisplayedValueAttr: function(/*String*/ label, /*Boolean?*/ priorityChange){
			// summary:
			//		Hook so set('displayedValue', label) works.
			// description:
			//		Sets textbox to display label. Also performs reverse lookup
			//		to set the hidden value.  label should corresponding to item.searchAttr.

			if(label == null){ label = ''; }

			// This is called at initialization along with every custom setter.
			// Usually (or always?) the call can be ignored.   If it needs to be
			// processed then at least make sure that the XHR request doesn't trigger an onChange()
			// event, even if it returns after creation has finished
			if(!this._created){
				if(!("displayedValue" in this.params)){
					return;
				}
				priorityChange = false;
			}

			if (typeof text != 'undefined') {
				text = text.replace(/\ /g,"%20");
			}
            if (priorityChange){ return;}
			// Do a reverse lookup to map the specified displayedValue to the hidden value.
{'fraction_non_alphanumeric': 0.16536458333333334, 'fraction_numerical': 0.0013020833333333333, 'mean_word_length': 2.0217542235593613, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '355568', 'n_tokens_mistral': 4205, 'n_tokens_neox': 3724, 'n_words': 722}