malformed_industries = [ ind for ind in parsed_industries if len(ind) not in (3, 5) ] if malformed_industries: raise ValueError( "Arguments not valid industry categories or category orders: %s" % str(malformed_industries)) orders = [order for order in parsed_industries if len(order) == 3] cats = [cat for cat in parsed_industries if len(cat) == 5] return self._add_industry_clauses(query, cats, orders) _punctuation_to_spaces = dict([(c, ' ') for c in "\"'&|!():*\\"]) _strip_postgres_ft_operators = build_map_substrings(_punctuation_to_spaces) class FulltextField(Field): def __init__(self, name, model_fields=None): super(FulltextField, self).__init__(name) self.model_fields = model_fields if model_fields else [name] def apply(self, query, *searches): ft_searches = [_format_ft_search(s) for s in searches] exact_searches = [_format_exact_search(s) for s in searches] where_clause = _search_clause(self.model_fields, [s is not None for s in exact_searches]) params = dict([('ft_term_%s' % i, ft_searches[i])
""" A collection of pre-configured normalizers. Only one demo normalizer for now. """ from dcdata.utils.strings.transformers import compose, build_map_substrings, build_remove_substrings, build_remove_suffixes basic_normalizer = compose( unicode.lower, build_map_substrings({' and ': '&'}), build_remove_substrings(" ,.\"\'@+#$(){}[]\\&-/"), build_remove_suffixes([ 'association', 'assoc', 'assn', 'incorporated', 'inc', 'company', 'co', 'corporation', 'corp', 'committee', 'cmte', 'limited', 'ltd' ]))
def apply(self, query, *industries): parsed_industries = [self._extract_cat_or_order(i) for i in industries] malformed_industries = [ind for ind in parsed_industries if len(ind) not in (3, 5)] if malformed_industries: raise ValueError("Arguments not valid industry categories or category orders: %s" % str(malformed_industries)) orders = [order for order in parsed_industries if len(order)==3] cats = [cat for cat in parsed_industries if len(cat)==5] return self._add_industry_clauses(query, cats, orders) _punctuation_to_spaces = dict([(c, ' ') for c in "\"'&|!():*\\"]) _strip_postgres_ft_operators = build_map_substrings(_punctuation_to_spaces) class FulltextField(Field): def __init__(self, name, model_fields=None): super(FulltextField, self).__init__(name) self.model_fields = model_fields if model_fields else [name] def apply(self, query, *searches): ft_searches = [_format_ft_search(s) for s in searches] exact_searches = [_format_exact_search(s) for s in searches] where_clause = _search_clause(self.model_fields, [s is not None for s in exact_searches]) params = dict([('ft_term_%s' % i, ft_searches[i]) for i in range(len(searches))]) params.update(dict([('exact_term_%s' % i, exact_searches[i]) for i in range(len(searches))]))
""" A collection of pre-configured normalizers. Only one demo normalizer for now. """ from dcdata.utils.strings.transformers import compose, build_map_substrings, build_remove_substrings, build_remove_suffixes basic_normalizer = compose(unicode.lower, build_map_substrings({' and ': '&'}), build_remove_substrings(" ,.\"\'@+#$(){}[]\\&-/"), build_remove_suffixes(['association', 'assoc', 'assn', 'incorporated', 'inc', 'company', 'co', 'corporation', 'corp', 'committee', 'cmte', 'limited', 'ltd']))