-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazuresearch.js
36 lines (31 loc) · 1013 Bytes
/
azuresearch.js
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
35
36
exports.query = function (query, cb) {
var AzureSearch = require('azure-search'),
async = require('async');
var client = AzureSearch({
url: "https://arg.search.windows.net",
key:"6BDDF0E8DC8959B985436A5F6905823B"
});
// Call Azure search to get indexes
client.listIndexes(function (err, schemas) {
if (err) {
cb(err);
}
console.log("schemas: ", schemas.length);
var iterator = function(schema, callback) {
console.log("schema name: ", schema.name);
client.search(schema.name, { search: query, top: 4 }, function (err, results) {
if (err) {
return;
}
var indexResults = {
index: schema.name,
results: results
}
callback(null, indexResults);
});
};
async.map(schemas, iterator, function(err, results) {
cb(null, results);
});
});
}