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 calls 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 = ;var client = ;
If using in the browser:
Note that from the browser, you must have the
corsOptions
set in the index schema, and onlysearch
,suggest
,lookup
andcount
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 key: true name: 'description' type: 'Edm.String' searchable: true filterable: false retrievable: true sortable: false facetable: false key: false scoringProfiles: defaultScoringProfile: null corsOptions: null ; // create/update an indexclient; // update an indexclient; // get an indexclient; // list the indexesclient; // get the stats for an indexclient; var data = 'text': 'Text to analyze' 'analyzer': 'standard' // shows how an analyzer breaks text into tokensclient
You can also add documents to the index, and search it:
var doc1 = "id": "document1" "description": "this is the description of my document" // add documents to an indexclient; // retrieve a document from an indexclient; // count the number of documents in the indexclient; // search the index (note that multiple arguments can be passed as an array)client; // suggest results based on partial inputclient;
You can get, create, update and delete data sources:
var options = name : "blob-datasource" type : "azureblob" credentials : connectionString : "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=yyy" container : name : "mycontainer" query : "" client; client; client; client;
You can also create, update, list, get, delete, run and reset indexers:
var schema = name: 'myindexer' description: 'Anything' //Optional. Anything you want, or null dataSourceName: 'myDSName' //Required. The name of an existing data source targetIndexName: 'myIndexName' //Required. The name of an existing index schedule: //Optional. All of the parameters below are required. interval: 'PT15M' //The pattern for this is: "P[nD][T[nH][nM]]". Examples: PT15M for every 15 minutes, PT2H for every 2 hours. startTime: '2016-06-01T00:00:00Z' //A UTC datetime when the indexer should start running. parameters: //Optional. All of the parameters below are optional. 'maxFailedItems' : 10 //Default is 0 'maxFailedItemsPerBatch' : 5 //Default is 0 'base64EncodeKeys': false //Default is false 'batchSize': 500 //The default depends on the data source type: it is 1000 for Azure SQL and DocumentDB, and 10 for Azure Blob Storage ; // create/update an indexerclient; // update an indexerclient; // get an indexerclient; // list the indexersclient; // get the status for an indexerclient; // delete an indexerclient; // run an indexerclient; // reset an indexerclient;
It is also possible to work with Synonym Maps:
var client = url: 'https://xxx.search.windows.net' key: 'your key goes here' // Mandatory in order to enable preview support of synonyms version: '2017-11-11' var schema = name: 'mysynonmap' // only the 'solr' format is supported for now format: 'solr' synonyms: 'a=>b\nb=>c' client; client; client; client client;
It is also possible to work with Skillsets for Cognitive Search, currently in preview version '2017-11-11-Preview':
var client = url: 'https://xxx.search.windows.net' key: 'your key goes here' // Mandatory in order to enable preview support of skillsets version: '2017-11-11-Preview' var schema = name: 'myskillset' // Required for using the POST method description: 'My skillset description' // Optional skills: // Required array of skills '@odata.type': '#Microsoft.Skills.Text.SentimentSkill' inputs: name: 'text' source: '/document/content' outputs: name: 'score' targetName: 'myScore' client; client; client; client client;
Accessing the Raw Response
The raw response body is always returned as the 3rd argument in the callback.
i.e.
// search the indexclient;
Using Promises
To use promises, invoke azureSearch
as a function instead of a constructor.
i.e.
var azureSearch = ;
If you need access to the raw response body, use callback syntax instead.
Contributing
Contributions are very welcome.
To download the dependencies:
> npm install
To build the minified JavaScript:
> npm run build
To run the tests:
> npm run test
Please note that you will have to update your clientConfiguration
and storageConnectionString
variables in order to run the tests.
License
MIT