File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -247,6 +247,10 @@ export const index = function (items, fields) {
247
247
248
248
let i = 1 ;
249
249
250
+ fields . forEach ( ( field ) => {
251
+ facets [ 'data' ] [ field ] = Object . create ( null ) ;
252
+ } ) ;
253
+
250
254
items && items . map ( ( item ) => {
251
255
if ( ! item [ '_id' ] ) {
252
256
item [ '_id' ] = i ;
@@ -258,15 +262,10 @@ export const index = function (items, fields) {
258
262
259
263
items && items . map ( ( item ) => {
260
264
fields . forEach ( ( field ) => {
261
- //if (!item || !item[field]) {
262
265
if ( ! item ) {
263
266
return ;
264
267
}
265
268
266
- if ( ! facets [ 'data' ] [ field ] ) {
267
- facets [ 'data' ] [ field ] = Object . create ( null ) ;
268
- }
269
-
270
269
if ( Array . isArray ( item [ field ] ) ) {
271
270
item [ field ] . forEach ( ( v ) => {
272
271
if ( ! item [ field ] ) {
Original file line number Diff line number Diff line change @@ -65,6 +65,25 @@ describe('search', function () {
65
65
done ( ) ;
66
66
} ) ;
67
67
68
+ it ( 'searches no items with filters and query' , function test ( done ) {
69
+ const itemsjs = itemsJS ( [ ] , configuration ) ;
70
+
71
+ const result = itemsjs . search ( {
72
+ filters : {
73
+ tags : [ 'a' ] ,
74
+ category : [ 'drama' ] ,
75
+ } ,
76
+ query : 'comedy' ,
77
+ } ) ;
78
+
79
+ assert . equal ( result . data . items . length , 0 ) ;
80
+ assert . equal ( result . data . aggregations . in_cinema . buckets . length , 0 ) ;
81
+ assert . equal ( result . data . aggregations . category . buckets . length , 0 ) ;
82
+ assert . equal ( result . data . aggregations . year . buckets . length , 0 ) ;
83
+
84
+ done ( ) ;
85
+ } ) ;
86
+
68
87
it ( 'searches with two filters' , function test ( done ) {
69
88
const itemsjs = itemsJS ( items , configuration ) ;
70
89
@@ -244,7 +263,7 @@ describe('search', function () {
244
263
} catch ( err ) {
245
264
assert . equal (
246
265
err . message ,
247
- '"query" and "filter" options are not working once native search is disabled' ,
266
+ '"query" and "filter" options are not working once native search is disabled'
248
267
) ;
249
268
}
250
269
You can’t perform that action at this time.
0 commit comments