Filters the items in this tree based on the inputed keywords.
        
        :param      terms           | {<str> dataType: [<str> term, ..], ..}
                    caseSensitive   | <bool>
        
        :return     <bool> | found
778973
def __filterItems(self, 
                      terms, 
                      caseSensitive=False):
        
        found = False
        items = []
        
        # collect the items to process
        for i in range(self.count()):
            items.append(self.item(i))
        
        for item in items:
            if not isinstance(item, XListWidgetItem):
                continue
            
            # if there is no filter keywords, then all items will be visible
            if not any(terms.values()):
                found = True
                item.setHidden(False)
            
            else:
                # match all generic keywords
                generic         = terms.get('*', [])
                generic_found   = dict((key, False) for key in generic)
                
                # match all specific keywords
                dtype_found  = dict((col, False) for col in terms if col != '*')
                
                # look for any matches for any data type
                mfound = False
                
                for dataType in self._filteredDataTypes:
                    # determine the check text based on case sensitivity
                    if caseSensitive:
                        check = nativestring(item.filterData(dataType))
                    else:
                        check = nativestring(item.filterData(dataType)).lower()
                    
                    specific = terms.get(dataType, [])
                    
                    # make sure all the keywords match
                    for key in generic + specific:
                        if not key:
                            continue
                        
                        # look for exact keywords
                        elif key.startswith('"') and key.endswith('"'):
                            if key.strip('"') == check:
                                if key in generic:
                                    generic_found[key] = True
                                
                                if key in specific:
                                    dtype_found[dataType] = True
                        
                        # look for ending keywords
                        elif key.startswith('*') and not key.endswith('*'):
                            if check.endswith(key.strip('*')):
                                if key in generic:
                                    generic_found[key] = True
                                if key in specific:
                                    dtype_found[dataType] = True
                        
                        # look for starting keywords
                        elif key.endswith('*') and not key.startswith('*'):
                            if check.startswith(key.strip('*')):
                                if key in generic:
                                    generic_found[key] = True
                                if key in specific:
                                    dtype_found[dataType] = True
                        
                        # look for generic keywords
                        elif key.strip('*') in check:
                            if key in generic:
                                generic_found[key] = True
                            if key in specific:
                                dtype_found[dataType] = True
                    
                    mfound = all(dtype_found.values()) and \
                             all(generic_found.values())
                    if mfound:
                        break
                
                item.setHidden(not mfound)
                
                if mfound:
                    found = True
        
        return found
298649
def quick_search(self, terms):
        ''''''
        assert type(terms) is str
        p = [{'quicksearch': terms}]
        return self.search_bugs(p)
219492
def _has_terms(self):
        
        loc = self._super_get('_term_location')
        return self._super_has(loc) \
               and isiterable(self._super_get(loc)) \
               and len(self._super_get(loc)) > 0 \
               and all([isinstance(term, Term) for term in self._super_get(loc)])
1282595
def filter(self, *condition):
        
        if not condition:
            return self
        cond = true()
        for c in condition:
            if c is not None:
                if isinstance(c, (str, unicode)):
                    c = text(c)
                cond = and_(c, cond)
        if self.condition is not None:
            self.condition = and_(cond, self.condition)
        else:
            self.condition = cond
        return self
686849
def classify(self, term, **kwargs):
        
        term = self._normalize(term)
        if dict.__contains__(self, term):
            return self[term][0].keys()[-1]
        # If the term is not in the dictionary, check the classifiers.
        # Returns the first term in the list returned by a classifier.
        for classifier in self.classifiers:
            # **kwargs are useful if the classifier requests extra information,
            # for example the part-of-speech tag.
            v = classifier.parents(term, **kwargs)
            if v:
                return v[0]
548098
def do_list(lookup, term):
    """"""

    space = lookup.keys()
    matches = fnmatch.filter(space, term)

    return [(m, translate(lookup, m)) for m in matches]
1016005
def filtered_search(self,
               id_list: Iterable,
               negated_classes: Iterable,
               limit: Optional[int],
               taxon_filter: Optional,
               category_filter: Optional,
               method: Optional) -> SimResult:
        
        pass
639371
def data_filter(data, filters)
      filters.split(',').each do |filter|
        field = filter.split(':').first.strip.downcase
        search = filter.split(':').last.strip
        if search =~ /^\/.*\/?/
          data = data.find_all { |k| k["#{field}"].to_s =~ search.to_regexp } if field && search
        else
          data = data.find_all { |k| k["#{field}"].to_s == "#{search}" } if field && search
        end
      end
      data
    end
17172
def _query_from_term(self, term, field_name, filter_type, is_not):
        
        if field_name != 'content' and field_name not in self.backend.column:
            raise InvalidIndexError('field "%s" not indexed' % field_name)

        # It it is an AutoQuery, it has no filters
        # or others, thus we short-circuit the procedure.
        if isinstance(term, AutoQuery):
            if field_name != 'content':
                query = '%s:%s' % (field_name, term.prepare(self))
            else:
                query = term.prepare(self)
            return [self.backend.parse_query(query)]
        query_list = []

        # Handle `ValuesListQuerySet`.
        if hasattr(term, 'values_list'):
            term = list(term)

        if field_name == 'content':
            # content is the generic search:
            # force no field_name search
            # and the field_type to be 'text'.
            field_name = None
            field_type = 'text'

            # we don't know what is the type(term), so we parse it.
            # Ideally this would not be required, but
            # some filters currently depend on the term to make decisions.
            term = _to_xapian_term(term)

            query_list.append(self._filter_contains(term, field_name, field_type, is_not))
            # when filter has no filter_type, haystack uses
            # filter_type = 'content'. Here we remove it
            # since the above query is already doing this
            if filter_type == 'content':
                filter_type = None
        else:
            # get the field_type from the backend
            field_type = self.backend.schema[self.backend.column[field_name]]['type']

        # private fields don't accept 'contains' or 'startswith'
        # since they have no meaning.
        if filter_type in ('contains', 'startswith') and field_name in (ID, DJANGO_ID, DJANGO_CT):
            filter_type = 'exact'

        if field_type == 'text':
            # we don't know what type "term" is, but we know we are searching as text
            # so we parse it like that.
            # Ideally this would not be required since _term_query does it, but
            # some filters currently depend on the term to make decisions.
            if isinstance(term, list):
                term = [_to_xapian_term(term) for term in term]
            else:
                term = _to_xapian_term(term)

        # todo: we should check that the filter is valid for this field_type or raise InvalidIndexError
        if filter_type == 'contains':
            query_list.append(self._filter_contains(term, field_name, field_type, is_not))
        elif filter_type in ('content', 'exact'):
            query_list.append(self._filter_exact(term, field_name, field_type, is_not))
        elif filter_type == 'in':
            query_list.append(self._filter_in(term, field_name, field_type, is_not))
        elif filter_type == 'startswith':
            query_list.append(self._filter_startswith(term, field_name, field_type, is_not))
        elif filter_type == 'endswith':
            raise NotImplementedError("The Xapian search backend doesn't support endswith queries.")
        elif filter_type == 'gt':
            query_list.append(self._filter_gt(term, field_name, field_type, is_not))
        elif filter_type == 'gte':
            query_list.append(self._filter_gte(term, field_name, field_type, is_not))
        elif filter_type == 'lt':
            query_list.append(self._filter_lt(term, field_name, field_type, is_not))
        elif filter_type == 'lte':
            query_list.append(self._filter_lte(term, field_name, field_type, is_not))
        elif filter_type == 'range':
            query_list.append(self._filter_range(term, field_name, field_type, is_not))
        return query_list
977659
def _make_query_from_terms(self, terms):
        

        expanded_terms = self._expand_terms(terms)

        cterms = ''
        if expanded_terms['doc']:
            cterms = self.backend._or_join(expanded_terms['doc'])

        keywords = expanded_terms['keywords']

        frm_to = self._from_to_as_term(expanded_terms['from'], expanded_terms['to'])

        if frm_to:
            keywords.append(frm_to)

        if keywords:
            if cterms:
                cterms = self.backend._and_join(
                    [cterms, self.backend._field_term('keywords', expanded_terms['keywords'])])
            else:
                cterms = self.backend._field_term('keywords', expanded_terms['keywords'])

        logger.debug('partition terms conversion: `{}` terms converted to `{}` query.'.format(terms, cterms))

        return cterms
688213
def simple_types_filter(data):
    '''
    
    '''
    if data is None:
        return data

    simpletypes_keys = (six.string_types, six.text_type, six.integer_types, float, bool)
    simpletypes_values = tuple(list(simpletypes_keys) + [list, tuple])

    if isinstance(data, (list, tuple)):
        simplearray = []
        for value in data:
            if value is not None:
                if isinstance(value, (dict, list)):
                    value = simple_types_filter(value)
                elif not isinstance(value, simpletypes_values):
                    value = repr(value)
            simplearray.append(value)
        return simplearray

    if isinstance(data, dict):
        simpledict = {}
        for key, value in six.iteritems(data):
            if key is not None and not isinstance(key, simpletypes_keys):
                key = repr(key)
            if value is not None and isinstance(value, (dict, list, tuple)):
                value = simple_types_filter(value)
            elif value is not None and not isinstance(value, simpletypes_values):
                value = repr(value)
            simpledict[key] = value
        return simpledict

    return data
1203636
def _filter_contains(self, term, field_name, field_type, is_not):
        
        if field_type == 'text':
            term_list = term.split()
        else:
            term_list = [term]

        query = self._or_query(term_list, field_name, field_type)
        if is_not:
            return xapian.Query(xapian.Query.OP_AND_NOT, self._all_query(), query)
        else:
            return query
229454
def find(self, search_term: str) -> List[Commodity]:
        
        query = (
            self.query
            .filter(Commodity.mnemonic.like('%' + search_term + '%') |
                    Commodity.fullname.like('%' + search_term + '%'))
        )
        return query.all()
1111331
def filter_from_query(query, id_field="id", field_map={}):
    
    f = groups_filter_from_query(query, field_map=field_map)
    excluded_ids = query.get("excluded_ids")
    included_ids = query.get("included_ids")

    if included_ids:  # include these, please
        if f is None:
            f = Terms(pk=included_ids)
        else:
            f |= Terms(pk=included_ids)

    if excluded_ids:  # exclude these
        if f is None:
            f = MatchAll()

        f &= ~Terms(pk=excluded_ids)
    return f
1086307
def _filter_by_pattern(self, pattern):
        """"""
        try:
            _len = len(pattern)
        except TypeError:
            raise TypeError("pattern is not a list of Booleans. Got {}".format(
                type(pattern)))
        _filt_values = [d for i, d in enumerate(self._values) if pattern[i % _len]]
        _filt_datetimes = [d for i, d in enumerate(self.datetimes) if pattern[i % _len]]
        return _filt_values, _filt_datetimes
1113071
def search(context, keywords, module, raw, kind):
    
    logging.info(_('Entering search mode'))
    sense = context.obj['sense']
    func = sense.query_names if module else sense.query_info
    none = True
    for keyword in keywords:
        output = func(keyword, raw, kind)
        if output:
            none = False
            print(output)
        else:
            logging.warning(_('No results: %s'), keyword)
    sys.exit(1 if none else 0)
379869
def filter(self, key_pattern='*', is_regex=False):
        
        if is_regex:
            if isinstance(key_pattern, str):
                regex = re.compile(key_pattern)
            else:
                regex = key_pattern
        else:
            regex = None
        for k, v in self.items():
            if regex and regex.match(k) or (not regex) and fnmatch(k, key_pattern):
                yield k, v