# File lib/scrubyt/core/scraping/pattern.rb, line 236
    def evaluate(source, filter_indices)
      if type == :detail_page # DIRTY!
        return @filters[0].evaluate(source)
      end

      #we apply all filters if filter_indices is nil
      indices_to_evaluate = filter_indices.nil? ? 0...@filters.size : filter_indices
      #stores the results of all filters
      all_filter_results = []
      #remembers which filters have retured a certain result
      indices_mapping = {}
      #evaluate filters and collect filter results
      indices_to_evaluate.each do |filter_index|
        filter = @filters[filter_index]
        filter_results = filter.evaluate(source)
        filter_results.each do |result|
          #add result to list if not already there
          all_filter_results << result if all_filter_results.index(result).nil?
          #add the current filter's index to the mapping
           (indices_mapping[result] ||= []) << filter_index
        end
      end

      #apply constraints
      if @constraints.size > 0
        all_filter_results = all_filter_results.select do |result|
          @constraints.inject(true) { |accepted, constraint| accepted && constraint.check(result) }
        end
      end
      #apply indexer
      all_filter_results = @result_indexer.select_indices_to_extract(all_filter_results) if !@result_indexer.nil?

      #create result nodes and evaluate children
      result_nodes = []
      all_filter_results.each do |result|
        #create result node
        node = ResultNode.new(@name, result, @options)
        node.generated_by_leaf = (@children.size == 0)
        #evaluate children
        @children.each do |child|
          raise if self.filter_count != 1 && child.filter_count != self.filter_count
          if self.filter_count == 1
            #evaluate all child filters
            node.push(*child.evaluate(result, nil))
          else
            #evaluate appropriate child filters
            node.push(*child.evaluate(result, indices_mapping[result]))
          end
        end
        #apply child constraints (ensure_presence_of_pattern)
        required_child_names = @constraints.select {|c| c.type == Scrubyt::Constraint::CONSTRAINT_TYPE_ENSURE_PRESENCE_OF_PATTERN }.map {|c| c.target}
        unless required_child_names.empty?
          check = lambda { |node_to_check|
            required_child_names.delete node_to_check.name
            node_to_check.each { |child| check.call child }
          }
          check.call node
        end
        next unless required_child_names.empty?
        #add the current result node to the list
        result_nodes << node
      end
      if result_nodes.empty?
        result_nodes << ResultNode.new(@name, @options[:default], @options) if @options[:default]
      end
      case output_type
        when :model
          return result_nodes
        when :page_list
          result_nodes.each do |result_node|
            @extractor.add_to_next_page_list result_node
          end
          return []
      end
    end