Sadum1 commited on
Commit
8d5a786
·
verified ·
1 Parent(s): 87ba52d

Update backend/app/search.py

Browse files
Files changed (1) hide show
  1. backend/app/search.py +14 -0
backend/app/search.py CHANGED
@@ -32,6 +32,7 @@ from app.schemas import (
32
  SourceCount,
33
  )
34
  from app.sources.europe_pmc_search import search_europe_pmc
 
35
  from app.sources.pubmed_search import search_pubmed
36
 
37
  # NTP and IARC have no public REST/JSON API (confirmed by research) — only
@@ -98,6 +99,15 @@ def build_europe_pmc_query(groups: list[list[str]]) -> str:
98
  )
99
 
100
 
 
 
 
 
 
 
 
 
 
101
  def describe_strategy(groups: list[list[str]]) -> str:
102
  """Database-neutral strategy for display and reporting."""
103
  return (
@@ -138,6 +148,7 @@ async def run_search(protocol: Protocol) -> SearchRun:
138
  per_source = {
139
  LiteratureSource.PUBMED: legacy,
140
  LiteratureSource.EUROPE_PMC: legacy,
 
141
  }
142
  else:
143
  query_mode = "search_terms"
@@ -145,6 +156,7 @@ async def run_search(protocol: Protocol) -> SearchRun:
145
  per_source = {
146
  LiteratureSource.PUBMED: build_pubmed_query(groups),
147
  LiteratureSource.EUROPE_PMC: build_europe_pmc_query(groups),
 
148
  }
149
 
150
  source_counts: list[SourceCount] = []
@@ -159,6 +171,8 @@ async def run_search(protocol: Protocol) -> SearchRun:
159
  tasks.append(search_pubmed(per_source[source]))
160
  elif source == LiteratureSource.EUROPE_PMC:
161
  tasks.append(search_europe_pmc(per_source[source]))
 
 
162
 
163
  results = await asyncio.gather(*tasks) if tasks else []
164
  for count, items in results:
 
32
  SourceCount,
33
  )
34
  from app.sources.europe_pmc_search import search_europe_pmc
35
+ from app.sources.openalex_search import search_openalex # OpenAlex
36
  from app.sources.pubmed_search import search_pubmed
37
 
38
  # NTP and IARC have no public REST/JSON API (confirmed by research) — only
 
99
  )
100
 
101
 
102
+ def build_openalex_query(groups: list[list[str]]) -> str: # OpenAlex
103
+ """e.g. ("metformin") AND ("lactic acidosis" OR "lactate") — sent as the
104
+ title-and-abstract-only search, so the field restriction is applied by
105
+ the openalex_search module, not written into the query text."""
106
+ return " AND ".join(
107
+ "(" + " OR ".join(f'"{term}"' for term in group) + ")" for group in groups
108
+ )
109
+
110
+
111
  def describe_strategy(groups: list[list[str]]) -> str:
112
  """Database-neutral strategy for display and reporting."""
113
  return (
 
148
  per_source = {
149
  LiteratureSource.PUBMED: legacy,
150
  LiteratureSource.EUROPE_PMC: legacy,
151
+ LiteratureSource.OPENALEX: legacy, # OpenAlex
152
  }
153
  else:
154
  query_mode = "search_terms"
 
156
  per_source = {
157
  LiteratureSource.PUBMED: build_pubmed_query(groups),
158
  LiteratureSource.EUROPE_PMC: build_europe_pmc_query(groups),
159
+ LiteratureSource.OPENALEX: build_openalex_query(groups), # OpenAlex
160
  }
161
 
162
  source_counts: list[SourceCount] = []
 
171
  tasks.append(search_pubmed(per_source[source]))
172
  elif source == LiteratureSource.EUROPE_PMC:
173
  tasks.append(search_europe_pmc(per_source[source]))
174
+ elif source == LiteratureSource.OPENALEX: # OpenAlex
175
+ tasks.append(search_openalex(per_source[source]))
176
 
177
  results = await asyncio.gather(*tasks) if tasks else []
178
  for count, items in results: