fixed backed endpoints
This commit is contained in:
@@ -12,7 +12,7 @@ from . import logic
|
||||
from . import model
|
||||
|
||||
|
||||
router = APIRouter(prefix="/authors", tags=["Funding"])
|
||||
router = APIRouter(prefix="/api/inse-service/authors", tags=["Funding"])
|
||||
|
||||
|
||||
@router.get(
|
||||
|
||||
@@ -18,7 +18,6 @@ import json
|
||||
from . import schema
|
||||
from . import model
|
||||
from . import config
|
||||
from .integrations import llm
|
||||
|
||||
|
||||
from inse.models.topic import Topic
|
||||
|
||||
@@ -11,7 +11,6 @@ from typing import Optional, Callable, Any, List
|
||||
import hashlib
|
||||
import httpx
|
||||
from fastapi import HTTPException
|
||||
|
||||
from .. import config
|
||||
from .. import util
|
||||
from ..integrations import llm
|
||||
@@ -315,87 +314,6 @@ def search_persons_by_institution(
|
||||
persons = [util.get_persons_data(hit) for hit in hits]
|
||||
return AuthorsListResponse(results=persons,meta=Meta(count=total_count,page=page_offset))
|
||||
|
||||
FILTER_BUILDERS: dict[str, Callable[[Any], dict]] = {
|
||||
"institution": lambda v: {
|
||||
"nested": {
|
||||
"path": "last_known_institutions",
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"match_phrase": {
|
||||
"last_known_institutions.display_name": v
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"topic": lambda v: {
|
||||
"nested": {
|
||||
"path": "topics",
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"match_phrase": {
|
||||
"topics.display_name": v
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
def search_persons_with_filters(req: PersonSearchRequest) -> AuthorsListResponse:
|
||||
should_clauses = []
|
||||
must_clauses = []
|
||||
|
||||
if req.name:
|
||||
should_clauses = [
|
||||
{"match_phrase": {"display_name": {"query": req.name, "boost": 5}}},
|
||||
{"match_phrase_prefix": {"display_name": {"query": req.name, "boost": 3}}},
|
||||
]
|
||||
|
||||
for field, value in req.filters.model_dump(exclude_none=True).items():
|
||||
builder = FILTER_BUILDERS.get(field)
|
||||
if builder:
|
||||
must_clauses.append(builder(value))
|
||||
|
||||
if should_clauses or must_clauses:
|
||||
query = {
|
||||
"bool": {
|
||||
**({"should": should_clauses, "minimum_should_match": 1} if should_clauses else {}),
|
||||
**({"must": must_clauses} if must_clauses else {}),
|
||||
}
|
||||
}
|
||||
else:
|
||||
query = {"match_all": {}}
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
index="openalex-authors",
|
||||
query=query,
|
||||
offset=req.page_offset,
|
||||
source=req.include.split(",") if req.include else True,
|
||||
size=req.limit,
|
||||
track_total_hits=True,
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Elasticsearch search failed: {str(e)}")
|
||||
|
||||
total_count = response.get("hits", {}).get("total", {}).get("value", 0)
|
||||
hits = response.get("hits", {}).get("hits", [])
|
||||
|
||||
return AuthorsListResponse(
|
||||
results=[util.get_persons_data(hit) for hit in hits],
|
||||
meta=Meta(count=total_count, page=req.page_offset),
|
||||
)
|
||||
|
||||
|
||||
def _enrich_author_data(author_data) -> Optional[CustomAuthor]:
|
||||
if not author_data:
|
||||
return None
|
||||
|
||||
@@ -175,17 +175,6 @@ def search_persons_by_institution(
|
||||
):
|
||||
return logic.search_persons_by_institution(institution_name, include=include,page_offset=page_offset,limit=limit)
|
||||
|
||||
@router.post(
|
||||
"/persons/searchWithFilters",
|
||||
operation_id="searchPersonsWithFilters",
|
||||
response_model=AuthorsListResponse,
|
||||
summary="Search for persons with optional name and filters.",
|
||||
tags=["Persons"],
|
||||
)
|
||||
def search_persons_with_filters(body: model.PersonSearchRequest):
|
||||
return logic.search_persons_with_filters(body)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/persons/search-list",
|
||||
operation_id="searchPersonsList",
|
||||
|
||||
@@ -27,8 +27,6 @@ from . import schema
|
||||
from . import database
|
||||
from . import security
|
||||
from . import util
|
||||
from .works import service as works_service
|
||||
from .funders import service as funders_service
|
||||
|
||||
|
||||
|
||||
@@ -44,8 +42,6 @@ router = APIRouter(
|
||||
responses={404: {"description": "Not found"}},
|
||||
)
|
||||
|
||||
router.include_router(funders_service.router)
|
||||
|
||||
# @app.get("/", include_in_schema=False)
|
||||
# async def show_api():
|
||||
# return RedirectResponse("api")
|
||||
|
||||
@@ -65,8 +65,6 @@ model/model2-yr-mean-citedness.ts
|
||||
model/models.ts
|
||||
model/open-access.ts
|
||||
model/person-bio.ts
|
||||
model/person-filters.ts
|
||||
model/person-search-request.ts
|
||||
model/publication-ids-by-author-position.ts
|
||||
model/publications-by-author-response.ts
|
||||
model/score.ts
|
||||
|
||||
Reference in New Issue
Block a user