Solr.spec.data.js
6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
define(function(require) {
'use strict';
var _ = require('underscore');
var Util = require('./Util');
var Facets = require('./Facets');
var Solr = require('./Solr');
function createSolrResponse(has) {
var solrData = {};
var facetCounts = Util.setField(solrData, 'facet_counts', {});
var facetIntervals = Util.setField(facetCounts, 'facet_intervals', {});
var facetRanges = Util.setField(facetCounts, 'facet_ranges', {});
var facetFields = Util.setField(facetCounts, 'facet_fields', {});
var facetQueries = Util.setField(facetCounts, 'facet_queries', {});
if (has.stats) {
solrData.stats = {};
Util.setField(solrData.stats, 'stats_fields', {});
}
return solrData;
}
function makeSolrResponseMixedCase(solrData) {
var facetCounts = Util.getField(solrData, 'facet_counts');
return {
facetCounts: facetCounts,
facetRanges: Util.getField(facetCounts, 'facet_ranges'),
facetFields: Util.getField(facetCounts, 'facet_fields'),
facetQueries: Util.getField(facetCounts, 'facet_queries'),
statsFields: Util.getField(solrData.stats, 'stats_fields'),
};
}
function createStaticSolrResponse(has, toMerge) {
var solrResponse = createSolrResponse({stats: true});
var solrData = makeSolrResponseMixedCase(solrResponse);
_.each(solrData, function(value, key) {
_.extend(value, toMerge[key]);
});
return solrResponse;
}
function expectItem(item, key, value, checked) {
expect(item.get('key')).toEqual(key);
expect(item.get('value')).toEqual(value);
expect(item.get('checked')).toEqual(checked);
}
var facetsBuilder = function facetsBuilder() {
return {
model: new Facets.Facet({
formName: 'model',
label: 'Model',
},
{
queryField: 'model_s',
facetType: 'field',
bins: {
misc: ['saturn', 'jeep'],
startsWithB: ['buick'],
},
}),
year: new Facets.Facet({
formName: 'year',
orderByDirection: 'desc',
label: 'Year',
},
{
queryField: 'year_dt',
comparator: 'date',
facetType: 'year-field',
facetStats: true,
formatter: function(item) {
var value = item.get('key');
if (value === 'before') {
return 'Older';
}
if (value === 'after') {
return 'Newer';
}
var year = new Date(value).getUTCFullYear();
return year + ' - ' + (year + 2);
},
}),
dateOfBirth: new Facets.Facet({
formName: 'dateOfBirth',
label: 'Birthday',
}, {
queryField: 'dateOfBirth_dt',
comparator: 'date',
facetType: 'year',
facetStats: true,
other: 'before',
start: 'NOW/YEAR-25YEAR',
}),
value: new Facets.Facet({
formName: 'value',
label: 'Value',
}, {
queryField: 'value_d',
comparator: 'number',
facetType: 'field',
facetStats: true,
formatter: function(item) {
var value = parseInt(item.get('key'));
return '$' + value + ' - $' + (value + 1000);
},
}),
};
};
var responses = {
sequential: [
createStaticSolrResponse({stats: true}, {
facetRanges: {
dateOfBirth: {
counts: [
'1974-01-01T00:00:00.000Z', 1,
'1972-01-01T00:00:00.000Z', 1,
'1970-01-01T00:00:00.000Z', 1,
],
before: 5,
},
},
facetFields: {
model: [
'ford', 23,
'chevy', 18,
'toyota', 5,
'saturn', 7, // keep here to test the bin/exclude feature
'jeep', 19, // keep here to test the bin/exclude feature
'buick', 0, // keep here to test the bin/exclude feature
'dodge', 0,
],
value: [
'23456', 1,
'5678', 2,
'1234', 3,
],
year: [
'2000-01-01T00:00:00.000Z', 1,
'2001-01-01T00:00:00.000Z', 4,
'2002-01-01T00:00:00.000Z', 0,
'2003-01-01T00:00:00.000Z', 3,
'2004-01-01T00:00:00.000Z', 0,
'2005-01-01T00:00:00.000Z', 0,
'2006-01-01T00:00:00.000Z', 0,
'2007-01-01T00:00:00.000Z', 0,
'2008-01-01T00:00:00.000Z', 7,
'2009-01-01T00:00:00.000Z', 0,
'2010-01-01T00:00:00.000Z', 1,
],
},
facetQueries: {
'model:misc': 26,
'model:startsWithB': 0,
},
statsFields: {
year: {min: '2000', max: '2010'},
dateOfBirth: {min: '2000', max: '2010'},
value: {min: '1234', max: '23456'},
},
}),
],
suggestions: [
createStaticSolrResponse({stats: true}, {
facetFields: {
'suggestions:model': [
'toyota', 5,
'ford', 23,
'chevy', 18,
'nissan', 0,
],
},
}),
],
};
var testSearchBuilder = function testSearchBuilder() {
var TestSearch = Solr.extend({}, {
selectUrl: '/solr/query/select',
orderingItems: [
{value: 'value_d asc', label: 'Value Ascending'},
{value: 'year_dt asc', label: 'Year Ascending'},
],
returnFields: [
'model_s',
'year_dt',
'value_d',
'dateOfBirth_dt',
],
facets: facetsBuilder(),
});
return TestSearch;
};
return {
testSearchBuilder: testSearchBuilder,
expectItem: expectItem,
facetsBuilder: facetsBuilder,
responses: responses,
};
});