99
1010from idc_collections .models import Attribute , DataSource , Attribute_Ranges , DataSetType
1111
12- from metadata . query_helpers import MOLECULAR_CATEGORIES
12+ from google_helpers . bigquery . utils import MOLECULAR_CATEGORIES
1313
1414logger = logging .getLogger ('main_logger' )
1515
@@ -112,9 +112,9 @@ def query_solr_and_format_result(query_settings, normalize_facets=True, normaliz
112112
113113# Execute a POST request to the solr server available available at settings.SOLR_URI
114114def query_solr (collection = None , fields = None , query_string = None , fqs = None , facets = None , sort = None , counts_only = True ,
115- collapse_on = None , offset = 0 , limit = 1000 , uniques = None , with_cursor = None , stats = None , totals = None ):
116- query_uri = "{}{}/query" .format (SOLR_URI , collection )
115+ collapse_on = None , offset = 0 , limit = 1000 , uniques = None , with_cursor = None , stats = None , totals = None , op = None ):
117116
117+ query_uri = "{}{}/query" .format (SOLR_URI , collection )
118118 payload = {
119119 "query" : query_string or "*:*" ,
120120 "limit" : 0 if counts_only else limit ,
@@ -124,6 +124,9 @@ def query_solr(collection=None, fields=None, query_string=None, fqs=None, facets
124124 }
125125 }
126126
127+ if op :
128+ payload ['params' ]['q.op' ] = op
129+
127130 if with_cursor :
128131 payload ['params' ]['cursorMark' ] = with_cursor
129132
@@ -174,7 +177,6 @@ def query_solr(collection=None, fields=None, query_string=None, fqs=None, facets
174177
175178 try :
176179 start = time .time ()
177-
178180 query_response = requests .post (query_uri , data = json .dumps (payload ), headers = {'Content-type' : 'application/json' }, auth = (SOLR_LOGIN , SOLR_PASSWORD ), verify = SOLR_CERT )
179181 stop = time .time ()
180182
@@ -392,7 +394,7 @@ def build_solr_facets(attrs, filter_tags=None, include_nulls=True, unique=None,
392394# still want those records when filtering on this attribute.
393395#
394396def build_solr_query (filters , comb_with = 'AND' , with_tags_for_ex = False , subq_join_field = None ,
395- search_child_records_by = None , global_value_op = 'OR' ):
397+ search_child_records_by = None , global_value_op = 'OR' , solr_default_op = 'OR' ):
396398
397399 # subq_join not currently used in IDC
398400 ranged_attrs = Attribute .get_ranged_attrs ()
@@ -502,7 +504,10 @@ def build_solr_query(filters, comb_with='AND', with_tags_for_ex=False, subq_join
502504
503505 # If it's looking for a single None value
504506 if len (values ) == 1 and values [0 ] == 'None' :
505- query_str += '(-%s:{* TO *})' % attr_name
507+ if (solr_default_op == "OR" ):
508+ query_str += '(-%s:{* TO *})' % attr_name
509+ else :
510+ query_str += '(*:* NOT %s:{* TO *})' % attr_name
506511 # If it's a ranged value, calculate the bins
507512 elif attr_name == 'bmi' :
508513 with_none = False
@@ -544,14 +549,19 @@ def build_solr_query(filters, comb_with='AND', with_tags_for_ex=False, subq_join
544549 clause = rngTemp .format (attr_name , values [0 ], values [1 ])
545550 else :
546551 clause = "{}:{}" .format (attr_name , values [0 ])
547-
548- query_str += (('(-(-(%s) +(%s:{* TO *})))' % (clause , attr_name )) if with_none else "(+({}))" .format (clause ))
552+ if (solr_default_op == "OR" ):
553+ query_str += (('(-(-(%s) +(%s:{* TO *})))' % (clause , attr_name )) if with_none else "(+({}))" .format (clause ))
554+ else :
555+ query_str += (('(%s OR (*:* NOT %s:{* TO *}))' % (clause , attr_name )) if with_none else "(+({}))" .format (clause ))
549556
550557 else :
551558 vals = "\" {} \" " .format (value_op ).join (values )
552559 if 'None' in values :
553560 values .remove ('None' )
554- query_str += '(-(-(%s:("%s")) +(%s:{* TO *})))' % (attr_name ,vals , attr_name )
561+ if (solr_default_op == "OR" ):
562+ query_str += '(-(-(%s:("%s")) +(%s:{* TO *})))' % (attr_name ,vals , attr_name )
563+ else :
564+ query_str += '((%s:("%s")) OR (*:* NOT %s:{* TO *}))' % (attr_name , vals , attr_name )
555565 else :
556566 query_str += '(+%s:("%s"))' % (attr_name , vals )
557567
0 commit comments