1 |
|
2 | var nock = require('nock'),
|
3 | solr = require('./../main'),
|
4 | vows = require('vows'),
|
5 | assert = require('assert');
|
6 | mocks = require('./mocks'),
|
7 | fs = require('fs');
|
8 |
|
9 |
|
10 | var config = JSON.parse(fs.readFileSync(__dirname + '/config.json'));
|
11 |
|
12 | if(config.mocked){
|
13 |
|
14 | mocks.group(nock);
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 | var suite = vows.describe('Solr Client API: group command');
|
20 |
|
21 | suite.addBatch({
|
22 | 'Grouping Result' : {
|
23 | 'with a field' : {
|
24 | topic : function(){
|
25 | var client = solr.createClient();
|
26 | var query = client.createQuery().q({ description : 'laptop'}).groupBy('title') ;
|
27 | client.search(query,this.callback);
|
28 | },
|
29 | 'should be possible' : function(err,res){
|
30 | assertCorrectResponse(err,res);
|
31 | }
|
32 | },
|
33 | 'with all availables options: field, limit,offset,sort,format,main,ngroups,truncate,cache' : {
|
34 | topic : function(){
|
35 | var client = solr.createClient();
|
36 | var query = client.createQuery().q({description : 'laptop'}).group({
|
37 | field : 'title',
|
38 | limit : 20,
|
39 | offset : 0,
|
40 | sort : 'score asc',
|
41 | format : 'grouped',
|
42 | main : false,
|
43 | ngroups : true,
|
44 | truncate : false,
|
45 | cache : 0
|
46 | });
|
47 | client.search(query,this.callback);
|
48 | },
|
49 | 'should be possible' :function(err,res) {
|
50 | assertCorrectResponse(err,res)
|
51 | }
|
52 | }
|
53 | }
|
54 | }).export(module);
|
55 |
|
56 |
|
57 |
|
58 | function assertCorrectResponse(err,data){
|
59 | assert.isNull(err);
|
60 | assert.isObject(data);
|
61 | assert.equal(data.responseHeader.status,0);
|
62 | }
|