From 63bc5c322569c4fa89a671adea9c8650c171f094 Mon Sep 17 00:00:00 2001 From: Kevin Schaper Date: Fri, 11 Aug 2023 15:59:21 -0700 Subject: [PATCH 1/2] Fixed autocomplete weirdness (was offsetting past the first result), plus in-taxon vs in-taxon-label fix that probably exists in another branch too --- backend/src/monarch_py/cli.py | 4 ++-- backend/src/monarch_py/datamodels/solr.py | 2 +- .../src/monarch_py/implementations/solr/solr_query_utils.py | 2 +- backend/src/monarch_py/service/solr_service.py | 1 + backend/src/monarch_py/solr_cli.py | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/src/monarch_py/cli.py b/backend/src/monarch_py/cli.py index f9b3e499d..cdb25bbfe 100644 --- a/backend/src/monarch_py/cli.py +++ b/backend/src/monarch_py/cli.py @@ -135,7 +135,7 @@ def associations( def search( q: str = typer.Option(None, "--query", "-q"), category: List[str] = typer.Option(None, "--category", "-c"), - in_taxon: str = typer.Option(None, "--in-taxon", "-t"), + in_taxon_label: str = typer.Option(None, "--in-taxon-label", "-t"), facet_fields: List[str] = typer.Option(None, "--facet-fields", "-ff"), facet_queries: List[str] = typer.Option(None, "--facet-queries"), limit: int = typer.Option(20, "--limit", "-l"), @@ -155,7 +155,7 @@ def search( Args: q: The query string to search for category: The category of the entity - taxon: The taxon of the entity + in_taxon_label: The taxon label to filter by limit: The number of entities to return offset: The offset of the first entity to be retrieved fmt: The format of the output (json, yaml, tsv, table) diff --git a/backend/src/monarch_py/datamodels/solr.py b/backend/src/monarch_py/datamodels/solr.py index 44fb555f9..8e3426c6b 100644 --- a/backend/src/monarch_py/datamodels/solr.py +++ b/backend/src/monarch_py/datamodels/solr.py @@ -37,7 +37,7 @@ class HistoPhenoKeys(Enum): class SolrQuery(BaseModel): q: str = "*:*" rows: int = 20 - start: int = 1 + start: int = 0 facet: bool = True facet_min_count = 1 facet_fields: Optional[List[str]] = Field(default_factory=list) diff --git a/backend/src/monarch_py/implementations/solr/solr_query_utils.py b/backend/src/monarch_py/implementations/solr/solr_query_utils.py index 0e1cfa746..75cd198fe 100644 --- a/backend/src/monarch_py/implementations/solr/solr_query_utils.py +++ b/backend/src/monarch_py/implementations/solr/solr_query_utils.py @@ -147,7 +147,7 @@ def build_search_query( def build_autocomplete_query(q: str) -> SolrQuery: - query = SolrQuery(q=q, limit=10, offset=0) + query = SolrQuery(q=q, limit=10, start=0) query.q = q # match the query fields to start with query.query_fields = entity_query_fields() diff --git a/backend/src/monarch_py/service/solr_service.py b/backend/src/monarch_py/service/solr_service.py index f68eb21b8..457819d89 100644 --- a/backend/src/monarch_py/service/solr_service.py +++ b/backend/src/monarch_py/service/solr_service.py @@ -26,6 +26,7 @@ def get(self, id): def query(self, q: SolrQuery) -> SolrQueryResult: url = f"{self.base_url}/{self.core.value}/select?{q.query_string()}" + logger.debug(f"SolrService.query: {url}") response = requests.get(url) data = json.loads(response.text) diff --git a/backend/src/monarch_py/solr_cli.py b/backend/src/monarch_py/solr_cli.py index 239b3b3d4..0f522b503 100644 --- a/backend/src/monarch_py/solr_cli.py +++ b/backend/src/monarch_py/solr_cli.py @@ -169,7 +169,7 @@ def associations( def search( q: str = typer.Option(None, "--query", "-q"), category: List[str] = typer.Option(None, "--category", "-c"), - in_taxon: str = typer.Option(None, "--in-taxon", "-t"), + in_taxon_label: str = typer.Option(None, "--in-taxon-label", "-t"), facet_fields: List[str] = typer.Option(None, "--facet-fields", "-ff"), facet_queries: List[str] = typer.Option(None, "--facet-queries"), limit: int = typer.Option(20, "--limit", "-l"), @@ -189,7 +189,7 @@ def search( Optional Args: q: The query string to search for category: The category of the entity - taxon: The taxon of the entity + in_taxon_label: The taxon label to filter on facet_fields: The fields to facet on facet_queries: The queries to facet on limit: The number of entities to return From f5018cfcbea3954b752cb8af2ba8754cdca102d8 Mon Sep 17 00:00:00 2001 From: Kevin Schaper Date: Fri, 11 Aug 2023 16:08:18 -0700 Subject: [PATCH 2/2] Fixture update, plus formatting --- backend/src/monarch_py/api/entity.py | 6 ++- .../solr/solr_implementation.py | 8 ++-- .../fixtures/association_table_response.py | 2 +- backend/tests/fixtures/autocomplete.py | 47 ++++++++++--------- backend/tests/fixtures/autocomplete_query.py | 2 +- .../tests/fixtures/autocomplete_response.py | 37 ++++++++------- backend/tests/fixtures/histopheno_response.py | 2 +- backend/tests/fixtures/search_response.py | 2 +- frontend/fixtures/association-table.json | 4 +- frontend/fixtures/autocomplete.json | 47 ++++++++++--------- 10 files changed, 88 insertions(+), 69 deletions(-) diff --git a/backend/src/monarch_py/api/entity.py b/backend/src/monarch_py/api/entity.py index 5a3bbfe64..e8d245733 100644 --- a/backend/src/monarch_py/api/entity.py +++ b/backend/src/monarch_py/api/entity.py @@ -51,7 +51,11 @@ def _association_table( title="Type of association to retrieve association table data for", ), query: str = Query(None, example="thumb", title="Query string to limit results to a subset"), - sort: List[str] = Query(None, example=["subject_label asc", "predicate asc", "object_label asc"], title="Sort results by a list of field + direction statements"), + sort: List[str] = Query( + None, + example=["subject_label asc", "predicate asc", "object_label asc"], + title="Sort results by a list of field + direction statements", + ), pagination: PaginationParams = Depends(), ) -> AssociationTableResults: """ diff --git a/backend/src/monarch_py/implementations/solr/solr_implementation.py b/backend/src/monarch_py/implementations/solr/solr_implementation.py index 980e10dfd..37f9487a5 100644 --- a/backend/src/monarch_py/implementations/solr/solr_implementation.py +++ b/backend/src/monarch_py/implementations/solr/solr_implementation.py @@ -322,10 +322,10 @@ def get_association_table( self, entity: str, category: str, - q: str =None, - sort: List[str]=None, - offset: int=0, - limit: int =5, + q: str = None, + sort: List[str] = None, + offset: int = 0, + limit: int = 5, ) -> AssociationTableResults: query = build_association_table_query( diff --git a/backend/tests/fixtures/association_table_response.py b/backend/tests/fixtures/association_table_response.py index 10cf52e4c..be2f5e1db 100644 --- a/backend/tests/fixtures/association_table_response.py +++ b/backend/tests/fixtures/association_table_response.py @@ -5,7 +5,7 @@ def association_table_response(): return { "responseHeader": { - "QTime": 0, + "QTime": 1, "params": { "mm": "100%", "q": "*:*", diff --git a/backend/tests/fixtures/autocomplete.py b/backend/tests/fixtures/autocomplete.py index 5fa3a7a77..c1d5201a5 100644 --- a/backend/tests/fixtures/autocomplete.py +++ b/backend/tests/fixtures/autocomplete.py @@ -8,6 +8,32 @@ def autocomplete(): "offset": 0, "total": 195, "items": [ + { + "id": "MONDO:0019391", + "category": "biolink:Disease", + "name": "Fanconi anemia", + "full_name": None, + "description": "Fanconi anemia (FA) is a hereditary DNA repair disorder characterized by progressive pancytopenia with bone marrow failure, variable congenital malformations and predisposition to develop hematological or solid tumors.", + "xref": [ + "DOID:13636", + "GARD:0006425", + "ICD9:284.09", + "MESH:D005199", + "MedDRA:10055206", + "NCIT:C62505", + "OMIMPS:227650", + "Orphanet:84", + "SCTID:30575002", + "UMLS:C0015625", + ], + "provided_by": "phenio_nodes", + "in_taxon": None, + "in_taxon_label": None, + "symbol": None, + "synonym": [], + "highlight": None, + "score": None, + }, { "id": "MONDO:0001083", "category": "biolink:Disease", @@ -353,27 +379,6 @@ def autocomplete(): "highlight": None, "score": None, }, - { - "id": "MONDO:0012186", - "category": "biolink:Disease", - "name": "Fanconi anemia complementation group I", - "full_name": None, - "description": "Fanconi anemia caused by mutations in the FANCI gene, encoding Fanconi anemia group I protein.", - "xref": [ - "DOID:0111091", - "MESH:C563802", - "NCIT:C129026", - "OMIM:609053", - "UMLS:C1836861", - ], - "provided_by": "phenio_nodes", - "in_taxon": None, - "in_taxon_label": None, - "symbol": None, - "synonym": [], - "highlight": None, - "score": None, - }, ], "facet_fields": [], "facet_queries": [], diff --git a/backend/tests/fixtures/autocomplete_query.py b/backend/tests/fixtures/autocomplete_query.py index 672513c2c..cae8e88a2 100644 --- a/backend/tests/fixtures/autocomplete_query.py +++ b/backend/tests/fixtures/autocomplete_query.py @@ -6,7 +6,7 @@ def autocomplete_query(): return { "q": "fanc", "rows": 20, - "start": 1, + "start": 0, "facet": True, "facet_fields": [], "facet_queries": [], diff --git a/backend/tests/fixtures/autocomplete_response.py b/backend/tests/fixtures/autocomplete_response.py index d531011c3..257103133 100644 --- a/backend/tests/fixtures/autocomplete_response.py +++ b/backend/tests/fixtures/autocomplete_response.py @@ -12,7 +12,7 @@ def autocomplete_response(): "defType": "edismax", "facet_min_count": "1", "qf": "id^100 name^10 name_t^5 name_ac symbol^10 symbol_t^5 symbol_ac synonym synonym_t synonym_ac", - "start": "1", + "start": "0", "boost": 'product(if(termfreq(category,"biolink:Disease"),10.0,1),if(and(termfreq(in_taxon,"NCBITaxon:9606"),termfreq(category,"biolink:Gene")),5.0,1))', "rows": "20", "facet": "true", @@ -20,8 +20,27 @@ def autocomplete_response(): }, "response": { "num_found": 195, - "start": 1, + "start": 0, "docs": [ + { + "id": "MONDO:0019391", + "category": "biolink:Disease", + "name": "Fanconi anemia", + "xref": [ + "DOID:13636", + "GARD:0006425", + "ICD9:284.09", + "MESH:D005199", + "MedDRA:10055206", + "NCIT:C62505", + "OMIMPS:227650", + "Orphanet:84", + "SCTID:30575002", + "UMLS:C0015625", + ], + "provided_by": "phenio_nodes", + "description": "Fanconi anemia (FA) is a hereditary DNA repair disorder characterized by progressive pancytopenia with bone marrow failure, variable congenital malformations and predisposition to develop hematological or solid tumors.", + }, { "id": "MONDO:0001083", "category": "biolink:Disease", @@ -235,20 +254,6 @@ def autocomplete_response(): "provided_by": "phenio_nodes", "description": "Inherited cancer-predisposing syndrome due to biallelic BRCA2 mutations is a rare cancer-predisposing syndrome, associated with the D1 subgroup of Fanconi anemia (FA), characterized by progressive bone marrow failure, cardiac, brain, intestinal or skeletal abnormalities and predisposition to various malignancies. Bone marrow suppression and the incidence of developmental abnormalities are less frequent than in other FA, but cancer risk is very high with the spectrum of childhood cancers including Wilms tumor, brain tumor (often medulloblastoma) and ALL/AML.", }, - { - "id": "MONDO:0012186", - "category": "biolink:Disease", - "name": "Fanconi anemia complementation group I", - "xref": [ - "DOID:0111091", - "MESH:C563802", - "NCIT:C129026", - "OMIM:609053", - "UMLS:C1836861", - ], - "provided_by": "phenio_nodes", - "description": "Fanconi anemia caused by mutations in the FANCI gene, encoding Fanconi anemia group I protein.", - }, ], }, "facet_counts": {"facet_fields": {}, "facet_queries": {}}, diff --git a/backend/tests/fixtures/histopheno_response.py b/backend/tests/fixtures/histopheno_response.py index 24285eded..0208f34ee 100644 --- a/backend/tests/fixtures/histopheno_response.py +++ b/backend/tests/fixtures/histopheno_response.py @@ -5,7 +5,7 @@ def histopheno_response(): return { "responseHeader": { - "QTime": 2, + "QTime": 1, "params": { "facet.query": [ 'object_closure:"HP:0000924"', diff --git a/backend/tests/fixtures/search_response.py b/backend/tests/fixtures/search_response.py index eb6e12db2..f29467560 100644 --- a/backend/tests/fixtures/search_response.py +++ b/backend/tests/fixtures/search_response.py @@ -5,7 +5,7 @@ def search_response(): return { "responseHeader": { - "QTime": 0, + "QTime": 1, "params": { "mm": "100%", "q": "fanconi", diff --git a/frontend/fixtures/association-table.json b/frontend/fixtures/association-table.json index 6873b19c6..f202fe4d9 100644 --- a/frontend/fixtures/association-table.json +++ b/frontend/fixtures/association-table.json @@ -63,7 +63,7 @@ "human disease or disorder" ], "subject_taxon": null, - "subject_taxon_label": "test subject taxon label", + "subject_taxon_label": null, "predicate": "biolink:has_phenotype", "object": "HP:0002460", "original_object": null, @@ -134,7 +134,7 @@ "organ system subdivision" ], "object_taxon": null, - "object_taxon_label": "test object taxon label", + "object_taxon_label": null, "primary_knowledge_source": "infores:hpo-annotations", "aggregator_knowledge_source": ["infores:monarchinitiative"], "category": "biolink:DiseaseToPhenotypicFeatureAssociation", diff --git a/frontend/fixtures/autocomplete.json b/frontend/fixtures/autocomplete.json index a179eb30d..2eeb6f379 100644 --- a/frontend/fixtures/autocomplete.json +++ b/frontend/fixtures/autocomplete.json @@ -3,6 +3,32 @@ "offset": 0, "total": 195, "items": [ + { + "id": "MONDO:0019391", + "category": "biolink:Disease", + "name": "Fanconi anemia", + "full_name": null, + "description": "Fanconi anemia (FA) is a hereditary DNA repair disorder characterized by progressive pancytopenia with bone marrow failure, variable congenital malformations and predisposition to develop hematological or solid tumors.", + "xref": [ + "DOID:13636", + "GARD:0006425", + "ICD9:284.09", + "MESH:D005199", + "MedDRA:10055206", + "NCIT:C62505", + "OMIMPS:227650", + "Orphanet:84", + "SCTID:30575002", + "UMLS:C0015625" + ], + "provided_by": "phenio_nodes", + "in_taxon": null, + "in_taxon_label": null, + "symbol": null, + "synonym": [], + "highlight": null, + "score": null + }, { "id": "MONDO:0001083", "category": "biolink:Disease", @@ -332,27 +358,6 @@ "synonym": [], "highlight": null, "score": null - }, - { - "id": "MONDO:0012186", - "category": "biolink:Disease", - "name": "Fanconi anemia complementation group I", - "full_name": null, - "description": "Fanconi anemia caused by mutations in the FANCI gene, encoding Fanconi anemia group I protein.", - "xref": [ - "DOID:0111091", - "MESH:C563802", - "NCIT:C129026", - "OMIM:609053", - "UMLS:C1836861" - ], - "provided_by": "phenio_nodes", - "in_taxon": null, - "in_taxon_label": null, - "symbol": null, - "synonym": [], - "highlight": null, - "score": null } ], "facet_fields": [],