Skip to content

Commit

Permalink
Merge pull request #137 from I-GUIDE/134-search-results-with-minimum-…
Browse files Browse the repository at this point in the history
…relevance-score

[#134] Search results with minimum relevance score
  • Loading branch information
Maurier authored May 15, 2024
2 parents d5a14e6 + b3e75e9 commit 9d1f380
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
DB_USERNAME: ${{ secrets.DB_USERNAME_BETA }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD_BETA }}
run: |
variables=("OIDC_ISSUER" "DB_USERNAME" "DB_PASSWORD" "DB_HOST" "DATABASE_NAME" "DB_PROTOCOL" "TESTING" "VITE_APP_LOGIN_URL" "HYDROSHARE_META_READ_URL" "HYDROSHARE_FILE_READ_URL")
variables=("OIDC_ISSUER" "DB_USERNAME" "DB_PASSWORD" "DB_HOST" "DATABASE_NAME" "DB_PROTOCOL" "TESTING" "VITE_APP_LOGIN_URL" "HYDROSHARE_META_READ_URL" "HYDROSHARE_FILE_READ_URL", "SEARCH_RELEVANCE_SCORE_THRESHOLD")
# Empty the .env file
> .env
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
variables=("OIDC_ISSUER" "DB_USERNAME" "DB_PASSWORD" "DB_HOST" "DATABASE_NAME" "DB_PROTOCOL" "TESTING" "VITE_APP_LOGIN_URL" "HYDROSHARE_META_READ_URL" "HYDROSHARE_FILE_READ_URL")
variables=("OIDC_ISSUER" "DB_USERNAME" "DB_PASSWORD" "DB_HOST" "DATABASE_NAME" "DB_PROTOCOL" "TESTING" "VITE_APP_LOGIN_URL" "HYDROSHARE_META_READ_URL" "HYDROSHARE_FILE_READ_URL", "SEARCH_RELEVANCE_SCORE_THRESHOLD")
# Empty the .env file
> .env
Expand Down
1 change: 1 addition & 0 deletions api/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Settings(BaseSettings):
oidc_issuer: str
hydroshare_meta_read_url: HttpUrl
hydroshare_file_read_url: HttpUrl
search_relevance_score_threshold: float = 1.4

def __init__(self, **data: Any) -> None:
super().__init__(**data)
Expand Down
6 changes: 6 additions & 0 deletions api/routes/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from fastapi import APIRouter, Request, Depends
from pydantic import BaseModel, validator

from api.config import get_settings

router = APIRouter()


Expand Down Expand Up @@ -153,6 +155,10 @@ def stages(self):
stages.append(
{'$set': {'score': {'$meta': 'searchScore'}, 'highlights': {'$meta': 'searchHighlights'}}},
)
if self.term:
# get only results which meet minimum relevance score threshold
score_threshold = get_settings().search_relevance_score_threshold
stages.append({'$match': {'score': {'$gt': score_threshold}}})
return stages


Expand Down

0 comments on commit 9d1f380

Please sign in to comment.