azure-search
Advanced tools
Comparing version 0.0.5 to 0.0.6
43
index.js
@@ -176,3 +176,44 @@ var http = require('https'); | ||
}, | ||
updateDocuments : function(indexName,documents,cb){ | ||
if (!indexName) throw new Error("indexName is not defined"); | ||
if (!documents) throw new Error("documents is not defined"); | ||
for(var i=0; i<documents.length;i++){ | ||
documents[i]["@search.action"] = "merge"; | ||
} | ||
post(['indexes', indexName, "docs", "index"], {value:documents}, function(err, data){ | ||
if (err) return cb(err); | ||
if (data && data.error) return cb(data.error); | ||
cb(null, data.value); | ||
}); | ||
}, | ||
uploadDocuments : function(indexName,documents,cb){ | ||
if (!indexName) throw new Error("indexName is not defined"); | ||
if (!documents) throw new Error("documents is not defined"); | ||
for(var i=0; i<documents.length;i++){ | ||
documents[i]["@search.action"] = "upload"; | ||
} | ||
post(['indexes', indexName, "docs", "index"], {value:documents}, function(err, data){ | ||
if (err) return cb(err); | ||
if (data && data.error) return cb(data.error); | ||
cb(null, data.value); | ||
}); | ||
}, | ||
deleteDocuments : function(indexName,keys,cb){ | ||
if (!indexName) throw new Error("indexName is not defined"); | ||
if (!keys) throw new Error("keys is not defined"); | ||
for(var i=0; i<keys.length;i++){ | ||
keys[i]["@search.action"] = "delete"; | ||
} | ||
post(['indexes', indexName, "docs", "index"], {value:keys}, function(err, data){ | ||
if (err) return cb(err); | ||
if (data && data.error) return cb(data.error); | ||
cb(null, data.value); | ||
}); | ||
}, | ||
search : function(indexName, query, cb){ | ||
@@ -179,0 +220,0 @@ if (!indexName) throw new Error("indexName is not defined"); |
{ | ||
"name": "azure-search", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A client for the Azure Search service", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ # node-azure-search | ||
This module call the Azure Search REST API. The documentation for the API is available [here](http://msdn.microsoft.com/library/azure/dn798935.aspx). | ||
This module calls the Azure Search REST API. The documentation for the API is available [here](http://msdn.microsoft.com/library/azure/dn798935.aspx). | ||
@@ -144,2 +144,2 @@ ## Installation | ||
MIT | ||
MIT |
92
test.js
// to test, first create a search service in azure, and set the url and key here. | ||
var client = require('./index')({ | ||
url: "https://xxx.search.windows.net", | ||
key:"yyy" | ||
url: "https://xxx.search.windows.net", | ||
key: "yyy" | ||
}); | ||
@@ -60,3 +60,3 @@ | ||
"id": "document1", | ||
"description": "this is the description of my document" | ||
"description": "this is the description of my unique document" | ||
} | ||
@@ -70,2 +70,86 @@ client.addDocuments("myindex", [doc1], function(err, data){ | ||
it("deletes a document", function(done){ | ||
var doc2 = { | ||
"id": "document2", | ||
"description": "this is the description of my document" | ||
}; | ||
client.addDocuments("myindex", [doc2], function(err, data){ | ||
if (err) return done("error returned"); | ||
if (!data) return done("data is null"); | ||
var key = { "id":"document2" }; | ||
client.deleteDocuments("myindex", [key], function(err, data){ | ||
if (err) return done("error returned"); | ||
if (!data) return done("data is null"); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
it("updates a document", function(done){ | ||
var doc3 = { | ||
"id": "document3", | ||
"description": "this is the description of my document" | ||
}; | ||
client.addDocuments("myindex", [doc3], function(err, data){ | ||
if (err) return done("error returned"); | ||
if (!data) return done("data is null"); | ||
//update description field | ||
doc3.description = "updated description"; | ||
client.updateDocuments("myindex", [doc3], function(err, data){ | ||
if (err) return done("error returned"); | ||
if (!data) return done("data is null"); | ||
//ensure changes were saved | ||
client.lookup("myindex", "document3", function(err, results){ | ||
if (err) return done("error returned"); | ||
if (!results) return done("results is null"); | ||
if (results.description !== doc3.description) return done("document not updated"); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it("uploads a document", function(done){ | ||
var doc4 = { | ||
"id": "document4", | ||
"description": "this is the description of my document" | ||
}; | ||
client.uploadDocuments("myindex", [doc4], function(err, data){ | ||
if (err) return done("error returned"); | ||
if (!data) return done("data is null"); | ||
//update description field | ||
doc4.description = "updated description"; | ||
client.uploadDocuments("myindex", [doc4], function(err, data){ | ||
if (err) return done("error returned"); | ||
if (!data) return done("data is null"); | ||
//ensure changes were saved | ||
client.lookup("myindex", "document4", function(err, results){ | ||
if (err) return done("error returned"); | ||
if (!results) return done("results is null"); | ||
if (results.description !== doc4.description) return done("document not updated"); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it("lists the indexes", function(done){ | ||
@@ -129,3 +213,3 @@ client.listIndexes(function(err, indexes){ | ||
it("searches", function(done){ | ||
client.search("myindex", {search:"document"}, function(err, results){ | ||
client.search("myindex", {search:"unique"}, function(err, results){ | ||
if (err) return done("error returned"); | ||
@@ -132,0 +216,0 @@ if (!results) return done("results is null"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125058
853
144