if (dims.length===1)// If there is only one dimension we add year as a dimension, since it is the standard dim.
dims.splice(0,0,'min_year')
letresult=req.result;
letresultOriginal=req.result;
letdimsValues={};
result.forEach((r)=>{
letdimsValues={};// Object with the id's of dims
letdimsNames={}// Object the names of the dims
resultOriginal.forEach((r)=>{
dims.forEach((dim)=>{
letrqfName=rqf.fieldValues[dim].resultField;
letrqfName=rqf.fieldValues[dim].resultField;// rqf with the id value
letsecondaryRqfName=rqfName.slice(0,-2)+'name'// rqf with the 'name' value
if (typeofrqfName==='object'){// if the resultField is an array we verify what the rqf with the name field is
rqfName.forEach((name)=>{
if (name.includes("_id"))
rqfName=name;
else
secondaryRqfName=name;
})
}
if (typeofdimsValues[rqfName]==='undefined'){
dimsValues[rqfName]=[];
dimsNames[secondaryRqfName]=[];
}
if (dimsValues[rqfName].indexOf(r[rqfName])===-1){
if (['school','city','state','region'].includes(dim)){// those should be ordered by its name
letnamePosition=binarySearch(r[secondaryRqfName],dimsNames[secondaryRqfName],0,dimsNames[secondaryRqfName].length)// find the position of the name in alphabetical order and keep the names vector ordered