Support for related search and spelling suggestions
This commit is contained in:
parent
f3909e5c0f
commit
8d3d53c261
3 changed files with 96 additions and 0 deletions
14
README.md
14
README.md
|
@ -108,6 +108,20 @@ Accepted filter values:
|
|||
* Style:\<Photo | Graphics\>
|
||||
* Face:\<Face | Portrait | Other\>
|
||||
|
||||
#### Related Search:
|
||||
```js
|
||||
Bing.relatedSearch('berlin', {market: 'en-US'}, function (err, res, body) {
|
||||
var suggestions = body.d.results.map(function(r){ return r.Title});
|
||||
console.log(suggestions.join('\n'));
|
||||
});
|
||||
```
|
||||
|
||||
#### Spelling Suggestions:
|
||||
```js
|
||||
Bing.spellingSuggestion('awsome spell', function (err, res, body) {
|
||||
console.log(body.d.results[0]); //awesome spell
|
||||
});
|
||||
```
|
||||
|
||||
#### Specify Market
|
||||
Getting spanish results:
|
||||
|
|
37
lib/bing.js
37
lib/bing.js
|
@ -258,6 +258,43 @@ Bing.prototype.images = function (query, options, callback) {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Performs a Bing search in the Related Search vertical.
|
||||
*
|
||||
* @param {String} query Query term to search for.
|
||||
*
|
||||
* @param {Object} options Options to command, allows overriding
|
||||
* of rootUri, accKey (Bing API key),
|
||||
* userAgent, reqTimeout, top, skip,
|
||||
*
|
||||
* @param {requestCallback} callback Callback called with (potentially
|
||||
* json-parsed) response.
|
||||
* @function
|
||||
*/
|
||||
Bing.prototype.relatedSearch = function (query, options, callback) {
|
||||
this.searchVertical(query, "RelatedSearch", options, callback);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Performs a Bing search in the Spelling Suggestions vertical.
|
||||
*
|
||||
* @param {String} query Query term to search for.
|
||||
*
|
||||
* @param {Object} options Options to command, allows overriding
|
||||
* of rootUri, accKey (Bing API key),
|
||||
* userAgent, reqTimeout, top, skip,
|
||||
*
|
||||
* @param {requestCallback} callback Callback called with (potentially
|
||||
* json-parsed) response.
|
||||
* @function
|
||||
*/
|
||||
Bing.prototype.spelling = function (query, options, callback) {
|
||||
this.searchVertical(query, "SpellingSuggestions", options, callback);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Capitalises the first word of the passed string
|
||||
*
|
||||
|
|
|
@ -165,3 +165,48 @@ describe("Bing Video", function () {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
describe("Bing Related Search", function () {
|
||||
|
||||
this.timeout(1000 * 10);
|
||||
|
||||
it('finds related search suggestions', function (done) {
|
||||
|
||||
Bing.relatedSearch('berlin',
|
||||
{ top: 5, market: 'en-US' },
|
||||
function (err, res, body) {
|
||||
|
||||
should.not.exist(err);
|
||||
should.exist(res);
|
||||
should.exist(body);
|
||||
|
||||
body.d.results.should.have.length(5);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("Bing Spelling Suggestion", function () {
|
||||
|
||||
this.timeout(1000 * 10);
|
||||
|
||||
it('finds proper spelling', function (done) {
|
||||
|
||||
Bing.spelling('awsome spell',
|
||||
function (err, res, body) {
|
||||
|
||||
should.not.exist(err);
|
||||
should.exist(res);
|
||||
should.exist(body);
|
||||
|
||||
// Find at leas one suggestion
|
||||
body.d.results.length.should.be.aboveOrEqual(1);
|
||||
body.d.results[0].Value.should.equal("awesome spell");
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue