librepages/search.js

1 line
27 KiB
JavaScript
Raw Normal View History

(function(){var itemTypes=["mod","externcrate","import","struct","enum","fn","type","static","trait","impl","tymethod","method","structfield","variant","macro","primitive","associatedtype","constant","associatedconstant","union","foreigntype","keyword","existential","attr","derive","traitalias",];var TY_PRIMITIVE=itemTypes.indexOf("primitive");var TY_KEYWORD=itemTypes.indexOf("keyword");function printTab(nb){if(nb===0||nb===1||nb===2){searchState.currentTab=nb}var nb_copy=nb;onEachLazy(document.getElementById("titles").childNodes,function(elem){if(nb_copy===0){addClass(elem,"selected")}else{removeClass(elem,"selected")}nb_copy-=1});onEachLazy(document.getElementById("results").childNodes,function(elem){if(nb===0){addClass(elem,"active")}else{removeClass(elem,"active")}nb-=1})}function removeEmptyStringsFromArray(x){for(var i=0,len=x.length;i<len;++i){if(x[i]===""){x.splice(i,1);i-=1}}}var levenshtein_row2=[];function levenshtein(s1,s2){if(s1===s2){return 0}var s1_len=s1.length,s2_len=s2.length;if(s1_len&&s2_len){var i1=0,i2=0,a,b,c,c2,row=levenshtein_row2;while(i1<s1_len){row[i1]=++i1}while(i2<s2_len){c2=s2.charCodeAt(i2);a=i2;++i2;b=i2;for(i1=0;i1<s1_len;++i1){c=a+(s1.charCodeAt(i1)!==c2?1:0);a=row[i1];b=b<a?(b<c?b+1:c):(a<c?a+1:c);row[i1]=b}}return b}return s1_len+s2_len}window.initSearch=function(rawSearchIndex){var MAX_LEV_DISTANCE=3;var MAX_RESULTS=200;var GENERICS_DATA=2;var NAME=0;var INPUTS_DATA=0;var OUTPUT_DATA=1;var NO_TYPE_FILTER=-1;var searchIndex;var searchWords;var currentResults;var ALIASES={};var params=searchState.getQueryStringParams();if(searchState.input.value===""){searchState.input.value=params.search||""}function execQuery(query,searchWords,filterCrates){function itemTypeFromName(typename){for(var i=0,len=itemTypes.length;i<len;++i){if(itemTypes[i]===typename){return i}}return NO_TYPE_FILTER}var valLower=query.query.toLowerCase(),val=valLower,typeFilter=itemTypeFromName(query.type),results={},results_in_args={},results_returned={},split=valLower.split("::");removeEmptyStringsFromArray(split);function transformResults(results){var duplicates={};var out=[];for(var i=0,len=results.length;i<len;++i){var result=results[i];if(result.id>-1){var obj=searchIndex[result.id];obj.lev=result.lev;var res=buildHrefAndPath(obj);obj.displayPath=pathSplitter(res[0]);obj.fullPath=obj.displayPath+obj.name;obj.fullPath+="|"+obj.ty;if(duplicates[obj.fullPath]){continue}duplicates[obj.fullPath]=true;obj.href=res[1];out.push(obj);if(out.length>=MAX_RESULTS){break}}}return out}function sortResults(results,isType){var ar=[];for(var entry in results){if(hasOwnPropertyRustdoc(results,entry)){var result=results[entry];result.word=searchWords[result.id];result.item=searchIndex[result.id]||{};ar.push(result)}}results=ar;if(results.length===0){return[]}results.sort(function(aaa,bbb){var a,b;a=(aaa.word!==val);b=(bbb.word!==val);if(a!==b){return a-b}a=(aaa.lev);b=(bbb.lev);if(a!==b){return a-b}a=(aaa.item.crate!==window.currentCrate);b=(bbb.item.crate!==window.currentCrate);if(a!==b){return a-b}a=aaa.word.length;b=bbb.word.length;if(a!==b){return a-b}a=aaa.word;b=bbb.word;if(a!==b){return(a>b?+1:-1)}a=(aaa.index<0);b=(bbb.index<0);if(a!==b){return a-b}a=aaa.index;b=bbb.index;if(a!==b){return a-b}if((aaa.item.ty===TY_PRIMITIVE&&bbb.item.ty!==TY_KEYWORD)||(aaa.item.ty===TY_KEYWORD&&bbb.item.ty!==TY_PRIMITIVE)){return-1}if((bbb.item.ty===TY_PRIMITIVE&&aaa.item.ty!==TY_PRIMITIVE)||(bbb.item.ty===TY_KEYWORD&&aaa.item.ty!==TY_KEYWORD)){return 1}a=(aaa.item.desc==="");b=(bbb.item.desc==="");if(a!==b){return a-b}a=aaa.item.ty;b=bbb.item.ty;if(a!==b){return a-b}a=aaa.item.path;b=bbb.item.path;if(a!==b){return(a>b?+1:-1)}return 0});for(var i=0,len=results.length;i<len;++i){result=results[i];if(result.dontValidate){continue}var name=result.item.name.toLowerCase(),path=result.item.path.toLowerCase(),parent=result.item.parent;if(!isType&&!validateResult(name,path,split,parent)){result.id=-1}}return transformResults(results)}function extractGenerics(val){val=val.toLowerCase();if(val.indexOf("<")!==-1){var values=val.substring(val.indexOf("<")