def add_query_tweaks(): """ Add query tweaks set in control panel """ params = {} for id in ["qf", "bq", "bf"]: value = get_setting(field=id) if value: params[id] = value if params: params["defType"] = "edismax" return params
def extract_elevate_schema(query): """ If no site_name is passed in query and remote_elevate_schema is set, return the schema from remote site. """ local_schema_json = get_setting( field="elevate_schema", interface=IElevateSettings ) remote_schema = get_setting( field="remote_elevate_schema", interface=IRerSolrpushSettings ) # if local_schema is set and there is a filter on site_name, return the # local elevate schema if local_schema_json: local_schema = json.loads(local_schema_json) if local_schema: if query.get("site_name", []): return local_schema if not remote_schema: return local_schema if remote_schema: try: resp = requests.get( remote_schema, headers={"Accept": "application/json"} ) except requests.exceptions.RequestException as err: logger.error("Connection problem:\n{0}".format(err)) return [] if resp.status_code != 200: logger.error( "Problems fetching schema:\n{0}\n{1}".format( resp.status_code, resp.reason ) ) return [] return resp.json() return []
def _set_query_debug(solr, params): try: if not get_setting( field="query_debug", interface=IRerSolrpushSettings ): return except KeyError: # key not available: do not save data return request = getRequest() annotations = IAnnotations(request) annotations["solr_query"] = { "url": "{url}/select?{params}".format( url=solr.url, params=safe_urlencode(params, True) ), "params": params, }
def reply(self): data = get_setting(field="elevate_schema", interface=IElevateSettings) return json.loads(data)
def is_right_portal_type(item): enabled_types = get_setting(field="enabled_types") if not enabled_types: return True return item.portal_type in enabled_types
def create_index_dict(item): """Restituisce un dizionario pronto per essere 'mandato' a SOLR per l'indicizzazione. """ index_fields = get_index_fields() frontend_url = get_setting(field="frontend_url") if frontend_url: frontend_url = frontend_url.rstrip("/") catalog = api.portal.get_tool(name="portal_catalog") adapter = queryMultiAdapter((item, catalog), IIndexableObject) index_me = {} for field, field_infos in index_fields.items(): if field in RESTAPI_METADATA_FIELDS: # skip. These fields are only metadata fields needed in restap-like # repsonses and can be copied in solr configuration. continue field_type = field_infos.get("type") if six.PY2: field = field.encode("ascii") value = getattr(adapter, field, None) if not value: continue if callable(value): value = value() if six.PY2: value = fix_py2_strings(value) if isinstance(value, DateTime): value = parse_date_as_datetime(value) else: if field_type == "date": value = parse_date_str(value) index_me[field] = value for field in ADDITIONAL_FIELDS: value = getattr(item, field, None) if value is not None: index_me[field] = value portal = api.portal.get() # extra-catalog schema index_me["site_name"] = get_site_title() index_me["path"] = "/".join(item.getPhysicalPath()) index_me["path_depth"] = len(item.getPhysicalPath()) - 2 index_me["attachment"] = attachment_to_index(item) index_me["getIcon"] = False if "view_name" in index_fields.keys(): index_me["view_name"] = item.getLayout() # convert url to frontend one if frontend_url: index_me["url"] = item.absolute_url().replace( portal.portal_url(), frontend_url ) else: index_me["url"] = item.absolute_url() has_image = getattr(item.aq_base, "image", None) if has_image: index_me["getIcon"] = True return index_me