Merge branch 'dev' of https://project.nes.uni-due.de/gitea/lbs/smartguide into ts-82-author-overview-and-description
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(
|
||||
|
||||
@@ -19,7 +19,7 @@ import json
|
||||
import time
|
||||
from . import schema
|
||||
from . import model
|
||||
from . import config
|
||||
from . import configxs
|
||||
from .integrations import elasticsearch
|
||||
from .integrations import llm
|
||||
from . import util
|
||||
@@ -55,9 +55,8 @@ es_client = _init_es_client()
|
||||
|
||||
topic_cache_filename: str = "topic_hierarchy_cache.json"
|
||||
|
||||
S = TypeVar("S", bound=schema.Base)
|
||||
M = TypeVar("M", bound=model.BaseModel)
|
||||
|
||||
S = TypeVar('S', bound=schema.Base)
|
||||
M = TypeVar('M', bound=model.BaseModel)
|
||||
|
||||
def filter_none():
|
||||
return True
|
||||
@@ -346,10 +345,11 @@ def generate_person_bio(author_id: str, include: Optional[set[str]] = None) -> s
|
||||
|
||||
return bio
|
||||
|
||||
def get_person_by_id(author_id: str, include: Optional[str] = None) -> AuthorsListResponse:
|
||||
body = {
|
||||
"_source":include.split(",") if include else True,
|
||||
}
|
||||
|
||||
def get_person_by_id(
|
||||
author_id: str, include: Optional[str] = None
|
||||
) -> AuthorsListResponse:
|
||||
try:
|
||||
hit = elasticsearch.get(
|
||||
index="openalex-authors",
|
||||
@@ -383,16 +383,18 @@ def search_persons_by_name(
|
||||
"display_name": {"query": author_name, "boost": 3}
|
||||
}
|
||||
},
|
||||
{"match": {"display_name": {"query": author_name, "fuzziness": 1}}},
|
||||
# {
|
||||
# "match": {
|
||||
# "display_name": {
|
||||
# "query": author_name,
|
||||
# "fuzziness": 1
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
body = {
|
||||
"size":limit,
|
||||
"query":search_query,
|
||||
"_source":include.split(",") if include else True,
|
||||
}
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
index="openalex-authors",
|
||||
@@ -517,12 +519,11 @@ def search_persons_by_institution(
|
||||
},
|
||||
}
|
||||
}
|
||||
print(include, institution_name)
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
index="openalex-authors",
|
||||
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