Skip to content

Commit

Permalink
[#136] number of matching records for term based search
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdash committed Aug 27, 2024
1 parent 3954b7a commit 93d0f3a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions dspback/routers/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,43 @@ async def search(
# get only results which meet minimum relevance score threshold
score_threshold = get_settings().search_relevance_score_threshold
stages.append({'$match': {'score': {'$gt': score_threshold}}})
stages[0]['$search']['count'] = {'type': 'total'}

stages.append({'$project': {'meta': "$$SEARCH_META",
'_id': 0,
'@context': 1,
'repository_identifier': 1,
'url': 1,
'@type': 1,
'provider': 1,
'name': 1,
'description': 1,
'keywords': 1,
'creator': 1,
'funding': 1,
'temporalCoverage': 1,
'spatialCoverage': 1,
'license': 1,
'datePublished': 1,
'dateCreated': 1,
'relations': 1,
'legacy': 1,
'clusters': 1,
'score': 1,
'highlights': {'$meta': 'searchHighlights'}
}
})

results = await request.app.db[get_settings().mongo_database]["discovery"].aggregate(stages).to_list(pageSize)

if term:
meta = None
for result in results:
meta = result.pop('meta', None)
if meta:
results = {"meta": meta, "docs": results}
else:
results = {"docs": results}
return results


Expand Down

0 comments on commit 93d0f3a

Please sign in to comment.