@abcagency/hc-ui-components 1.3.52 → 1.3.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rollupPluginBabelHelpers.js +10 -1
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/dist/apis/hcApi.js +1 -1
- package/dist/apis/hcApi.js.map +1 -1
- package/dist/components/modules/buttons/button-group-apply.js.map +1 -1
- package/dist/contexts/mapListContext.js +1 -1
- package/dist/contexts/mapListContext.js.map +1 -1
- package/dist/util/filterUtil.js +53 -27
- package/dist/util/filterUtil.js.map +1 -1
- package/package.json +1 -1
- package/src/components/modules/buttons/button-group-apply.js +130 -130
- package/src/contexts/mapListContext.tsx +1 -1
- package/src/util/filterUtil.js +310 -280
package/src/util/filterUtil.js
CHANGED
|
@@ -1,280 +1,310 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
|
-
import { getDistinctItemsByProximity } from '~/util/mapUtil';
|
|
3
|
-
|
|
4
|
-
import Fuse from 'fuse.js';
|
|
5
|
-
|
|
6
|
-
export const getFilterOptions = (listings, filteredListings, field, excludeZeroCount = null) => {
|
|
7
|
-
const options = new Set();
|
|
8
|
-
listings.forEach(listing => {
|
|
9
|
-
if (listing.fields[field]) {
|
|
10
|
-
options.add(listing.fields[field]);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const optionCounts = {};
|
|
15
|
-
options.forEach(option => {
|
|
16
|
-
optionCounts[option] = 0;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
filteredListings.forEach(listing => {
|
|
20
|
-
const value = listing.fields[field];
|
|
21
|
-
if (value && optionCounts.hasOwnProperty(value)) {
|
|
22
|
-
optionCounts[value] += 1;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return Array.from(options)
|
|
27
|
-
.sort()
|
|
28
|
-
.map(option => ({
|
|
29
|
-
name: option,
|
|
30
|
-
count: optionCounts[option] || 0
|
|
31
|
-
}))
|
|
32
|
-
.filter(option => !(excludeZeroCount === true && option.count === 0));
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const getSpecialFeatureOptions = (listings, filteredListings, siteConfig, favorites) => {
|
|
36
|
-
const specialFeatures = siteConfig.specialFeatures;
|
|
37
|
-
const featureCounts = Object.keys(specialFeatures).sort().reduce((acc, key) => {
|
|
38
|
-
acc[specialFeatures[key]] = 0;
|
|
39
|
-
return acc;
|
|
40
|
-
}, {});
|
|
41
|
-
|
|
42
|
-
filteredListings.forEach(listing => {
|
|
43
|
-
Object.entries(specialFeatures).forEach(([featureKey, featureName]) => {
|
|
44
|
-
if (listing.fields[featureKey] == 1) {
|
|
45
|
-
featureCounts[featureName] += 1;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const specialFeatureOptions = Object.entries(featureCounts).map(([name, count]) => ({
|
|
51
|
-
name,
|
|
52
|
-
count
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
for (let option of specialFeatureOptions) {
|
|
56
|
-
if (option.name === 'Favorite') {
|
|
57
|
-
option.count = filteredListings.filter(x => favorites.includes(x.id)).length;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return specialFeatureOptions;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const getPointsOfInterestOptions = pointsOfInterestNames => {
|
|
65
|
-
return Object.entries(pointsOfInterestNames).sort().map(([key, name]) => ({
|
|
66
|
-
key,
|
|
67
|
-
name
|
|
68
|
-
}));
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const generateFilterOptions = (
|
|
72
|
-
filteredListings,
|
|
73
|
-
allListings,
|
|
74
|
-
siteConfig,
|
|
75
|
-
filterOptions,
|
|
76
|
-
parentField,
|
|
77
|
-
favorites,
|
|
78
|
-
selectedFilters
|
|
79
|
-
) => {
|
|
80
|
-
if (allListings.length > 0) {
|
|
81
|
-
const dynamicFilters = siteConfig.fieldFiltersShown.map(fieldName => {
|
|
82
|
-
if (fieldName === parentField && filterOptions?.filters) {
|
|
83
|
-
return filterOptions.filters.find(filter => filter.id === fieldName);
|
|
84
|
-
}
|
|
85
|
-
if
|
|
86
|
-
return {
|
|
87
|
-
id: fieldName,
|
|
88
|
-
title: siteConfig.fieldNames[fieldName],
|
|
89
|
-
items:
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
import { getDistinctItemsByProximity } from '~/util/mapUtil';
|
|
3
|
+
|
|
4
|
+
import Fuse from 'fuse.js';
|
|
5
|
+
|
|
6
|
+
export const getFilterOptions = (listings, filteredListings, field, excludeZeroCount = null) => {
|
|
7
|
+
const options = new Set();
|
|
8
|
+
listings.forEach(listing => {
|
|
9
|
+
if (listing.fields[field]) {
|
|
10
|
+
options.add(listing.fields[field]);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const optionCounts = {};
|
|
15
|
+
options.forEach(option => {
|
|
16
|
+
optionCounts[option] = 0;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
filteredListings.forEach(listing => {
|
|
20
|
+
const value = listing.fields[field];
|
|
21
|
+
if (value && optionCounts.hasOwnProperty(value)) {
|
|
22
|
+
optionCounts[value] += 1;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return Array.from(options)
|
|
27
|
+
.sort()
|
|
28
|
+
.map(option => ({
|
|
29
|
+
name: option,
|
|
30
|
+
count: optionCounts[option] || 0
|
|
31
|
+
}))
|
|
32
|
+
.filter(option => !(excludeZeroCount === true && option.count === 0));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const getSpecialFeatureOptions = (listings, filteredListings, siteConfig, favorites) => {
|
|
36
|
+
const specialFeatures = siteConfig.specialFeatures;
|
|
37
|
+
const featureCounts = Object.keys(specialFeatures).sort().reduce((acc, key) => {
|
|
38
|
+
acc[specialFeatures[key]] = 0;
|
|
39
|
+
return acc;
|
|
40
|
+
}, {});
|
|
41
|
+
|
|
42
|
+
filteredListings.forEach(listing => {
|
|
43
|
+
Object.entries(specialFeatures).forEach(([featureKey, featureName]) => {
|
|
44
|
+
if (listing.fields[featureKey] == 1) {
|
|
45
|
+
featureCounts[featureName] += 1;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const specialFeatureOptions = Object.entries(featureCounts).map(([name, count]) => ({
|
|
51
|
+
name,
|
|
52
|
+
count
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
for (let option of specialFeatureOptions) {
|
|
56
|
+
if (option.name === 'Favorite') {
|
|
57
|
+
option.count = filteredListings.filter(x => favorites.includes(x.id)).length;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return specialFeatureOptions;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const getPointsOfInterestOptions = pointsOfInterestNames => {
|
|
65
|
+
return Object.entries(pointsOfInterestNames).sort().map(([key, name]) => ({
|
|
66
|
+
key,
|
|
67
|
+
name
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const generateFilterOptions = (
|
|
72
|
+
filteredListings,
|
|
73
|
+
allListings,
|
|
74
|
+
siteConfig,
|
|
75
|
+
filterOptions,
|
|
76
|
+
parentField,
|
|
77
|
+
favorites,
|
|
78
|
+
selectedFilters
|
|
79
|
+
) => {
|
|
80
|
+
if (allListings.length > 0) {
|
|
81
|
+
const dynamicFilters = siteConfig.fieldFiltersShown.map(fieldName => {
|
|
82
|
+
if (fieldName === parentField && filterOptions?.filters) {
|
|
83
|
+
return filterOptions.filters.find(filter => filter.id === fieldName);
|
|
84
|
+
}
|
|
85
|
+
if(fieldName == 'categoryClass'){
|
|
86
|
+
return {
|
|
87
|
+
id: fieldName,
|
|
88
|
+
title: siteConfig.fieldNames[fieldName],
|
|
89
|
+
items: getFilterOptions(allListings, allListings, fieldName)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if(fieldName == 'category' && selectedFilters.categoryClass){
|
|
93
|
+
const categoryClassKeys = Object.keys(selectedFilters.categoryClass);
|
|
94
|
+
const filteredListings = allListings.filter(
|
|
95
|
+
x => categoryClassKeys.includes(x.fields?.categoryClass)
|
|
96
|
+
);
|
|
97
|
+
return {
|
|
98
|
+
id: fieldName,
|
|
99
|
+
title: siteConfig.fieldNames[fieldName],
|
|
100
|
+
items: getFilterOptions(allListings, filteredListings, fieldName, false)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (fieldName == "specialFeatures") {
|
|
104
|
+
return {
|
|
105
|
+
id: fieldName,
|
|
106
|
+
title: siteConfig.fieldNames[fieldName],
|
|
107
|
+
items: getSpecialFeatureOptions(allListings, filteredListings, siteConfig, favorites).sort()
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
id: fieldName,
|
|
112
|
+
title: siteConfig.fieldNames[fieldName],
|
|
113
|
+
items: getFilterOptions(allListings, filteredListings, fieldName)
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const locations =
|
|
118
|
+
siteConfig.locationFiltersShown.map((fieldName, index) => {
|
|
119
|
+
let locationFilteredListings = allListings;
|
|
120
|
+
locationFilteredListings = allListings.filter(listing => {
|
|
121
|
+
return Object.entries(selectedFilters).every(([key, value]) => {
|
|
122
|
+
if (siteConfig.locationFiltersShown.includes(key)) return true;
|
|
123
|
+
if (value && typeof value === 'object' && value[listing.fields[key]] === true) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
if (index === 0) {
|
|
130
|
+
return {
|
|
131
|
+
id: fieldName,
|
|
132
|
+
title: siteConfig.fieldNames[fieldName],
|
|
133
|
+
items: getFilterOptions(allListings, locationFilteredListings, fieldName, true)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (fieldName === 'entityName' && filterOptions?.locations) {
|
|
137
|
+
const cityIncluded = siteConfig.locationFiltersShown.includes('city');
|
|
138
|
+
const stateIncluded = siteConfig.locationFiltersShown.includes('state');
|
|
139
|
+
const cityStateIncluded = siteConfig.locationFiltersShown.includes('cityState');
|
|
140
|
+
const uniqueCities = cityIncluded ? [...new Set(filteredListings.map(listing => listing.fields.city))] : [];
|
|
141
|
+
const uniqueStates = stateIncluded ? [...new Set(filteredListings.map(listing => listing.fields.state))] : [];
|
|
142
|
+
const uniqueCityStates = cityStateIncluded ? [...new Set(filteredListings.map(listing => listing.fields.cityState))] : [];
|
|
143
|
+
const filteredByLocation = locationFilteredListings.filter(listing => {
|
|
144
|
+
const cityMatches = cityIncluded ? uniqueCities.includes(listing.fields.city) : true;
|
|
145
|
+
const stateMatches = stateIncluded ? uniqueStates.includes(listing.fields.state) : true;
|
|
146
|
+
const cityStateMatches = cityStateIncluded ? uniqueCityStates.includes(listing.fields.cityState) : true;
|
|
147
|
+
return cityMatches && stateMatches && cityStateMatches;
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
id: fieldName,
|
|
151
|
+
title: siteConfig.fieldNames[fieldName],
|
|
152
|
+
items: getFilterOptions(allListings, filteredByLocation, fieldName, true)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (fieldName === 'city') {
|
|
156
|
+
if (siteConfig.locationFiltersShown.includes('state') && selectedFilters.state) {
|
|
157
|
+
const selectedStates = Object.keys(selectedFilters.state).filter(
|
|
158
|
+
state => selectedFilters.state[state] === true
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const filteredByLocation = locationFilteredListings.filter(listing =>
|
|
162
|
+
selectedStates.includes(listing.fields.state)
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
id: fieldName,
|
|
167
|
+
title: siteConfig.fieldNames[fieldName],
|
|
168
|
+
items: getFilterOptions(allListings, filteredByLocation, fieldName, true)
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
id: fieldName,
|
|
175
|
+
title: siteConfig.fieldNames[fieldName],
|
|
176
|
+
items: getFilterOptions(allListings, filteredListings, fieldName, true)
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const pointsOfInterest = {
|
|
181
|
+
id: "pointsOfInterest",
|
|
182
|
+
title: siteConfig.pointsOfInterestConfig.title,
|
|
183
|
+
items: getPointsOfInterestOptions(
|
|
184
|
+
siteConfig.pointsOfInterestConfig.pointsOfInterestNames
|
|
185
|
+
)
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
filters: dynamicFilters,
|
|
190
|
+
locations: locations,
|
|
191
|
+
pointsOfInterest: pointsOfInterest
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return null;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const applyFilters = (
|
|
199
|
+
allListings,
|
|
200
|
+
selectedFilters,
|
|
201
|
+
query,
|
|
202
|
+
listingEntities,
|
|
203
|
+
favorites,
|
|
204
|
+
siteConfig
|
|
205
|
+
) => {
|
|
206
|
+
let results = allListings;
|
|
207
|
+
let invertedSpecialFeaturesMap;
|
|
208
|
+
if (siteConfig.specialFeatures) {
|
|
209
|
+
invertedSpecialFeaturesMap = Object.entries(siteConfig.specialFeatures).reduce((acc, [key, value]) => {
|
|
210
|
+
acc[value] = key;
|
|
211
|
+
return acc;
|
|
212
|
+
}, {});
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
const hasFavorite = !!selectedFilters.specialFeatures && !!selectedFilters.specialFeatures.Favorite;
|
|
216
|
+
|
|
217
|
+
if (hasFavorite && selectedFilters.specialFeatures.Favorite == true) {
|
|
218
|
+
results = results.filter(x => favorites.includes(x.id));
|
|
219
|
+
}
|
|
220
|
+
var favorite;
|
|
221
|
+
if (hasFavorite) {
|
|
222
|
+
favorite = selectedFilters.specialFeatures.Favorite;
|
|
223
|
+
delete selectedFilters.specialFeatures.Favorite;
|
|
224
|
+
}
|
|
225
|
+
for (const [field, filterItems] of Object.entries(selectedFilters)) {
|
|
226
|
+
const formattedField = field;
|
|
227
|
+
if (field === "pointsOfInterest") continue;
|
|
228
|
+
if (field === "specialFeatures" && invertedSpecialFeaturesMap && Object.keys(filterItems).length > 0) {
|
|
229
|
+
results = results.filter(listing => {
|
|
230
|
+
return Object.entries(filterItems).some(([filterName, filterValue]) => {
|
|
231
|
+
const listingFieldName = invertedSpecialFeaturesMap[filterName];
|
|
232
|
+
return filterValue && listing.fields[listingFieldName] == 1;
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
} else if (Object.keys(filterItems).length > 0) {
|
|
236
|
+
results = results.filter(listing =>
|
|
237
|
+
filterItems.hasOwnProperty(listing.fields[formattedField])
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (query) {
|
|
242
|
+
results = searchResults(results, query);
|
|
243
|
+
}
|
|
244
|
+
const distinctItems = getDistinctItemsByProximity(results, listingEntities);
|
|
245
|
+
if (hasFavorite) {
|
|
246
|
+
selectedFilters.specialFeatures.Favorite = favorite;
|
|
247
|
+
}
|
|
248
|
+
return { filteredListings: results, mapItems: distinctItems };
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
function searchResults(results, query) {
|
|
252
|
+
const fields = [
|
|
253
|
+
'id',
|
|
254
|
+
'fields.posted',
|
|
255
|
+
'fields.subtitle',
|
|
256
|
+
'fields.education',
|
|
257
|
+
'fields.position',
|
|
258
|
+
'fields.category',
|
|
259
|
+
'fields.categoryclass',
|
|
260
|
+
'fields.shift',
|
|
261
|
+
'fields.citystate',
|
|
262
|
+
'fields.city',
|
|
263
|
+
'fields.state',
|
|
264
|
+
'fields.schedule',
|
|
265
|
+
'fields.customflag1',
|
|
266
|
+
'fields.bonus',
|
|
267
|
+
'fields.remote',
|
|
268
|
+
'fields.useclientjoburl',
|
|
269
|
+
'fields.datecreated',
|
|
270
|
+
'fields.datelastedited'
|
|
271
|
+
];
|
|
272
|
+
|
|
273
|
+
const options = {
|
|
274
|
+
includeScore: true,
|
|
275
|
+
threshold: 0.3,
|
|
276
|
+
keys: fields
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const fuse = new Fuse(results, options);
|
|
280
|
+
const lowerCaseQuery = query.toLowerCase();
|
|
281
|
+
const queryTerms = lowerCaseQuery.split(' ');
|
|
282
|
+
|
|
283
|
+
const exactIdMatch = results.find(result => result.id.toString() === query);
|
|
284
|
+
if (exactIdMatch) {
|
|
285
|
+
return [exactIdMatch];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const fuseQuery = queryTerms.map(term => ({
|
|
289
|
+
$or: fields.map(field => ({ [field]: term }))
|
|
290
|
+
}));
|
|
291
|
+
|
|
292
|
+
const fuseResults = fuse.search({ $and: fuseQuery });
|
|
293
|
+
|
|
294
|
+
return fuseResults.map(result => result.item);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export const filterListingsByLocation = (
|
|
298
|
+
allListings,
|
|
299
|
+
selectedLocation,
|
|
300
|
+
listingEntities
|
|
301
|
+
) => {
|
|
302
|
+
let results = allListings;
|
|
303
|
+
if (selectedLocation !== null) {
|
|
304
|
+
results = results.filter(item =>
|
|
305
|
+
selectedLocation.items.hasOwnProperty(item.id)
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
const mapItems = getDistinctItemsByProximity(results, listingEntities);
|
|
309
|
+
return { filteredListings: results, mapItems: mapItems };
|
|
310
|
+
};
|