Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt user to try using "quotes" in search #2107

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions peachjam/js/components/FindDocuments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
>
<input
v-model="q"
type="text"
type="search"
class="form-control"
:placeholder="searchPlaceholder"
:aria-label="$t('Search documents')"
Expand All @@ -58,7 +58,7 @@
>
<button
type="submit"
class="btn btn-primary ms-1"
class="btn btn-primary ms-2"
:disabled="loading"
>
<span
Expand All @@ -79,6 +79,10 @@
<div class="my-2">
<HelpBtn page="search/" />
</div>
<div v-if="searchTip" class="alert alert-primary">
{{ searchTip.prompt }}
<a href="#" @click.stop.prevent="useSearchTip()">{{ searchTip.q }}</a>
</div>
</div>
<div
id="nav-advanced-search"
Expand Down Expand Up @@ -263,6 +267,7 @@ export default {
ordering: '-score',
q: '',
drawerOpen: false,
searchTip: null,
advancedSearchCriteria: [{
text: '',
fields: [],
Expand Down Expand Up @@ -552,6 +557,11 @@ export default {
this.search();
},

useSearchTip () {
this.q = this.searchTip.q;
this.search();
},

formatFacets () {
const generateOptions = (buckets, labels) => {
return buckets.map((bucket) => ({
Expand Down Expand Up @@ -672,13 +682,23 @@ export default {
},

async search (pushState = true) {
this.searchTip = null;

// if one of the search fields is true perform search
if (this.q || (Array.isArray(this.advancedSearchCriteria) && this.advancedSearchCriteria.some(f => f.text))) {
this.loadingCount = this.loadingCount + 1;

// scroll to put the search box at the top of the window
scrollToElement(this.$refs['search-box']);

// search tip
if (this.q && this.q.indexOf('"') === -1) {
this.searchTip = {
prompt: this.$t('Try using quotes to search for an exact phrase: '),
q: `"${this.q}"`
};
}

try {
const params = this.generateSearchParams();
const previousId = this.searchInfo.trace_id || '';
Expand Down Expand Up @@ -778,7 +798,7 @@ export default {
date_to: null,
date_from: null
};
},
}

}
};
Expand Down
Loading