Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[#8] Add spec for _mlt query
  • Loading branch information
mikepb committed Oct 19, 2013
1 parent 4eee5a6 commit daf3786
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
5 changes: 4 additions & 1 deletion sage.js
Expand Up @@ -927,7 +927,10 @@ Apache License
* @return this
*/
mlt: function(id /* [query], [headers], [callback] */) {
return this._(arguments, 1)('GET', id + '/_mlt');
var request = this._(arguments, 1)
, fields = request.q && request.q.mlt_fields;
if (isArray(fields)) request.q.mlt_fields = fields.join(',');
return request('GET', id + '/_mlt');
}

};
Expand Down
2 changes: 1 addition & 1 deletion sage.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions test/shared.js
Expand Up @@ -5,17 +5,19 @@ if (typeof require != 'undefined') {

(function(){

var lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';

this.sageFactory = function() {
this.client = sage('http://127.0.0.1:9200');
this.index = this.client.index('sage-test');
this.type = this.index.type('type1');
};

this.docFactory = function() {
this.doc = { _id: '0', hello: 'World' };
this.doc = { _id: '0', hello: 'World', text: lorem };
this.docs = [];
for (var i = 1; i < 10; i++) {
this.docs.push({ _id: '' + i, hello: 'World' + i });
this.docs.push({ _id: '' + i, hello: 'World' + i, text: lorem });
}
};

Expand Down
20 changes: 20 additions & 0 deletions test/type-test.js
Expand Up @@ -49,6 +49,7 @@ describe('Type', function(){
describe('getting documents', function(){
before(createIndex);
before(putDocument);
before(bulkDocuments);
after(destroyIndex);

describe('#get', function(){
Expand All @@ -67,6 +68,25 @@ describe('Type', function(){
});
});

describe('#mlt', function(){
it('should wait for index to build', function(done){
this.slow(3000); setTimeout(done, 1000);
});
it('should accept more-like-this query', function(done){
var doc = this.doc;
this.type.mlt(doc._id, {
mlt_fields: ['text'],
min_doc_freq: 1
}, function(err, body, status, headers, res){
if (!err) {
expect(body).to.have.length(9);
shouldHave2xxStatus(status);
}
done(err);
});
});
});

});

describe('updating documents', function(){
Expand Down

0 comments on commit daf3786

Please sign in to comment.