Skip to content

Commit

Permalink
Merge pull request #98 from geodatagouv/tusbar/fix-search-index
Browse files Browse the repository at this point in the history
Fix search default index
  • Loading branch information
tusbar committed Dec 3, 2018
2 parents 42a2ec2 + 81059c0 commit 3542e57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
10 changes: 8 additions & 2 deletions lib/models/ConsolidatedRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ const schema = new Schema({
})

/* Indexes */
schema.index({createdAt: -1})
schema.index({'facets.name': 1, 'facets.value': 1})
schema.index({'resources.serviceId': 1})
schema.index({
createdAt: -1
})
schema.index({
'facets.name': 1,
'facets.value': 1,
createdAt: -1
})

schema.index({
'metadata.type': 1,
Expand Down
21 changes: 15 additions & 6 deletions lib/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,22 @@ module.exports = function (searchQuery, catalogName) {

const resolvers = {
results: () => {
const select = {}
const sort = {}

if (query.$text) {
select.score = {
$meta: 'textScore'
}

sort.score = {
$meta: 'textScore'
}
}

return ConsolidatedRecord.find(query)
.select({
score: {
$meta: 'textScore'
},
...select,
recordId: 1,
'metadata.title': 1,
'metadata.description': 1,
Expand All @@ -96,9 +107,7 @@ module.exports = function (searchQuery, catalogName) {
'metadata.revisionDate': 1
})
.sort({
score: {
$meta: 'textScore'
},
...sort,
createdAt: -1
})
.skip(offset)
Expand Down

0 comments on commit 3542e57

Please sign in to comment.