-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUploadBooksToSearch.js
69 lines (56 loc) · 1.65 KB
/
UploadBooksToSearch.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var AzureSearch = require('azure-search');
var _ = require("underscore");
var client = AzureSearch({
url: "https://islamicmobility.search.windows.net",
key: process.env.SearchKey
});
/*
client.getIndex("books", function(err, index) {
if (err) console.log(err);
console.log(index);
});
*/
var data = require("./data/filesystem")
var books = data.data;
_.each(books, function(book) {
book.id = (book.title + " by " + book.author).replace(".", "").replace("/","").replace("\\","").replace(".", "").replace("/","").replace("\\","").replace(".", "")
.replace("/","").replace("\\","").replace(".", "").replace("/","").replace("\\","").replace(".", "").replace("/","").replace("\\","")
;
});
/*
client.addDocuments('books', books, function(err, confirmation){
if (err) console.log(err);
console.log ("All done");
});
*/
client.search('books', {search:'woman'}, function(err, results){
if (err) {
console.log ("YIKES!!!");
console.log(err);
return;
}
console.log("Got results. Awww yeah");
var filtered = _.map(results, function(book) {
var book2 = [];
book2.score = book['@search.score'];
book2.title = book.title;
book2.author = book.author;
book2.description = book.description;
return book2;
});
console.log(filtered);
// results is an array of matching documents
});
/*
var index = require("./bookIndexSchema.json");
console.log(index);
client.deleteIndex("books", function(err, data) {
if (err) console.log(err);
console.log("Index deleted")
client.createIndex(index, function(err, data) {
if(err) console.log(err);
console.log("created index");
})
})
*/
console.log("And now we wait...");