Skip to content

Commit

Permalink
feat: Add type filter to site search (#699)
Browse files Browse the repository at this point in the history
* feat: Add type filter to site search

* fix: refactor and fix json parsing

* fix: section handle label for libguides

* fix: Add mapping for content types to section handle

* fix: Order the filters alphabetically
  • Loading branch information
pghorpade authored Apr 25, 2023
1 parent cb989ed commit d364c2c
Show file tree
Hide file tree
Showing 10 changed files with 448 additions and 201 deletions.
63 changes: 36 additions & 27 deletions pages/about/news/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<main id="main" class="page page-news">
<main
id="main"
class="page page-news"
>
<masthead-secondary
v-if="page.title"
:title="page.title"
Expand All @@ -22,10 +25,10 @@
<section-wrapper
v-show="
page &&
page.featuredNews &&
page.featuredNews.length &&
hits.length == 0 &&
!noResultsFound
page.featuredNews &&
page.featuredNews.length &&
hits.length == 0 &&
!noResultsFound
"
class="section-no-top-margin"
>
Expand All @@ -45,10 +48,10 @@
<divider-general
v-if="
page &&
page.featuredNews &&
page.featuredNews.length &&
hits.length == 0 &&
!noResultsFound
page.featuredNews &&
page.featuredNews.length &&
hits.length == 0 &&
!noResultsFound
"
/>

Expand All @@ -62,10 +65,10 @@
<section-wrapper
v-show="
page &&
page.featuredNews &&
page.featuredNews.length &&
hits.length == 0 &&
!noResultsFound
page.featuredNews &&
page.featuredNews.length &&
hits.length == 0 &&
!noResultsFound
"
theme="divider"
>
Expand All @@ -84,45 +87,49 @@
v-show="hits && hits.length > 0"
class="section-no-top-margin"
>
<h2 v-if="$route.query.q" class="about-results">
<h2
v-if="$route.query.q"
class="about-results"
>
Displaying {{ hits.length }} results for
<strong
><em>β€œ{{ $route.query.q }}”</em></strong
>
<strong><em>β€œ{{ $route.query.q }}”</em></strong>
</h2>
<h2 v-else class="about-results">
<h2
v-else
class="about-results"
>
Displaying {{ hits.length }} results
</h2>
<section-staff-article-list :items="parseHitsResults" />
</section-wrapper>

<!-- NO RESULTS -->
<section-wrapper v-show="noResultsFound" class="section-no-top-margin">
<section-wrapper
v-show="noResultsFound"
class="section-no-top-margin"
>
<div class="error-text">
<rich-text>
<h2>Search for β€œ{{ $route.query.q }}” not found.</h2>
<p>
We can’t find the term you are looking for on this page,
but we're here to help. <br />
but we're here to help. <br>
Try searching the whole site from
<a href="https://library.ucla.edu">UCLA Library Home</a
>, or try one of the these regularly visited links:
<a href="https://library.ucla.edu">UCLA Library Home</a>, or try one of the these regularly visited links:
</p>
<ul>
<li>
<a
href="https://www.library.ucla.edu/research-teaching-support/research-help"
>Research Help</a
>
>Research Help</a>
</li>
<li>
<a href="/help/services-resources/ask-us">Ask Us</a>
</li>
<li>
<a
href="https://www.library.ucla.edu/use/access-privileges/disability-resources"
>Accessibility Resources</a
>
>Accessibility Resources</a>
</li>
</ul>
</rich-text>
Expand Down Expand Up @@ -212,7 +219,9 @@ export default {
query_text,
config.newsIndex.searchFields,
"sectionHandle:article",
JSON.parse(this.$route.query.filters) || {},
(this.$route.query.filters &&
JSON.parse(this.$route.query.filters)) ||
{},
config.newsIndex.sortField,
config.newsIndex.orderBy,
config.newsIndex.resultFields,
Expand Down
107 changes: 54 additions & 53 deletions pages/about/programs/index.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<template>
<main id="main" class="page page-programs">
<nav-breadcrumb to="/about" :title="page.title" parent-title="About" />
<main
id="main"
class="page page-programs"
>
<nav-breadcrumb
to="/about"
:title="page.title"
parent-title="About"
/>

<masthead-secondary :title="page.title" :text="page.text" />
<masthead-secondary
:title="page.title"
:text="page.text"
/>

<search-generic
search-type="about"
Expand All @@ -15,23 +25,26 @@
<section-wrapper
v-show="
page &&
page.featuredPrograms &&
page.featuredPrograms.length &&
hits.length == 0 &&
!noResultsFound
page.featuredPrograms &&
page.featuredPrograms.length &&
hits.length == 0 &&
!noResultsFound
"
theme="divider"
>
<divider-way-finder class="search-margin" color="about" />
<divider-way-finder
class="search-margin"
color="about"
/>
</section-wrapper>

<section-wrapper
v-show="
page &&
page.featuredPrograms &&
page.featuredPrograms.length &&
hits.length == 0 &&
!noResultsFound
page.featuredPrograms &&
page.featuredPrograms.length &&
hits.length == 0 &&
!noResultsFound
"
class="section-no-top-margin"
>
Expand Down Expand Up @@ -66,9 +79,9 @@
<section-wrapper
v-show="
parsedProgramsList &&
parsedProgramsList.length > 0 &&
hits.length == 0 &&
!noResultsFound
parsedProgramsList.length > 0 &&
hits.length == 0 &&
!noResultsFound
"
section-title="All Programs & Initiatives"
>
Expand All @@ -80,45 +93,49 @@
v-show="hits && hits.length > 0"
class="section-no-top-margin"
>
<h2 v-if="$route.query.q" class="about-results">
<h2
v-if="$route.query.q"
class="about-results"
>
Displaying {{ hits.length }} results for
<strong
><em>β€œ{{ $route.query.q }}</em></strong
>”
<strong><em>β€œ{{ $route.query.q }}</em></strong>”
</h2>
<h2 v-else class="about-results">
<h2
v-else
class="about-results"
>
Displaying {{ hits.length }} results
</h2>
<section-staff-article-list :items="parseHitsResults" />
</section-wrapper>

<!-- NO RESULTS -->
<section-wrapper v-show="noResultsFound" class="section-no-top-margin">
<section-wrapper
v-show="noResultsFound"
class="section-no-top-margin"
>
<div class="error-text">
<rich-text>
<h2>Search for β€œ{{ $route.query.q }}” not found.</h2>
<p>
We can’t find the term you are looking for on this page,
but we're here to help. <br />
but we're here to help. <br>
Try searching the whole site from
<a href="https://library.ucla.edu">UCLA Library Home</a
>, or try one of the these regularly visited links:
<a href="https://library.ucla.edu">UCLA Library Home</a>, or try one of the these regularly visited links:
</p>
<ul>
<li>
<a
href="https://www.library.ucla.edu/research-teaching-support/research-help"
>Research Help</a
>
>Research Help</a>
</li>
<li>
<a href="/help/services-resources/ask-us">Ask Us</a>
</li>
<li>
<a
href="https://www.library.ucla.edu/use/access-privileges/disability-resources"
>Accessibility Resources</a
>
>Accessibility Resources</a>
</li>
</ul>
</rich-text>
Expand All @@ -142,6 +159,7 @@
// UTILITIES
import getListingFilters from "~/utils/getListingFilters"
import config from "~/utils/searchConfig"
import queryFilterHasValues from "~/utils/queryFilterHasValues"
// HELPERS
import _get from "lodash/get"
Expand Down Expand Up @@ -182,7 +200,11 @@ export default {
this.hits = []
if (
(this.$route.query.q && this.$route.query.q !== "") ||
this.$route.query.filters
(this.$route.query.filters &&
queryFilterHasValues(
this.$route.query.filters,
config.programsList.filters
))
) {
if (!this.page.title) {
const data = await this.$graphql.default.request(PROGRAMS_LIST)
Expand All @@ -196,7 +218,9 @@ export default {
query_text,
config.programsList.searchFields,
"sectionHandle:program",
JSON.parse(this.$route.query.filters) || {},
(this.$route.query.filters &&
JSON.parse(this.$route.query.filters)) ||
{},
config.programsList.sortField,
config.programsList.orderBy,
config.programsList.resultFields,
Expand Down Expand Up @@ -309,29 +333,6 @@ export default {
this.setFilters()
},
methods: {
queryFilterHasValues() {
if (!this.$route.query.filters) return false
let routeQueryFilters = JSON.parse(this.$route.query.filters)
// //console.log(
// "is route query exixts:" + JSON.stringify(routeQueryFilters)
// )
let configFilters = config.programsList.filters
for (const filter of configFilters) {
if (
Array.isArray(routeQueryFilters[filter.esFieldName]) &&
routeQueryFilters[filter.esFieldName].length > 0
) {
return true
} else if (
routeQueryFilters[filter.esFieldName] &&
!Array.isArray(routeQueryFilters[filter.esFieldName]) &&
routeQueryFilters[filter.esFieldName] != ""
) {
return true
}
}
return false
},
async setFilters() {
const searchAggsResponse = await this.$dataApi.getAggregations(
config.programsList.filters,
Expand Down
4 changes: 3 additions & 1 deletion pages/about/staff/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ export default {
query_text,
config.staff.searchFields,
"sectionHandle:staffMember",
JSON.parse(this.$route.query.filters) || {},
(this.$route.query.filters &&
JSON.parse(this.$route.query.filters)) ||
{},
config.staff.sortField,
config.staff.orderBy,
config.staff.resultFields,
Expand Down
Loading

14 comments on commit d364c2c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644834da6f71201d0b389b9b--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://6448754be50aff54fc438bbb--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://6448dd9bb8353538b7245154--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://6449862932c5c05c0b4829d2--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644a2f213c76cc6071695e3d--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644ad7a4a20da100a0e24334--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644b80caf3b5c07235994624--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644c2971c9c13b0d6327a928--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644cd24263f0756b6c818ea1--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644d7aaeac9d3653ea44ac8b--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644e23a4cbc6c42a101d0d47--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644ecc4e8276600dfa3360b7--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://644f75218276606952335f03--uclalibrary.netlify.app

Please sign in to comment.