Skip to content

Commit

Permalink
Adds q.op=AND to Solr queries so that boolean syntax will work (#459)
Browse files Browse the repository at this point in the history
We need to specify q.op=AND along with mm=100% to allow for boolean
query syntax, which is a little surprising, but explained in
https://issues.apache.org/jira/browse/SOLR-8812
  • Loading branch information
kevinschaper authored Nov 2, 2023
1 parent 029186a commit 9e9e7ea
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion backend/src/monarch_py/datamodels/solr.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class SolrQuery(BaseModel):
filter_queries: Optional[List[str]] = Field(default_factory=list)
query_fields: str = None
def_type: str = "edismax"
mm: str = "100%" # All tokens in the query must be found in the doc, equivalent to q.op="AND"
q_op: str = "AND" # See SOLR-8812, need this plus mm=100% to allow boolean operators in queries
mm: str = "100%" # All tokens in the query must be found in the doc
boost: str = None
sort: str = None

Expand Down Expand Up @@ -83,6 +84,8 @@ def _solrize(self, value):
return "qf"
elif value == "def_type":
return "defType"
elif value == "q_op":
return "q.op"
elif value is True:
return "true"
elif value is False:
Expand Down
1 change: 1 addition & 0 deletions backend/tests/fixtures/association_counts_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def association_counts_query():
],
"query_fields": None,
"def_type": "edismax",
"q_op": "AND",
"mm": "100%",
"boost": None,
"sort": None,
Expand Down
3 changes: 2 additions & 1 deletion backend/tests/fixtures/association_counts_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def association_counts_response():
return {
"responseHeader": {
"QTime": 4,
"QTime": 1,
"params": {
"facet.query": [
'(category:"biolink:DiseaseToPhenotypicFeatureAssociation") AND (subject:"MONDO:0020121" OR subject_closure:"MONDO:0020121")',
Expand Down Expand Up @@ -38,6 +38,7 @@ def association_counts_response():
"defType": "edismax",
"facet_min_count": "1",
"start": "0",
"q.op": "AND",
"fq": 'subject:"MONDO\\:0020121" OR subject_closure:"MONDO\\:0020121" OR object:"MONDO\\:0020121" OR object_closure:"MONDO\\:0020121"',
"rows": "20",
"facet": "true",
Expand Down
1 change: 1 addition & 0 deletions backend/tests/fixtures/association_query_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def association_query_direct():
],
"query_fields": "subject subject_label predicate object object_label",
"def_type": "edismax",
"q_op": "AND",
"mm": "100%",
"boost": None,
"sort": None,
Expand Down
1 change: 1 addition & 0 deletions backend/tests/fixtures/association_query_indirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def association_query_indirect():
],
"query_fields": "subject subject_label predicate object object_label",
"def_type": "edismax",
"q_op": "AND",
"mm": "100%",
"boost": None,
"sort": None,
Expand Down
3 changes: 2 additions & 1 deletion backend/tests/fixtures/association_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
def association_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 0,
"params": {
"mm": "100%",
"q": "*:*",
"defType": "edismax",
"facet_min_count": "1",
"start": "0",
"q.op": "AND",
"fq": 'subject:"MONDO\\:0020121" OR subject_closure:"MONDO\\:0020121" OR object:"MONDO\\:0020121" OR object_closure:"MONDO\\:0020121"',
"rows": "20",
"facet": "true",
Expand Down
3 changes: 2 additions & 1 deletion backend/tests/fixtures/association_table_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
def association_table_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 0,
"params": {
"mm": "100%",
"q": "*:*",
"defType": "edismax",
"facet_min_count": "1",
"start": "0",
"q.op": "AND",
"fq": [
"category:biolink\\:DiseaseToPhenotypicFeatureAssociation",
'subject:"MONDO\\:0020121" OR subject_closure:"MONDO\\:0020121" OR object:"MONDO\\:0020121" OR object_closure:"MONDO\\:0020121"',
Expand Down
1 change: 1 addition & 0 deletions backend/tests/fixtures/autocomplete_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def autocomplete_query():
"filter_queries": [],
"query_fields": "id^100 name^10 name_t^5 name_ac symbol^10 symbol_t^5 symbol_ac synonym synonym_t synonym_ac",
"def_type": "edismax",
"q_op": "AND",
"mm": "100%",
"boost": 'product(if(termfreq(category,"biolink:Disease"),10.0,1),if(and(termfreq(in_taxon,"NCBITaxon:9606"),termfreq(category,"biolink:Gene")),5.0,1))',
"sort": None,
Expand Down
3 changes: 2 additions & 1 deletion backend/tests/fixtures/autocomplete_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
def autocomplete_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 0,
"params": {
"mm": "100%",
"q": "fanc",
"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": "0",
"q.op": "AND",
"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",
Expand Down
1 change: 1 addition & 0 deletions backend/tests/fixtures/histopheno_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def histopheno_query():
"filter_queries": ["subject_closure:MONDO\\:0020121"],
"query_fields": None,
"def_type": "edismax",
"q_op": "AND",
"mm": "100%",
"boost": None,
"sort": None,
Expand Down
3 changes: 2 additions & 1 deletion backend/tests/fixtures/histopheno_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def histopheno_response():
return {
"responseHeader": {
"QTime": 6,
"QTime": 1,
"params": {
"facet.query": [
'object_closure:"HP:0000924"',
Expand Down Expand Up @@ -34,6 +34,7 @@ def histopheno_response():
"defType": "edismax",
"facet_min_count": "1",
"start": "0",
"q.op": "AND",
"fq": "subject_closure:MONDO\\:0020121",
"rows": "0",
"facet": "true",
Expand Down
1 change: 1 addition & 0 deletions backend/tests/fixtures/search_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def search_query():
"filter_queries": ["name:*"],
"query_fields": "id^100 name^10 name_t^5 name_ac symbol^10 symbol_t^5 symbol_ac synonym synonym_t synonym_ac",
"def_type": "edismax",
"q_op": "AND",
"mm": "100%",
"boost": 'product(if(termfreq(category,"biolink:Disease"),10.0,1),if(and(termfreq(in_taxon,"NCBITaxon:9606"),termfreq(category,"biolink:Gene")),5.0,1))',
"sort": None,
Expand Down
3 changes: 2 additions & 1 deletion backend/tests/fixtures/search_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
def search_response():
return {
"responseHeader": {
"QTime": 3,
"QTime": 1,
"params": {
"mm": "100%",
"q": "fanconi",
"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": "0",
"q.op": "AND",
"boost": 'product(if(termfreq(category,"biolink:Disease"),10.0,1),if(and(termfreq(in_taxon,"NCBITaxon:9606"),termfreq(category,"biolink:Gene")),5.0,1))',
"fq": "name:*",
"rows": "20",
Expand Down

0 comments on commit 9e9e7ea

Please sign in to comment.