Spaces:
Running
Running
fix: reliable ArXiv ID lookup and uniformized paper ID prefixes
Browse files
app/api/routes/discovery.py
CHANGED
|
@@ -92,6 +92,7 @@ async def discovery_search(request: SearchRequest, db: Session = Depends(get_db)
|
|
| 92 |
arxiv_data = arxiv_service.fetch_papers(request.query, request.max_results)
|
| 93 |
for p in arxiv_data:
|
| 94 |
p["source"] = "ArXiv"
|
|
|
|
| 95 |
p["has_pdf"] = True # ArXiv always has PDF
|
| 96 |
|
| 97 |
# 2. Fetch from DOAJ
|
|
|
|
| 92 |
arxiv_data = arxiv_service.fetch_papers(request.query, request.max_results)
|
| 93 |
for p in arxiv_data:
|
| 94 |
p["source"] = "ArXiv"
|
| 95 |
+
p["id"] = f"arxiv_{p['id']}" # Uniformize with prefixes
|
| 96 |
p["has_pdf"] = True # ArXiv always has PDF
|
| 97 |
|
| 98 |
# 2. Fetch from DOAJ
|
app/services/analysis_service.py
CHANGED
|
@@ -94,7 +94,10 @@ class AnalysisService:
|
|
| 94 |
svc = PubMedService(); remote_data = svc.fetch_papers(pid.replace("pubmed_", ""), 1)
|
| 95 |
elif "openalex_" in pid:
|
| 96 |
svc = OpenAlexService(); remote_data = svc.fetch_papers(pid.replace("openalex_", ""), 1)
|
|
|
|
|
|
|
| 97 |
else:
|
|
|
|
| 98 |
svc = ArXivService(); remote_data = svc.fetch_papers(pid, 1)
|
| 99 |
|
| 100 |
if remote_data:
|
|
@@ -111,6 +114,8 @@ class AnalysisService:
|
|
| 111 |
db.commit()
|
| 112 |
db.refresh(paper)
|
| 113 |
logger.info(f"Saved remote paper {pid} to project {project_id}")
|
|
|
|
|
|
|
| 114 |
except Exception as fetch_err:
|
| 115 |
logger.error(f"Failed to fetch/save remote paper {pid}: {fetch_err}")
|
| 116 |
|
|
|
|
| 94 |
svc = PubMedService(); remote_data = svc.fetch_papers(pid.replace("pubmed_", ""), 1)
|
| 95 |
elif "openalex_" in pid:
|
| 96 |
svc = OpenAlexService(); remote_data = svc.fetch_papers(pid.replace("openalex_", ""), 1)
|
| 97 |
+
elif "arxiv_" in pid:
|
| 98 |
+
svc = ArXivService(); remote_data = svc.fetch_papers(pid.replace("arxiv_", ""), 1)
|
| 99 |
else:
|
| 100 |
+
# Fallback to ArXiv if no prefix (for old saved papers without prefix)
|
| 101 |
svc = ArXivService(); remote_data = svc.fetch_papers(pid, 1)
|
| 102 |
|
| 103 |
if remote_data:
|
|
|
|
| 114 |
db.commit()
|
| 115 |
db.refresh(paper)
|
| 116 |
logger.info(f"Saved remote paper {pid} to project {project_id}")
|
| 117 |
+
else:
|
| 118 |
+
logger.warning(f"No remote data found for {pid}")
|
| 119 |
except Exception as fetch_err:
|
| 120 |
logger.error(f"Failed to fetch/save remote paper {pid}: {fetch_err}")
|
| 121 |
|
app/services/arxiv_service.py
CHANGED
|
@@ -17,8 +17,13 @@ class ArXivService:
|
|
| 17 |
Search ArXiv for papers (Metadata only).
|
| 18 |
"""
|
| 19 |
logger.info(f"Searching ArXiv for: {query} (max: {max_results})")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
search = arxiv.Search(
|
| 21 |
-
query=query,
|
|
|
|
| 22 |
max_results=max_results,
|
| 23 |
sort_by=arxiv.SortCriterion.Relevance
|
| 24 |
)
|
|
|
|
| 17 |
Search ArXiv for papers (Metadata only).
|
| 18 |
"""
|
| 19 |
logger.info(f"Searching ArXiv for: {query} (max: {max_results})")
|
| 20 |
+
|
| 21 |
+
# Check if query looks like an ArXiv ID to use id_list (more reliable)
|
| 22 |
+
is_id = "." in query or "/" in query
|
| 23 |
+
|
| 24 |
search = arxiv.Search(
|
| 25 |
+
query="" if is_id else query,
|
| 26 |
+
id_list=[query] if is_id else [],
|
| 27 |
max_results=max_results,
|
| 28 |
sort_by=arxiv.SortCriterion.Relevance
|
| 29 |
)
|