Skip to content

Commit

Permalink
improve query string queries in Publications and fix infinite loading…
Browse files Browse the repository at this point in the history
… spinner (#1166)
  • Loading branch information
jarosenb authored Feb 1, 2024
1 parent 7410625 commit 48ac39d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 13 additions & 5 deletions designsafe/apps/api/publications/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}

}})
Expand All @@ -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

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 = () =>
Expand Down

0 comments on commit 48ac39d

Please sign in to comment.