Skip to content

Commit 3e9a4fe

Browse files
authored
Merge pull request #486 from AtlasOfLivingAustralia/472-473-species-list-queries
#472 #473 update species list queries
2 parents 0ca8cc7 + 6b1cc92 commit 3e9a4fe

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

grails-app/assets/javascripts/spApp/directive/listsList.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,17 @@
8383
//If the list is authoritative, Biocache builds index against species_list_uid (over night)
8484
//We should use q=species_list_uid:drxxxx
8585
if (found.isAuthoritative) {
86-
8786
scope._custom()({
8887
q: ["species_list_uid:" + found.dataResourceUid],
8988
name: found.listName,
9089
species_list: found.dataResourceUid
9190
})
9291
} else {
93-
//q=qid:xxxxxxxxxx
94-
ListsService.getItemsQ(found.dataResourceUid).then(function (data) {
95-
//example: (lsid:xxxx OR lsid:xxxx)
96-
var items = data.split(" OR ");
97-
var query = data;
98-
var limit = 200;
99-
if (items.length > limit ) {
100-
alert("Note: only the first 200 names will be used when when adding species to the map (for user-uploaded checklists)");
101-
query = items.slice(0,limit).join(" OR ") +")";
102-
}
103-
scope._custom()({
104-
q: [query],
105-
name: found.listName,
106-
species_list: found.dataResourceUid
107-
})
92+
scope._custom()({
93+
// list not indexed, can be very slow (minutes)
94+
q: ["species_list:" + found.dataResourceUid],
95+
name: found.listName,
96+
species_list: found.dataResourceUid
10897
})
10998
}
11099

grails-app/assets/javascripts/spApp/service/facetAutoCompleteService.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@
170170
var data = ListsService.getItemsQCached(species_list);
171171
if (data === undefined) {
172172
return ListsService.getItemsQ(species_list).then(function () {
173-
// species list info is now cached
174-
return scope.getFacets(dynamic, groups, species_list)
173+
// species list info is now cached, retry this function
174+
return scope.getGroupedFacets(dynamic, groups, species_list)
175175
})
176176
} else {
177177
if (data.length > 0 && data[0].kvpValues && data[0].kvpValues.length > 0) {
@@ -256,8 +256,8 @@
256256
var data = ListsService.getItemsQCached(species_list);
257257
if (data === undefined) {
258258
return ListsService.getItemsQ(species_list).then(function () {
259-
// species list info is now cached
260-
return scope.getFacets(dynamic, groups, species_list)
259+
// species list info is now cached, retry this function
260+
scope.getAllFacets(dynamic, list, species_list)
261261
})
262262
} else {
263263
if (data.length > 0 && data[0].kvpValues && data[0].kvpValues.length > 0) {
@@ -347,4 +347,4 @@
347347

348348
return scope;
349349
}])
350-
}(angular));
350+
}(angular));

grails-app/assets/javascripts/spApp/service/listsService.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
list: function (q, max, offset, sort, order, user) {
2828
var params = '';
2929
if (q) params += "/" + encodeURIComponent(q);
30-
//TODO: investigate paging
30+
//TODO: investigate paging, or keep increasing max
3131
// if(q) params += '&q=' + encodeURIComponent(q);
3232
// if(max) params += '&max=' + max;
3333
// if(offset) params += '&offset=' + offset;
3434
// if(sort) params += '&sort=' + sort;
3535
// if(order) params += '&order=' + order;
3636
// if(user) params += '&user=' + user;
37-
params += "?" + "&max=2000";
37+
params += "?" + "&max=20000";
3838
if ($SH.userId) {
3939
params += "&user=" + $SH.userId
4040
}
@@ -74,16 +74,13 @@
7474
return cache.get(listId);
7575
},
7676
getItemsQ: function (listId) {
77-
// TODO: use 'species_list:' after biocache-service is redeployed
78-
//return $q.when('species_list:' + listId);
79-
8077
if (scope.getItemsQCached(listId)) {
81-
return $q.when(scope.listToFq(scope.getItemsQCached(listId)))
78+
return scope.getListFq(listId);
8279
} else {
8380
return scope.items(listId, {includeKVP: true}).then(function (data) {
8481
cache.put(listId, data);
8582

86-
return $q.when(scope.listToFq(data));
83+
return scope.getListFq(listId);
8784
});
8885
}
8986
},
@@ -110,10 +107,25 @@
110107
}
111108
}
112109
if (terms.length > 0) {
110+
terms[0] = "(" + terms[0];
113111
terms[terms.length - 1] += ")";
114112
}
115113
return terms.join(" OR ");
116-
}
114+
},
115+
getListFq: function (listId) {
116+
return $http.get($SH.baseUrl + "/portal/speciesListInfo?listId=" + listId, _httpDescription('getListInfo')).then(function (response) {
117+
if (response.data.isAuthoritative) {
118+
// list is indexed
119+
return $q.when('species_list_uid:' + listId)
120+
} else {
121+
// list is not indexed, can be very slow (minutes)
122+
return $q.when('species_list:' + listId)
123+
}
124+
}).catch(function () {
125+
// for a user's private lists, can be very slow (minutes)
126+
return $q.when('species_list:' + listId);
127+
});
128+
},
117129
};
118130

119131
return scope;

grails-app/controllers/au/org/ala/spatial/portal/PortalController.groovy

+18
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,24 @@ class PortalController {
440440
}
441441
}
442442

443+
def speciesListInfo() {
444+
def url = grailsApplication.config.lists.url
445+
446+
def r = webService.get("${url}/ws/speciesList/${params.listId}".toString(), null, org.apache.http.entity.ContentType.APPLICATION_JSON, false, true, [:])
447+
448+
if (r == null) {
449+
def status = response.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR)
450+
r = [status: status, error: 'Unknown error when fetching list']
451+
}
452+
453+
def status = r.statusCode
454+
if (r.statusCode < 200 || r.statusCode > 300) {
455+
r = [error: r.resp ]
456+
}
457+
458+
render status: status, r.resp as JSON
459+
}
460+
443461
def q() {
444462
def json = (Map) request.JSON
445463

0 commit comments

Comments
 (0)