Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

mock-search.js 1.7 KB

You have to be logged in to leave a comment. Sign In
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
  1. var _ = require('lodash');
  2. var uuid = require('uuid');
  3. var loremIpsum = require('lorem-ipsum');
  4. var Refiners = ['region', 'type'];
  5. function refineFormatter(refiners) {
  6. return _.zipObject(
  7. refiners.map(function (r) { return 'By ' + _.capitalize(r); }),
  8. refiners);
  9. }
  10. function search(query) {
  11. console.log('mock-search.query:', query);
  12. // mock items facets
  13. var region = (_.find(query.filters, ['key', 'region']) || { value: undefined }).value;
  14. var type = (_.find(query.filters, ['key', 'type']) || { value: undefined }).value;
  15. var i = (query.pageNumber - 1) * 3;
  16. var result = {
  17. facets: [
  18. {
  19. key: 'region',
  20. options: [
  21. { value: 'US', count: 10 },
  22. { value: 'Canada', count: 10 }
  23. ]
  24. },
  25. {
  26. key: 'type',
  27. options: [
  28. { value: 'Unknown', count: 6 },
  29. { value: 'A', count: 2 },
  30. { value: 'B', count: 3 }
  31. ]
  32. }
  33. ],
  34. results: [
  35. { key: uuid.v4(), title: 'Test ' + query.searchText + ' #' + (i + 1), description: loremIpsum(), region: region, type: type },
  36. { key: uuid.v4(), title: 'Test ' + query.searchText + ' #' + (i + 2), description: loremIpsum(), region: region, type: type },
  37. { key: uuid.v4(), title: 'Test ' + query.searchText + ' #' + (i + 3), description: loremIpsum(), region: region, type: type }
  38. ]
  39. };
  40. return Promise.resolve(result);
  41. }
  42. module.exports = {
  43. search: search,
  44. refiners: Refiners,
  45. refineFormatter: refineFormatter
  46. };
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...