Skip to content

Commit

Permalink
[#129] list all records when no search criteria is used
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdash committed Jul 1, 2024
1 parent 9796e83 commit 0747b9e
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions dspback/routers/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,34 @@ async def search(
term,
)

compound = {'filter': filters, 'must': must}
compound = {}
if filters:
compound = {'filter': filters}
if must:
compound['must'] = must

if term:
should = [{'autocomplete': {'query': term, 'path': key, 'fuzzy': {'maxEdits': 1}}} for key in search_paths]
compound['should'] = should

stages.insert(
0,
{
'$search': {
'index': 'fuzzy_search',
'compound': compound,
}
},
)
stages.append(
{'$set': {'score': {'$meta': 'searchScore'}, 'highlights': {'$meta': 'searchHighlights'}}},
)
if compound:
stages.insert(
0,
{
'$search': {
'index': 'fuzzy_search',
'compound': compound,
}
},
)

if term:
stages[0]['$search']['highlight'] = {'path': search_paths}
# get only results which meet minimum relevance score threshold
score_threshold = get_settings().search_relevance_score_threshold
stages.append({'$match': {'score': {'$gt': score_threshold}}})

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

return results


Expand Down Expand Up @@ -216,7 +219,6 @@ async def base_search(
must = []
stages = []
filters = []
must.append({'term': {'path': '@type', 'query': "Dataset"}})
if publishedStart:
filters.append(
{
Expand Down

0 comments on commit 0747b9e

Please sign in to comment.