Skip to content

Commit

Permalink
feat(config): add scoring related values to config #398
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add scoring related values to config
  • Loading branch information
VKTB committed Feb 13, 2023
1 parent 22325f4 commit 0472d96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions datagateway_api/config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ search_api:
mechanism: "anon"
username: ""
password: ""
search_scoring:
enabled: false
api_url: "http://localhost:9000/score"
api_request_timeout: 5
group: "documents" #corresponds to the defined group in the scoring app. https://github.com/panosc-eu/panosc-search-scoring/blob/master/docs/md/PaNOSC_Federated_Search_Results_Scoring_API.md#model
limit: 1000
flask_reloader: false
log_level: "DEBUG"
log_location: "/home/runner/work/datagateway/datagateway/datagateway-api/datagateway_api/logs.log"
Expand Down
9 changes: 9 additions & 0 deletions datagateway_api/src/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class Config:
validate_assignment = True


class SearchScoring(BaseModel):
enabled: StrictBool
api_url: StrictStr
api_request_timeout: StrictInt
group: StrictStr
limit: StrictInt


class SearchAPI(BaseModel):
"""
Configuration model class that implements pydantic's BaseModel class to allow for
Expand All @@ -133,6 +141,7 @@ class SearchAPI(BaseModel):
mechanism: StrictStr
username: StrictStr
password: StrictStr
search_scoring: SearchScoring

_validate_extension = validator("extension", allow_reuse=True)(validate_extension)

Expand Down
8 changes: 4 additions & 4 deletions datagateway_api/src/search_api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ def get_score(entities, query):
try:
data = {
"query": query,
"group": Config.config.search_api.scoring_group,
"limit": Config.config.search_api.scoring_limit,
"group": Config.config.search_api.search_scoring.group,
"limit": Config.config.search_api.search_scoring.limit,
# With itemIds, scoring server returns a 400 error. No idea why.
# "itemIds": list(map(lambda entity: (entity["pid"]), entities)), #
}
response = requests.post(
Config.config.search_api.scoring_server,
Config.config.search_api.search_scoring.api_url,
json=data,
timeout=5, # Could this be a configuration parameter?
timeout=Config.config.search_api.search_scoring.api_request_timeout,
)
response.raise_for_status()
return response.json()["scores"]
Expand Down

0 comments on commit 0472d96

Please sign in to comment.