|
40 | 40 |
|
41 | 41 | function filterFor2022(e) {
|
42 | 42 | // TODO: Task #2
|
43 |
| - //building a query expression using advanced query |
44 |
| - const queryExpression = buildQueryExpression().addStringField({ |
45 |
| - field: 'date', |
46 |
| - operator: 'isExactly', |
47 |
| - values: ['2022'] |
48 |
| - }).toQuerySyntax(); |
49 | 43 |
|
50 | 44 | //building a query expression using advanced query
|
51 |
| - const advancedQuery = "@year==2022"; |
52 |
| - |
53 |
| - //building the static filter value for the static filter |
54 |
| - const staticFilterValue = buildStaticFilterValue({ |
55 |
| - caption:'Content for 2022', //caption for the static filter value |
56 |
| - expression: queryExpression, |
57 |
| - }); |
| 45 | + const advancedQuery = "@year==2022"; |
58 | 46 |
|
59 |
| - const staticFilter = buildStaticFilter(headlessEngine, { |
60 |
| - id:"fileType", // id for static filter props, eg fileType |
61 |
| - values: [staticFilterValue] //needs a static filter value StaticFilterValue[] |
62 |
| - }) |
| 47 | + // loading all the actions needed to execute the search and log the events using the headless engine |
| 48 | + const advancedSearchQueryActionCreators = loadAdvancedSearchQueryActions(headlessEngine); |
| 49 | + const searchActionCreators = loadSearchActions(headlessEngine); |
| 50 | + const searchAnalyticsActionCreators = loadSearchAnalyticsActions(headlessEngine); |
| 51 | + |
| 52 | + // using the loadAdvancedSearchQueryActions send the advanced query `aq` and `groupBy` parameters to the headless engine |
| 53 | + const payloadDispatchableAction = advancedSearchQueryActionCreators.updateAdvancedSearchQueries({ |
| 54 | + "aq": advancedQuery, |
| 55 | + "groupBy": [ |
| 56 | + { |
| 57 | + "field": "@year", |
| 58 | + "sortCriteria": "occurrences", |
| 59 | + } |
| 60 | + ], |
| 61 | + }); |
63 | 62 |
|
| 63 | + // The static filter selection user clicks on the filter button to filter for 2022 content |
| 64 | + const dispatchableLogFilterSelectAction = searchAnalyticsActionCreators.logStaticFilterSelect({ |
| 65 | + staticFilterId:"year", |
| 66 | + staticFilterValue:{ |
| 67 | + caption: "Filter content for 2022", |
| 68 | + expression: advancedQuery, |
| 69 | + } |
| 70 | + }); |
64 | 71 |
|
65 |
| - // using the loadAdvancedSearchQueryActions to add the static filter to the search interface |
66 |
| - const advancedSearchQueryActionCreators = loadAdvancedSearchQueryActions(headlessEngine); |
67 |
| - const payloadDispatchableAction = advancedSearchQueryActionCreators.updateAdvancedSearchQueries(advancedQuery); |
68 |
| - headlessEngine.dispatch(payloadDispatchableAction); |
| 72 | + // Creating actions that executes a search query from the static filter. |
| 73 | + const dispatchableSearchAction = searchActionCreators.executeSearch(dispatchableLogFilterSelectAction); |
69 | 74 |
|
| 75 | + //The event to log when a search interface loads for the first time. |
| 76 | + const dispatchableLogInterfaceLoad = searchAnalyticsActionCreators.logInterfaceLoad(); |
| 77 | + //The event to log when the results sort criterion is changed |
| 78 | + const dispatchableLogSortChange = searchAnalyticsActionCreators.logResultsSort(); |
| 79 | + //The event to log when a user provides negative feedback for a given smart snippet answer |
| 80 | + const dispatchableLogDislikeSmartSnippet = searchAnalyticsActionCreators.logDislikeSmartSnippet(); |
| 81 | + //The event to log when a static filter value is selected. |
| 82 | + const dispatchableLogStaticFilterSelect = searchAnalyticsActionCreators.logStaticFilterSelect({ |
| 83 | + staticFilterId:"year", |
| 84 | + staticFilterValue:{ |
| 85 | + caption: "Filter content for 2022", |
| 86 | + expression: advancedQuery, |
| 87 | + } |
| 88 | + }); |
| 89 | + |
| 90 | + |
70 | 91 |
|
| 92 | + // dispatching the actions |
| 93 | + headlessEngine.dispatch(payloadDispatchableAction); |
| 94 | + headlessEngine.dispatch(dispatchableSearchAction); |
| 95 | + headlessEngine.dispatch(dispatchableLogSortChange); |
| 96 | + headlessEngine.dispatch(dispatchableLogDislikeSmartSnippet); |
| 97 | + headlessEngine.dispatch(dispatchableLogStaticFilterSelect); |
| 98 | + headlessEngine.dispatch(dispatchableLogInterfaceLoad); |
71 | 99 | }
|
72 | 100 |
|
73 | 101 | </script>
|
|
257 | 285 | right: 0;
|
258 | 286 | cursor: pointer;
|
259 | 287 | user-select: none;
|
| 288 | + |
260 | 289 | }
|
261 | 290 |
|
262 | 291 | .this-year-button:hover {
|
|
268 | 297 | color: white;
|
269 | 298 | }
|
270 | 299 | }
|
| 300 | + |
| 301 | + /* The styling I had to handle for the filter button to show on all screens */ |
| 302 | + @media only screen and (max-width:1014px) { |
| 303 | + .this-year-button { |
| 304 | + border: 1px solid #1372ec; |
| 305 | + border-radius: 10px; |
| 306 | + margin: 10px 10px 10px -100px; /* negative margin to move the button to the left */ |
| 307 | + text-align: center; |
| 308 | + padding: 10px; |
| 309 | + user-select: none; |
| 310 | + } |
| 311 | + |
| 312 | + .this-year-button:hover { |
| 313 | + background: #e1e9f3; |
| 314 | + } |
| 315 | + |
| 316 | + .this-year-button.active { |
| 317 | + background: #066bf0; |
| 318 | + color: white; |
| 319 | + } |
| 320 | + |
| 321 | + } |
| 322 | + |
271 | 323 | </style>
|
272 | 324 | </head>
|
273 | 325 |
|
274 | 326 | <body>
|
275 | 327 | <atomic-search-interface fields-to-include='["snrating","sncost","ytvideoduration","ytthumbnailurl"]'>
|
276 | 328 | <div class="header-bg"></div>
|
277 |
| - <atomic-search-box></atomic-search-box> |
| 329 | + |
| 330 | + <atomic-search-box ></atomic-search-box> |
278 | 331 | <div class="this-year-button">Filter for 2022 Content</div>
|
279 | 332 | <atomic-facet-manager>
|
280 | 333 | <atomic-category-facet field="geographicalhierarchy" label="World Atlas" with-search> </atomic-category-facet>
|
|
297 | 350 | <atomic-color-facet field="filetype" label="Files" number-of-values="6" sort-criteria="occurrences"></atomic-color-facet>
|
298 | 351 |
|
299 | 352 | <!-- building a facet for date so i can filter for 2022 content -->
|
300 |
| - <atomic-timeframe-facet label="Timeframe" with-date-picker="true" max="31/12/2022" min="01/01/2022" > |
301 |
| - </atomic-timeframe-facet> |
| 353 | + <atomic-facet field="year" label="Year" ></atomic-facet> |
| 354 | + |
| 355 | + <!-- <atomic-timeframe-facet label="Timeframe" with-date-picker="true" max="31/12/2022" min="01/01/2022" > |
| 356 | + </atomic-timeframe-facet> --> |
302 | 357 |
|
303 | 358 | </atomic-facet-manager>
|
304 | 359 | <atomic-breadbox></atomic-breadbox>
|
|
330 | 385 | /* Flexbox layout for the excerpt section to display the text and the image thumbnail */
|
331 | 386 | .excerpt-result-section {
|
332 | 387 | display: flex;
|
333 |
| - } |
| 388 | + } |
334 | 389 |
|
335 | 390 | .excerpt-text {
|
336 | 391 | flex: 8; /* Take 80% of the space */
|
337 | 392 | margin-right: 0.95rem;
|
| 393 | + |
338 | 394 | }
|
339 | 395 |
|
340 | 396 | .excerpt-image {
|
341 | 397 | flex: 2; /* Take the remaining 20% of the space */
|
342 | 398 | height: 100%;
|
343 | 399 | width: 100%;
|
344 |
| - object-fit: contain; |
| 400 | + object-fit: contain; |
345 | 401 | }
|
| 402 | + |
| 403 | + #featured-result::part(result-badge-element) { |
| 404 | + background-color:black; |
| 405 | + color: white; |
| 406 | + } |
| 407 | + |
| 408 | + #top-result::part(result-badge-element) { |
| 409 | + background-color:white; |
| 410 | + color: black; |
| 411 | + border: 1px solid black; |
| 412 | + } |
| 413 | + |
| 414 | + #date-result { |
| 415 | + color: rgb(5, 1, 1); |
| 416 | + font-weight: 500; |
| 417 | + } |
346 | 418 | </style>
|
347 | 419 |
|
348 | 420 | <!-- ** The Visual Result Section -- this gives the video icon ** -->
|
|
354 | 426 | <!-- ** The Badge Result Section ** -->
|
355 | 427 | <atomic-result-section-badges>
|
356 | 428 | <atomic-field-condition>
|
357 |
| - <atomic-result-badge if-defined="featured" label="featured"></atomic-result-badge> |
358 |
| - <atomic-result-badge if-defined="top result" label="top result"></atomic-result-badge> |
| 429 | + <atomic-result-badge if-defined="featured" label="featured" id="featured-result"></atomic-result-badge> |
| 430 | + <atomic-result-badge if-defined="top result" label="top result" id="top-result"></atomic-result-badge> |
359 | 431 | </atomic-field-condition>
|
360 | 432 | </atomic-result-section-badges>
|
361 | 433 |
|
362 | 434 | <!-- ** The Action Result Section for date ** -->
|
363 | 435 | <atomic-result-section-actions>
|
364 |
| - <atomic-field-condition if-defined="date"> |
365 |
| - <atomic-result-date></atomic-result-date> |
| 436 | + <atomic-field-condition if-defined="date" > |
| 437 | + <atomic-result-date id="date-result" ></atomic-result-date> |
366 | 438 | </atomic-field-condition>
|
367 | 439 | </atomic-result-section-actions>
|
368 | 440 |
|
|
0 commit comments