Skip to content

Commit

Permalink
Always order collection suggestions alphabetically (#38)
Browse files Browse the repository at this point in the history
Instead of by count, because the count is always 1 or 2 anyway (depending on whether the backend is listed with 1 or 2 versions). And then the count doesn't need to be displayed anymore either.

The new ordering revealed that there was a collection with id=null and title=null, which I traced back to the old Mundialis backend. It returned an error instead of a valid collections object in its `GET /collections` response. So I introduced a safety check in the pipelines that populate the `collections` and `processes` MongoDB collections.
  • Loading branch information
christophfriedrich committed Dec 20, 2019
1 parent 4448eab commit 7c85298
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ server.get('/api/backends/:backend/*', function(req, res, next) {

// list collections
server.get('/api/collections', function(req, res, next) {
aggregate(dbqueries.GET_DISTINCT_COLLECTIONS_WITH_COUNT_PIPELINE, 'collections')
aggregate(dbqueries.GET_DISTINCT_COLLECTIONS_PIPELINE, 'collections')
.then(prepare)
.then(data => { res.send(data); next(); })
.catch(err => next(err));
Expand Down
1 change: 0 additions & 1 deletion src/components/DiscoverSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
:multiple="true" :hideSelected="true" :closeOnSelect="false" :preserveSearch="true" openDirection="below">
<template slot="option" slot-scope="props" style="width: 100%">
<strong>{{props.option.id || '"'+props.search+'"'}}</strong>
<span v-if="props.option.count">&nbsp;({{props.option.count}})</span>
<p style="margin-bottom:0">{{props.option.title || "&nbsp;"}}</p>
</template>
</Multiselect>
Expand Down
9 changes: 4 additions & 5 deletions src/dbqueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,30 @@ module.exports = {
} }
],
GET_ALL_COLLECTIONS_PIPELINE: [
{ $match: { path: '/collections' } },
{ $match: { path: '/collections', 'content.collections': {$exists: true} } },
{ $addFields: { 'content.collections.backend': '$backend', 'content.collections.backendTitle': '$backendTitle', 'content.collections.retrieved': '$retrieved', 'content.collections.unsuccessfulCrawls': '$unsuccessfulCrawls' } },
{ $project: { 'collection': '$content.collections' } },
{ $unwind: '$collection' },
{ $replaceRoot: { newRoot: '$collection' } }
],
GET_ALL_PROCESSES_PIPELINE: [
// basically like for collections
{ $match: { path: '/processes' } },
{ $match: { path: '/processes', 'content.processes': {$exists: true} } },
{ $addFields: { 'content.processes.backend': '$backend', 'content.processes.backendTitle': '$backendTitle', 'content.processes.retrieved': '$retrieved', 'content.processes.unsuccessfulCrawls': '$unsuccessfulCrawls' } },
{ $project: { 'process': '$content.processes' } },
{ $unwind: '$process' },
{ $replaceRoot: {newRoot: '$process'} },
// convert `parameters` object to array because otherwise we can't search for parameter descriptions (MongoDB doesn't support wildcards for object keys)
{ $addFields: { 'parametersAsArray' : { $objectToArray: '$parameters' } } }
],
GET_DISTINCT_COLLECTIONS_WITH_COUNT_PIPELINE: [
GET_DISTINCT_COLLECTIONS_PIPELINE: [
{ $project: {id: {$ifNull: ["$id", "$name"]}, title: 1} }, // allow both id (v0.4) and name (v0.3)
{ $group: { // group by collection id, at the same time calculate the sum, and maintain title
_id: {$toLower: "$id"},
id: {$first: "$id"},
title: {$first: "$title"}, // if a collection *does* appear twice, the title is usually the same, so just using the first occurrence is enough
count: {$sum: 1}
} },
{ $sort: {count: -1, id: 1} } // sort by count DESC, id ASC
{ $sort: {id: 1} } // sort by id ASC
],
GET_DISTINCT_PROCESSES_WITH_COUNT_PIPELINE: [
{ $project: {id: {$ifNull: ["$id", "$name"]}, summary: 1} }, // allow both id (v0.4) and name (v0.3)
Expand Down

0 comments on commit 7c85298

Please sign in to comment.