-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb_lookup.gs
35 lines (30 loc) · 1.18 KB
/
bb_lookup.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function doGet(e) {
var sheets = SpreadsheetApp.openById('16jDQe5cslig1nZDjUvODy14iWMKSw-Q-aEC-m6kjUDo');
var queryStr = e.queryString;
function getSearchString(){
if(queryStr){
//assumes that there is one input value
var arr = queryStr.split("=");
var search = decodeURIComponent(arr[1]);
return search;
}
return "null";
}
function OnSearch(searchString) {
var values = sheets.getSheetByName('Sheet1').getDataRange().getValues();
for (var i = 1; i < values.length-1; i++) {
var row = values[i];
var searcharr = searchString.split(" ");
for (var k = 0;k <=searcharr.length-1; k++){
var word = searcharr[k].replace(/[^A-Za-z0-9\.]+/g, "");
if (row[0].equalsIgnoreCase(word)) {
var output = row[1];
var params = JSON.stringify({'Category': output, 'Matching word': word});
return ContentService.createTextOutput(params).setMimeType(ContentService.MimeType.JSON);
}
}
}
return ContentService.createTextOutput(JSON.stringify({'Category': 'null','Matching word': searchString})).setMimeType(ContentService.MimeType.JSON);
}
return OnSearch(getSearchString());
}