Created
May 19, 2017 11:16
-
-
Save tbnbooij/64b93215155d13eb31b6c9668e4eb948 to your computer and use it in GitHub Desktop.
Just a small function that simplifies making boolean search queries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input syntax: [["quadcopter", "quadrotor", "quadrotor helicopter"], ["motion", "dynamics"], ["control", "feedback"]] | |
// Output value: "(quadcopter OR quadrotor OR quadrotor helicopter) AND (motion OR dynamics) AND (control OR feedback)" | |
function getQuery(input_vals) { | |
var a = []; | |
var return_val = ""; | |
for (var i = 0; i < input_vals.length; i++) { | |
var temp_or = "("; | |
for(var j = 0; j < input_vals[i].length; j++) { | |
switch(j) { | |
case 0: | |
temp_or = temp_or + input_vals[i][j] + " OR"; | |
break; | |
case input_vals[i].length - 1: | |
temp_or = temp_or + " " + input_vals[i][j] + ")"; | |
break; | |
default: | |
temp_or = temp_or + " " + input_vals[i][j] + " OR"; | |
break; | |
} | |
} | |
a.push(temp_or); | |
} | |
for(var i = 0; i < a.length; i++) { | |
switch(i) { | |
case 0: | |
return_val = return_val + a[i] + " AND"; | |
break; | |
case a.length - 1: | |
return_val = return_val + " " + a[i]; | |
break; | |
default: | |
return_val = return_val + " " + a[i] + " AND"; | |
break; | |
} | |
} | |
return return_val; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment