Commit 864186ba authored by Kamal Dodiya's avatar Kamal Dodiya
Browse files

Black - Reformatting

parent b9adb4f4
......@@ -17,5 +17,5 @@ import os
PAGE = os.getenv("PAGE", 1)
PER_PAGE = os.getenv("PAGE", 100)
SOLR_SERVER = os.getenv("SOLR_SERVER","ensembl-solr-svc:8983")
SOLR_COLLECTION = os.getenv("SOLR_COLLECTION", "genome_search_v1")
\ No newline at end of file
SOLR_SERVER = os.getenv("SOLR_SERVER", "ensembl-solr-svc:8983")
SOLR_COLLECTION = os.getenv("SOLR_COLLECTION", "genome_search_v1")
......@@ -12,6 +12,7 @@
limitations under the License.
"""
async def transform_request_for_solr(query_input):
"""
Transform client request parameter to the parameter expected by the SOLR
......@@ -63,4 +64,4 @@ async def transform_search_result(search_result):
del search_result_doc["id"]
del search_result_doc["_version_"]
transformed_search_result_docs.append(search_result_doc)
return transformed_search_result_docs
\ No newline at end of file
return transformed_search_result_docs
__version__ = '0.1.0'
__version__ = "0.1.0"
......@@ -21,11 +21,11 @@ from ensembl_search_hub.resources.models import SearchQuery, SearchResult
from ensembl_search_hub.resources.solr_client import SOLRClient
solr = SOLRClient(SOLR_SERVER, SOLR_COLLECTION)
app = FastAPI()
@app.get("/search", response_model=SearchResult)
async def get_search_results(search_query: SearchQuery):
"""
......
from typing import Optional, List
from pydantic import BaseModel
class SearchQuery(BaseModel):
query: str
genome_ids: List[str] # = Query(..., min_length=1)
......@@ -48,4 +49,4 @@ class SearchResultDoc(BaseModel):
class SearchResult(BaseModel):
meta: SearchResultMeta
matches: List[SearchResultDoc] = []
\ No newline at end of file
matches: List[SearchResultDoc] = []
......@@ -15,40 +15,46 @@
import asyncio, aiohttp
import json
class SOLRClient:
def __init__(self, server_url, collection):
self.server = server_url
self.collection = collection
self.search_url = f'{self.server}/{self.collection}/select?'
def _prepare_search_request(self, solr_query_input):
query_params = "&".join(f'{k}={v}' for k,v in solr_query_input.items())
request_string = f'{self.search_url}{query_params}'
print (f'>>> {request_string}')
return request_string
async def get_search_results(self, solr_query_input):
solr_request = self._prepare_search_request(solr_query_input)
headers = {'Accept': 'application/json'}
async with aiohttp.ClientSession() as session:
async with session.get(solr_request, headers=headers) as response:
if response.status == 200:
search_results = await response.json(content_type=None)
return search_results
def __init__(self, server_url, collection):
self.server = server_url
self.collection = collection
self.search_url = f"{self.server}/{self.collection}/select?"
def _prepare_search_request(self, solr_query_input):
query_params = "&".join(f"{k}={v}" for k, v in solr_query_input.items())
request_string = f"{self.search_url}{query_params}"
print(f">>> {request_string}")
return request_string
async def get_search_results(self, solr_query_input):
solr_request = self._prepare_search_request(solr_query_input)
headers = {"Accept": "application/json"}
async with aiohttp.ClientSession() as session:
async with session.get(solr_request, headers=headers) as response:
if response.status == 200:
search_results = await response.json(content_type=None)
return search_results
async def main():
solr_url = 'http://hx-rke-wp-webadmin-14-worker-1.caas.ebi.ac.uk:31118/solr'
collection = 'genome_search_v1'
e2020_solr = SOLRClient(solr_url, collection)
search_q="MSH2"
resp1 = await e2020_solr.get_search_results(search_q)
print (resp1['response']['numFound'])
resp2 = await e2020_solr.get_search_results(search_q, ["homo_sapiens_GCA_000001405_28"])
print (resp2['response']['numFound'])
resp3 = await e2020_solr.get_search_results(search_q, ["homo_sapiens_GCA_000001405_28", "homo_sapiens_GCA_000001405_14"])
print (resp3['response']['numFound'])
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
\ No newline at end of file
solr_url = "http://hx-rke-wp-webadmin-14-worker-1.caas.ebi.ac.uk:31118/solr"
collection = "genome_search_v1"
e2020_solr = SOLRClient(solr_url, collection)
search_q = "MSH2"
resp1 = await e2020_solr.get_search_results(search_q)
print(resp1["response"]["numFound"])
resp2 = await e2020_solr.get_search_results(
search_q, ["homo_sapiens_GCA_000001405_28"]
)
print(resp2["response"]["numFound"])
resp3 = await e2020_solr.get_search_results(
search_q, ["homo_sapiens_GCA_000001405_28", "homo_sapiens_GCA_000001405_14"]
)
print(resp3["response"]["numFound"])
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
......@@ -2,4 +2,4 @@ from ensembl_search_hub import __version__
def test_version():
assert __version__ == '0.1.0'
assert __version__ == "0.1.0"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment