node-azure-search
A JavaScript client library for the Azure Search service, which works from either from Node.js or the browser. The module is browserify compatible.
This module call the Azure Search REST API. The documentation for the API is available here.
Installation
Use npm:
$ npm install azure-search
Usage
If using from node:
var AzureSearch = require('azure-search');
var client = AzureSearch({
url: "https://XXX.search.windows.net",
key:"YYY"
});
If using in the browser:
<html>
<head>
<script src="azure-search.min.js"></script>
</head>
<body>
<script>
var client = AzureSearch({
url: "https://XXX.search.windows.net",
key:"YYYY"
});
</script>
</body>
</html>
Note that from the browser, you must have the corsOptions
set in the index schema, and only search
, suggest
, lookup
and count
will work.
A client object can then be used to create, update, list, get and delete indexes:
var schema = {
name: 'myindex',
fields:
[ { name: 'id',
type: 'Edm.String',
searchable: false,
filterable: true,
retrievable: true,
sortable: true,
facetable: true,
suggestions: false,
key: true },
{ name: 'description',
type: 'Edm.String',
searchable: true,
filterable: false,
retrievable: true,
sortable: false,
facetable: false,
suggestions: true,
key: false } ],
scoringProfiles: [],
defaultScoringProfile: null,
corsOptions: null };
client.createIndex(schema, function(err, schema){
});
client.getIndex('myindex', function(err, schema){
});
client.listIndexes(function(err, schemas){
});
client.getIndexStats('myindex', function(err, stats){
});
client.deleteIndex('myindex', function(err){
});
You can also add documents to the index, and search it:
var doc1 = {
"id": "document1",
"description": "this is the description of my document"
}
client.addDocuments('myindex', [doc1], function(err, results){
});
client.lookup('myindex', 'document1', function(){
});
client.count('myindex', function(err, count){
});
client.search('myindex', {search: "document", $top: 10}, function(err, results){
});
client.suggest('myindex', {search: "doc"}, function(err, results){
});
License
MIT