Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

azure-search

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azure-search

A client for the Azure Search service

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 };

// create/update an index
client.createIndex(schema, function(err, schema){
	// an error, or the schema object back from the service
});

// get an index
client.getIndex('myindex', function(err, schema){
	// an error, or the schema object back from the service
});

// list the indexes
client.listIndexes(function(err, schemas){
	// an error, or the list of schemas from the service
});

// get the stats for an index
client.getIndexStats('myindex', function(err, stats){
	// an error, or the list of index stats from the service
});

// delete an index
client.deleteIndex('myindex', function(err){
	// optional error object
});

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 index
client.addDocuments('myindex', [doc1], function(err, results){
	// an error, or confirmation of each document being added
});

// retrieve a document from an index
client.lookup('myindex', 'document1', function(){
	// an error, or the document
});

// count the number of documents in the index
client.count('myindex', function(err, count){
	// an error, or the number of documents in the index	
});

// search the index
client.search('myindex', {search: "document", $top: 10}, function(err, results){
	// an error, or an array of matching results
});

// suggest results based on partial input
client.suggest('myindex', {search: "doc"}, function(err, results){
	// an error, or an array of matching results
});

License

MIT

FAQs

Package last updated on 25 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc