fix(backend/person_search): search failing due to unsupported search parameters
This commit is contained in:
@@ -7,6 +7,10 @@ def search(
|
||||
index: str,
|
||||
query_field: str = None,
|
||||
query_value: str = None,
|
||||
query: dict = None,
|
||||
source = None,
|
||||
size: int = None,
|
||||
sort: list = None,
|
||||
body: dict = None,
|
||||
) -> dict[str, Any]:
|
||||
|
||||
@@ -14,16 +18,26 @@ def search(
|
||||
"Authorization": f"ApiKey {config.settings.elasticsearch_api_key}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
payload = {
|
||||
"query": {
|
||||
"query_string": {
|
||||
"default_field": query_field,
|
||||
"query": query_value
|
||||
|
||||
if body is not None:
|
||||
payload = body
|
||||
elif query is not None:
|
||||
payload = {"query": query}
|
||||
if source is not None:
|
||||
payload["_source"] = source
|
||||
if size is not None:
|
||||
payload["size"] = size
|
||||
if sort is not None:
|
||||
payload["sort"] = sort
|
||||
else:
|
||||
payload = {
|
||||
"query": {
|
||||
"query_string": {
|
||||
"default_field": query_field,
|
||||
"query": query_value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if body != None:
|
||||
payload = body
|
||||
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
|
||||
@@ -395,15 +395,9 @@ def search_persons_by_name(
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
body = {
|
||||
"size":limit,
|
||||
"query":search_query,
|
||||
"_source":include.split(",") if include else True,
|
||||
}
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
index="openalex-authors",
|
||||
body=body,
|
||||
query=search_query,
|
||||
source=include.split(",") if include else True,
|
||||
size=limit,
|
||||
@@ -438,19 +432,11 @@ def search_persons_by_institution(
|
||||
},
|
||||
}
|
||||
}
|
||||
body = {
|
||||
"size":limit,
|
||||
"query":search_query,
|
||||
"_source":include.split(",") if include else True,
|
||||
"sort":[{"works_count": {"order": "desc"}}]
|
||||
}
|
||||
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
index="openalex-authors",
|
||||
body=body,
|
||||
source=include.split(",") if include else True,
|
||||
query=search_query,
|
||||
source=include.split(",") if include else True,
|
||||
size=limit,
|
||||
sort=[{"works_count": {"order": "desc"}}],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user