From 48ac39dbe16b103448b53feae50b69fb336e814e Mon Sep 17 00:00:00 2001 From: Jake Rosenberg Date: Wed, 31 Jan 2024 22:21:08 -0600 Subject: [PATCH] improve query string queries in Publications and fix infinite loading spinner (#1166) --- .../apps/api/publications/search_utils.py | 18 +++++++++++++----- .../services/publication-service.js | 14 +++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/designsafe/apps/api/publications/search_utils.py b/designsafe/apps/api/publications/search_utils.py index 6344bae1f0..89b14f3942 100644 --- a/designsafe/apps/api/publications/search_utils.py +++ b/designsafe/apps/api/publications/search_utils.py @@ -128,7 +128,7 @@ def author_query(author): {"path": "users", "ignore_unmapped": True, "query": { - "query_string": {"fields": ["users.first_name", "users.last_name", "users.username"], "query": author} + "query_string": {"fields": ["users.first_name", "users.last_name", "users.username"], "query": author, "type": "cross_fields"} } }}) @@ -140,7 +140,7 @@ def author_query(author): "authors.fname", "authors.lname", ] - aq2 = Q('multi_match', query=author, fields=other_author_fields, operator="AND", type="cross_fields") + aq2 = Q('query_string', type="cross_fields", query=author, fields=other_author_fields) return aq1 | aq2 @@ -196,11 +196,19 @@ def description_query(description): def search_string_query(search_string): if not search_string: return None - q1 = Q('query_string', query=f"\"{search_string}\"", fields=['project.value.description', + q1 = Q('query_string', query=search_string, default_operator="AND", type="cross_fields", fields=['project.value.description', 'project.value.keywords', 'project.value.title', 'projectId', 'project.value.projectType', - 'project.value.dataType']) + 'project.value.dataType', "project.value.pi", + "project.value.teamOrder.fname", + "project.value.teamOrder.lname", + "project.value.teamOrder.name", + "authors.fname", + "authors.lname", + "authors.email", + "authors.inst", + "users"]) q2 = Q({'term': {'projectId._exact': search_string}}) - return q1 | q2 | author_query(search_string) + return q1 | q2 diff --git a/designsafe/static/scripts/ng-designsafe/services/publication-service.js b/designsafe/static/scripts/ng-designsafe/services/publication-service.js index 343fcc94eb..9d8253d4e6 100644 --- a/designsafe/static/scripts/ng-designsafe/services/publication-service.js +++ b/designsafe/static/scripts/ng-designsafe/services/publication-service.js @@ -1,6 +1,6 @@ import _ from 'underscore'; -import { from } from 'rxjs'; -import { tap } from 'rxjs/operators'; +import { from, of } from 'rxjs'; +import { tap, catchError } from 'rxjs/operators'; import { takeLeadingSubscriber, takeLatestSubscriber } from './_rxjs-utils'; export class PublicationService { @@ -63,15 +63,23 @@ export class PublicationService { const operation = query_string ? 'search' : 'listing'; const listingObservable$ = from( this.$http.get(`/api/publications/${operation}/`, { params: { offset, limit, query_string } }) - ).pipe(tap(this.listingSuccessCallback)); + ).pipe(tap(this.listingSuccessCallback), catchError(() => this.listingErrorCallback())); return listingObservable$; } listingSuccessCallback(resp) { this.listing.publications = resp.data.listing; this.listing.loading = false; + this.listing.error = false; this.listing.reachedEnd = resp.data.listing.length < this.listing.params.limit; } + listingErrorCallback() { + this.listing.publications = [] + this.listing.loading = false; + this.listing.error = {message: "There was an error retrieving the requested publications."} + return of(null); + } + scrollPublications() { this.listing.loadingScroll = true; const observableMapping = () =>