Filter resources in the collection based on a Query

 @param [Query] query
   the query to match each resource in the collection

 @return [Array]
   the resources that match the Query
 @return [nil]
   nil if no resources match the Query

 @api private
484215
def filter(other_query)
      query  = self.query
      fields = query.fields.to_set
      unique = other_query.unique?

      # TODO: push this into a Query#subset? method
      if other_query.links.empty?                 &&
        (unique || (!unique && !query.unique?))   &&
        !other_query.reload?                      &&
        !other_query.raw?                         &&
        other_query.fields.to_set.subset?(fields) &&
        other_query.condition_properties.subset?(fields)
      then
        other_query.filter_records(to_a.dup)
      end
    end
1087648
def parse(query)
      @symbols = Tokenizer.symbols(query)
      @position = 0
      r = []
      r << read_maximal_term(0) until empty?
      r
    end
1210454
function filterQuery(query = {}, ...keys) {
  const out = {};
  keys.forEach((key) => {
    if (query[key] !== undefined && query[key] !== null) {
      out[key] = query[key];
    }
  });
  return out;
}
513018
def get(path: nil, headers: {}, query: {})
      execute(method: :get, path: path, query: query, headers: headers)
    end
410212
def find(self, query):
        ''''''
        if self.upstream:
            return self.upstream.find(query)
        else:
            return False
424176
def where(filter)
      if filter.is_a?(String) # we got a Sparql snippet
        where_clauses << filter
      elsif filter.is_a?(Hash)
        filter.each_pair do |key, value|
          field = resource_class.get_field(key)
          value = RDF::Literal.new(value) unless value.respond_to?(:to_base)
          where_clauses << "?uri <#{ field.predicate }> #{ value.to_base }"
        end
      end
      self
    end
1362589
def filter(self, *query_filter):
        '''
        '''
        for query in query_filter:
            self.query.append(query)
        return self
226455
def get_all_items(query = {})
      response = self.get('items', nil, query).body
      parsed = JSON.parse(response)
      all_items = []
      parsed.each do |item_hash|
        all_items.push OmekaClient::OmekaItem.new(self, item_hash)
      end
      return all_items
    end
1164550
def matches? query
      query.reduce(true) do |matches, (key, value)|
        matches = if key == 'tag'
          return false unless tags.present?
          tags.include? value
        else
          attributes[key] == value
        end
      end
    end
833724
def run_query(self, query):
        
        collection = self.ds.connection(self.collection_name)

        cursor = collection.find(query)
        if cursor.count() == 0:
            raise LookupError('Collection {0} has no {1} records'
                              .format(self.collection_name, self.model_klass.__name__))
        return [self.model_klass.from_json(entry) for entry in cursor]
1242837
def search(query)
      get('/v1/search'.freeze, { q: query })
    rescue => e
      logger.warn "API v1 - Search failed #{e.backtrace}"
      { 'results' => catalog(query) }
    end
960590
public static Filter[][] filters(Query query) {
        List<List<Filter>> paths = new ArrayList<>();
        List<Filter[]> workingPath = new ArrayList<>();

        addPathsToLeaves(query, workingPath, paths);

        Filter[][] ret = new Filter[paths.size()][];
        Arrays.setAll(ret, (i) -> paths.get(i).toArray(new Filter[paths.get(i).size()]));
        return ret;
    }
5418
def parse_query(query=nil, options={})
      valid_options = [:models, :lazy, :core, :results_format, :sql_options,
        :alternate_query, :boost_functions, :filter_queries, :facets, :sort,
        :scores, :operator, :latitude, :longitude, :radius, :relevance, :highlight,
        :offset, :per_page, :limit, :page,]
      query_options = {}

      return if query.nil?
      raise "Query should be a string" unless query.is_a?(String)
      raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty?
      begin
        Deprecation.validate_query(options)

        query_options[:filter_queries] = []
        query.strip!

        # using *:* disable index boosts, so use the type filter
        if query.blank?
          query = solr_type_condition(options)
        else
          query = sanitize_query(query)
          query_options[:filter_queries] << solr_type_condition(options)

          # put types on filtered fields
          query = replace_types([*query], ':').first
        end

        query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries]

        options[:alternate_query] ||= ''
        options[:alternate_query].strip!
        query = "#{options[:alternate_query]} #{query}" unless options[:alternate_query].blank?

        query = add_relevance query, options[:relevance]

        query_options[:query] = query

        field_list = options[:models].nil? ? solr_configuration[:primary_key_field] : "id"
        query_options[:field_list] = [field_list, 'score']

        per_page = options[:per_page] || options[:limit] || 30
        offset = options[:offset] || (((options[:page] || 1).to_i - 1) * per_page)
        query_options[:rows] = per_page
        query_options[:start] = offset

        query_options[:operator] = options[:operator]

        query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions]

        # first steps on the facet parameter processing
        if options[:facets]
          query_options[:facets] = {}
          query_options[:facets][:limit] = -1  # TODO: make this configurable
          query_options[:facets][:sort] = :count if options[:facets][:sort]
          query_options[:facets][:mincount] = 0
          query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false
          # override the :zeros (it's deprecated anyway) if :mincount exists
          query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount]
          query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields]
          query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse]
          query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query]

          if options[:facets][:dates]
            query_options[:date_facets] = {}
            # if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there
            if options[:facets][:dates][:fields]
              [:start, :end, :gap].each { |k| raise "#{k} must be present in faceted date query" unless options[:facets][:dates].include?(k) }
              query_options[:date_facets][:fields] = []
              options[:facets][:dates][:fields].each { |f|
                if f.kind_of? Hash
                  key = f.keys[0]
                  query_options[:date_facets][:fields] << {"#{key}_d" => f[key]}
                  validate_date_facet_other_options(f[key][:other]) if f[key][:other]
                else
                  query_options[:date_facets][:fields] << "#{f}_d"
                end
              }
            end

            query_options[:date_facets][:start]   = options[:facets][:dates][:start] if options[:facets][:dates][:start]
            query_options[:date_facets][:end]     = options[:facets][:dates][:end] if options[:facets][:dates][:end]
            query_options[:date_facets][:gap]     = options[:facets][:dates][:gap] if options[:facets][:dates][:gap]
            query_options[:date_facets][:hardend] = options[:facets][:dates][:hardend] if options[:facets][:dates][:hardend]
            query_options[:date_facets][:filter]  = replace_types([*options[:facets][:dates][:filter]].collect{|k| "#{k.dup.sub!(/ *:(?!\d) */,"_d:")}"}) if options[:facets][:dates][:filter]

            if options[:facets][:dates][:other]
              validate_date_facet_other_options(options[:facets][:dates][:other])
              query_options[:date_facets][:other] = options[:facets][:dates][:other]
            end

          end
        end

        if options[:highlight]
          query_options[:highlighting] = {}
          query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields]
          query_options[:highlighting][:require_field_match] =  options[:highlight][:require_field_match] if options[:highlight][:require_field_match]
          query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets]
          query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix]
          query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix]
        end

        query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort]

        if options[:radius]
          query_options[:radius] = options[:radius]
          query_options[:filter_queries] << '{!geofilt}'
        end
        query_options[:latitude] = options[:latitude]
        query_options[:longitude] = options[:longitude]

        not_dismax = query_options[:operator] == :or
        request = not_dismax ? Solr::Request::Standard.new(query_options) : Solr::Request::Dismax.new(query_options)
        ActsAsSolr::Post.execute(request, options[:core])
      rescue
        raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}"
      end
    end
1041833
def search(cls, query, page=1):
        
        path = '/files/search/{query}/page/{page}'.format(query=query, page=page)
        result = cls.client.request(path)
        files = result['files']
        return [cls(f) for f in files]
1080912
def filter_results(hash)
      return [] if hash.blank?
      h = []
      hash.each do |k,v|
        h << k if k.post_type != 'autosave'
      end
      h
    end
1039157
function( query, elements ){
        if( query != null ){
          var matches = false;
          elements = elements(); // make elements functional so we save cycles if query == null

          // query must match for at least one element (may be recursive)
          for(var i = 0; i < elements.size(); i++){
            if( queryMatches( query, elements.eq(i) ) ){
              matches = true;
              break;
            }
          }

          return matches;
        } else {
          return true;
        }
      }
579217
def match_states(query)
        state_requirements.detect do |state_requirement|
          [:from, :to].all? {|option| matches_requirement?(query, option, state_requirement[option])}
        end
      end