def search_solr(self, request_dict_json): """searches solr to get raw solr search results""" # Start building solr query if self.item_type_limit == "projects": self.facet_fields = self.PROJECT_FACET_FIELDS request_dict = json.loads(request_dict_json) query = self.compose_query(request_dict) """ try: response = self.solr.search(**query) except: # some hassels to handle project pivot queries response = KludgeSolrResponse() squery = response.build_request(query) url = urljoin(self.solr.base_url, 'select') http_response = self.solr.make_request.post(url, data=squery, timeout=240) response.raw_content = parse_response(http_response.content) """ # some hassels to handle project pivot queries response = KludgeSolrResponse() squery = response.build_request(query) url = urljoin(self.solr.base_url, "select") http_response = self.solr.make_request.post(url, data=squery, timeout=240) response.raw_content = parse_response(http_response.content) return response
def search_solr(self, request_dict_json): """searches solr to get raw solr search results""" # Start building solr query if self.item_type_limit == 'projects': self.facet_fields = self.PROJECT_FACET_FIELDS request_dict = json.loads(request_dict_json) query = self.compose_query(request_dict) """ try: response = self.solr.search(**query) except: # some hassels to handle project pivot queries response = KludgeSolrResponse() squery = response.build_request(query) url = urljoin(self.solr.base_url, 'select') http_response = self.solr.make_request.post(url, data=squery, timeout=240) response.raw_content = parse_response(http_response.content) """ # some hassels to handle project pivot queries response = KludgeSolrResponse() squery = response.build_request(query) url = urljoin(self.solr.base_url, 'select') http_response = self.solr.make_request.post(url, data=squery, timeout=240) response.raw_content = parse_response(http_response.content) return response
def pivot(self, search, facet_field, pivot_field, limit=1): try: field = "%s,%s" % (facet_field, pivot_field) query = {} query['q'] = search query['facet'] = 'true' query['facet.pivot'] = field query['facet.limit'] = limit query['facet.mincount'] = 1 query['rows'] = 0 queries = build_request(query) http_response = requests.get(urljoin(self.cursor.base_url, 'select'), params=queries) if http_response is not None: content = http_response.content if content is not None: content = parse_response(content) # print content if content is not None and 'facet_counts' in content: facet = content['facet_counts'] # print facet if facet is not None and 'facet_pivot' in facet: pivotList = facet['facet_pivot'][field] result = {} for pivot in pivotList: data = { 'total': 0, 'pos': 0, 'neu': 0, 'neg': 0 } data['total'] = pivot['count'] p = pivot['pivot'] for s in p: if str(s['value']) == '1': data['pos'] = s['count'] elif str(s['value']) == '-1': data['neg'] = s['count'] elif str(s['value']) == '0': data['neu'] = s['count'] # print data result[pivot['value']] = data return result except Exception, e: print "Error parsing facet pivot..." print e
def search_solr(self, request_dict_json): """searches solr to get raw solr search results""" # Start building solr query if self.item_type_limit == 'projects': self.facet_fields = self.PROJECT_FACET_FIELDS else: # add chronology stats fields, because its not just for projects self.stats_fields += self.CHRONO_STATS_FIELDS request_dict = json.loads(request_dict_json) query = self.compose_query(request_dict) if 'fq' in query: if isinstance(query['fq'], list): new_fq = [] for old_fq in query['fq']: if isinstance(old_fq, str): new_fq.append(old_fq.replace('(())', ' ')) query['fq'] = new_fq if self.do_bot_limit: # limit bots from requesting facets query['facet.field'] = [] query['stats.field'] = [] """ try: response = self.solr.search(**query) except: # some hassels to handle project pivot queries response = KludgeSolrResponse() squery = response.build_request(query) url = urljoin(self.solr.base_url, 'select') http_response = self.solr.make_request.post(url, data=squery, timeout=240) response.raw_content = parse_response(http_response.content) """ logger = logging.getLogger(__name__) # some hassels to handle project pivot queries response = KludgeSolrResponse() squery = response.build_request(query) url = urljoin(self.solr.base_url, 'select') try: http_response = self.solr.make_request.post(url, data=squery, timeout=240) response.raw_content = parse_response(http_response.content) except Exception as error: response = {} logger.error('[' + datetime.now().strftime('%x %X ') + settings.TIME_ZONE + '] Error: ' + str(error) + ' => Query: ' + str(squery)) return response
def query_solr(self, query): """ Connects to solr and runs a query""" query = self.finish_query(query) self.solr_connect() url = urljoin(self.solr.base_url, 'select') try: http_response = self.solr.make_request.post( url, data=query, timeout=240 ) self.solr_response = parse_response(http_response.content) except Exception as error: logger.error( '[' + datetime.now().strftime('%x %X ') + settings.TIME_ZONE + '] Error: ' + str(error) + ' => Query: ' + str(query) ) return self.solr_response