def before_search(self, search_params): """ Modify the search query. """ # Set the 'qf' (queryfield) parameter to a fixed list of boosted solr fields # tuned for DGU. If a dismax query is run, then these will be the fields that are searched # within. search_params[ 'qf'] = 'title^4 name^3 notes^2 text tags^0.3 group_titles^0.3 extras_harvest_document_content^0.2' # Escape q so that you can include dashes in the search and it doesn't mean 'NOT' # e.g. "Spend over 25,000 - NHS Leeds" -> "Spend over 25,000 \- NHS Leeds" if 'q' in search_params: search_params['q'] = solr_escape(search_params['q']) # Add popularity into default ranking - this kicks when there is # no keyword, so no rank. Leave name there, in case no popularity # scores have been loaded. # NB The UI has been adjusted to match this - see # ckanext/dgu/theme/templates/package/search.html order_by = search_params.get('sort') if order_by == 'rank' or order_by is None: search_params['sort'] = 'score desc, popularity desc, name asc' return search_params
def before_search(self, search_params): """ Modify the search query. """ # Set the 'qf' (queryfield) parameter to a fixed list of boosted solr fields # tuned for DGU. If a dismax query is run, then these will be the fields that are searched # within. search_params[ 'qf'] = 'title^4 name^3 notes^2 text tags^0.3 group_titles^0.3 extras_harvest_document_content^0.2' # ignore dataset_type:dataset which CKAN2 adds in - we dont use # dataset_type and it mucks up spatial search if search_params.get('fq'): search_params['fq'] = search_params['fq'].replace( '+dataset_type:dataset', '') # Escape q so that you can include dashes in the search and it doesn't mean 'NOT' # e.g. "Spend over 25,000 - NHS Leeds" -> "Spend over 25,000 \- NHS Leeds" # You can avoid this escaping on the API by setting escape_q=False. if 'q' in search_params and search_params.get('escape_q', True): search_params['q'] = solr_escape(search_params['q']) if 'escape_q' in search_params: search_params.pop('escape_q') # If the user does not specify a "sort by" method manually, # then it defaults here (and the UI has to have the same logic) # NB The UI has to be kept in step with this logic: # ckanext/dgu/theme/templates/package/search.html order_by = search_params.get('sort') bbox = search_params.get('extras', {}).get('ext_bbox') search_params_apart_from_bbox = search_params.get( 'q', '') + search_params.get('fq', '') sort_by_location_enabled = bool(bbox and not search_params_apart_from_bbox) if order_by in (None, 'spatial desc') and sort_by_location_enabled: search_params['sort'] = 'spatial desc' # This sort parameter is picked up by ckanext-spatial elif order_by in (None, 'rank'): # Score = SOLR rank = relevancy = how well q keyword matches the # SOLR record's text content. # Add popularity into default ranking - this kicks when there is # no keyword, so no rank. Leave name there, in case no popularity # scores have been loaded. search_params['sort'] = 'score desc, popularity desc, name asc' return search_params
def before_search(self, search_params): """ Modify the search query. """ # Set the 'qf' (queryfield) parameter to a fixed list of boosted solr fields # tuned for DGU. If a dismax query is run, then these will be the fields that are searched # within. search_params[ "qf" ] = "title^4 name^3 notes^2 text tags^0.3 group_titles^0.3 extras_harvest_document_content^0.2" # ignore dataset_type:dataset which CKAN2 adds in - we dont use # dataset_type and it mucks up spatial search if search_params.get("fq"): search_params["fq"] = search_params["fq"].replace("+dataset_type:dataset", "") # Escape q so that you can include dashes in the search and it doesn't mean 'NOT' # e.g. "Spend over 25,000 - NHS Leeds" -> "Spend over 25,000 \- NHS Leeds" # You can avoid this escaping on the API by setting escape_q=False. if "q" in search_params and search_params.get("escape_q", True): search_params["q"] = solr_escape(search_params["q"]) if "escape_q" in search_params: search_params.pop("escape_q") # If the user does not specify a "sort by" method manually, # then it defaults here (and the UI has to have the same logic) # NB The UI has to be kept in step with this logic: # ckanext/dgu/theme/templates/package/search.html order_by = search_params.get("sort") bbox = search_params.get("extras", {}).get("ext_bbox") search_params_apart_from_bbox = search_params.get("q", "") + search_params.get("fq", "") sort_by_location_enabled = bool(bbox and not search_params_apart_from_bbox) if order_by in (None, "spatial desc") and sort_by_location_enabled: search_params["sort"] = "spatial desc" # This sort parameter is picked up by ckanext-spatial elif order_by in (None, "rank"): # Score = SOLR rank = relevancy = how well q keyword matches the # SOLR record's text content. # Add popularity into default ranking - this kicks when there is # no keyword, so no rank. Leave name there, in case no popularity # scores have been loaded. search_params["sort"] = "score desc, popularity desc, name asc" return search_params
def before_search(self, search_params): """ Modify the search query. """ from paste.deploy.converters import asbool # Set the 'qf' (queryfield) parameter to a fixed list of boosted solr fields # tuned for DGU. If a dismax query is run, then these will be the fields that are searched # within. search_params['qf'] = 'title^4 name^3 notes^2 text tags^0.3 group_titles^0.3 extras_harvest_document_content^0.2' # Escape q so that you can include dashes in the search and it doesn't mean 'NOT' # e.g. "Spend over 25,000 - NHS Leeds" -> "Spend over 25,000 \- NHS Leeds" # You can avoid this escaping on the API by setting escape_q=False. if 'q' in search_params and search_params.get('escape_q', True): search_params['q'] = solr_escape(search_params['q']) if 'escape_q' in search_params: search_params.pop('escape_q') # If the user does not specify a "sort by" method manually, # then it defaults here (and the UI has to have the same logic) # NB The UI has to be kept in step with this logic: # ckanext/dgu/theme/templates/package/search.html order_by = search_params.get('sort') bbox = search_params.get('extras', {}).get('ext_bbox') search_params_apart_from_bbox = search_params.get('q', '') + search_params.get('fq', '') sort_by_location_enabled = bool(bbox and not search_params_apart_from_bbox) if order_by in (None, 'spatial desc') and sort_by_location_enabled: search_params['sort'] = 'spatial desc' # This sort parameter is picked up by ckanext-spatial elif order_by in (None, 'rank'): # Score = SOLR rank = relevancy = how well q keyword matches the # SOLR record's text content. # Add popularity into default ranking - this kicks when there is # no keyword, so no rank. Leave name there, in case no popularity # scores have been loaded. search_params['sort'] = 'score desc, popularity desc, name asc' return search_params
def before_search(self, search_params): """ Modify the search query. """ # Set the 'qf' (queryfield) parameter to a fixed list of boosted solr fields # tuned for DGU. If a dismax query is run, then these will be the fields that are searched # within. search_params['qf'] = 'title^4 name^3 notes^2 text tags^0.3 group_titles^0.3 extras_harvest_document_content^0.2' # Escape q so that you can include dashes in the search and it doesn't mean 'NOT' # e.g. "Spend over 25,000 - NHS Leeds" -> "Spend over 25,000 \- NHS Leeds" if 'q' in search_params: search_params['q'] = solr_escape(search_params['q']) # Add popularity into default ranking - this kicks when there is # no keyword, so no rank. Leave name there, in case no popularity # scores have been loaded. # NB The UI has been adjusted to match this - see # ckanext/dgu/theme/templates/package/search.html order_by = search_params.get('sort') if order_by == 'rank' or order_by is None: search_params['sort'] = 'score desc, popularity desc, name asc' return search_params