Skip to content

Commit

Permalink
Merge pull request #23 from dgkanatsios/master
Browse files Browse the repository at this point in the history
various updates
  • Loading branch information
richorama authored May 2, 2017
2 parents 3f1c266 + 541f645 commit 1a321ea
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 57 deletions.
13 changes: 9 additions & 4 deletions azure-search.min.js

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function (options) {
if (!options) throw new Error('please supply the options object')
if (!options.url) throw new Error('please supply the url of the search service')
if (!options.key) throw new Error('please supply the key of the search service')
if (!options.version) options.version = '2015-02-28-Preview'
if (!options.version) options.version = '2016-09-01'

var get = function (path, overrides, callback) {
execute(path, 'GET', null, overrides, callback)
Expand All @@ -21,7 +21,7 @@ module.exports = function (options) {
}

var execute = function (path, method, body, overrides, cb) {
path.push({'api-version': options.version})
path.push({ 'api-version': options.version })

var payload = ''
if (body) {
Expand Down Expand Up @@ -86,14 +86,12 @@ module.exports = function (options) {
} else {
cb(null, result, res)
}
return
})

res.on('error', function (err) {
if (cb) {
cb(err, null, res)
cb = undefined
return
}
})
})
Expand All @@ -106,14 +104,12 @@ module.exports = function (options) {
if (cb) {
cb(err, null, req)
cb = undefined
return
}
})
} catch (err) {
if (cb) {
cb(err)
cb = undefined
return
}
}
}
Expand Down Expand Up @@ -142,6 +138,14 @@ module.exports = function (options) {
cb(null, data, data)
})
},
testAnalyzer: function (indexName, data, cb) {
if (!indexName) throw new Error('indexName is not defined')
post(['indexes', indexName, 'analyze'], data, function (err, data) {
if (err) return cb(err, null, data)
if (data && data.error) return cb(data.error, null, data)
cb(null, data.tokens, data)
})
},
getIndexStats: function (indexName, cb) {
if (!indexName) throw new Error('indexName is not defined')
get(['indexes', indexName, 'stats'], null, function (err, data) {
Expand Down Expand Up @@ -254,7 +258,7 @@ module.exports = function (options) {
addDocuments: function (indexName, documents, cb) {
if (!indexName) throw new Error('indexName is not defined')
if (!documents) throw new Error('documents is not defined')
post(['indexes', indexName, 'docs', 'index'], {value: documents}, function (err, data) {
post(['indexes', indexName, 'docs', 'index'], { value: documents }, function (err, data) {
if (err) return cb(err, null, data)
if (data && data.error) return cb(data.error, null, data)
cb(null, data.value, data)
Expand All @@ -268,7 +272,7 @@ module.exports = function (options) {
documents[i]['@search.action'] = 'merge'
}

post(['indexes', indexName, 'docs', 'index'], {value: documents}, function (err, data) {
post(['indexes', indexName, 'docs', 'index'], { value: documents }, function (err, data) {
if (err) return cb(err, null, data)
if (data && data.error) return cb(data.error, null, data)
cb(null, data.value, data)
Expand All @@ -282,7 +286,7 @@ module.exports = function (options) {
documents[i]['@search.action'] = 'upload'
}

post(['indexes', indexName, 'docs', 'index'], {value: documents}, function (err, data) {
post(['indexes', indexName, 'docs', 'index'], { value: documents }, function (err, data) {
if (err) return cb(err, null, data)
if (data && data.error) return cb(data.error, null, data)
cb(null, data.value, data)
Expand All @@ -296,7 +300,7 @@ module.exports = function (options) {
keys[i]['@search.action'] = 'delete'
}

post(['indexes', indexName, 'docs', 'index'], {value: keys}, function (err, data) {
post(['indexes', indexName, 'docs', 'index'], { value: keys }, function (err, data) {
if (err) return cb(err, null, data)
if (data && data.error) return cb(data.error, null, data)
cb(null, data.value, data)
Expand Down Expand Up @@ -327,7 +331,7 @@ module.exports = function (options) {
count: function (indexName, cb) {
if (!indexName) throw new Error('indexName is not defined')

get(['indexes', indexName, 'docs', '$count'], {'Accept': 'text/plain'}, function (err, data) {
get(['indexes', indexName, 'docs', '$count'], { 'Accept': 'text/plain' }, function (err, data) {
if (err) return cb(err, null, data)
cb(null, parseInt(data.trim()), data)
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-search",
"version": "0.0.12",
"version": "0.0.13",
"description": "A client for the Azure Search service",
"main": "index.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ client.getIndexStats('myindex', function(err, stats){
// optional error, or the list of index stats from the service
});

var data = {
'text': 'Text to analyze',
'analyzer': 'standard'
}
// shows how an analyzer breaks text into tokens
client.testAnalyzer('myindex', data, function (err, tokens) {
//optional error, or array of tokens
}

// delete an index
client.deleteIndex('myindex', function(err){
// optional error
Expand Down
Loading

0 comments on commit 1a321ea

Please sign in to comment.