def facets(attribute, expression)
     # return an empty hash if no search expression is given
      return {} if expression.nil? || expression.strip.empty?
      value_number         = XapianDb::DocumentBlueprint.value_number_for(attribute)
      @query_parser        ||= QueryParser.new(self)
      query                = @query_parser.parse(expression)
      enquiry              = Xapian::Enquire.new(reader)
      enquiry.query        = query
      enquiry.collapse_key = value_number
      facets = {}
      enquiry.mset(0, size).matches.each do |match|
        facet_value = match.document.value(value_number)
        # We must add 1 to the collapse_count since collapse_count means
        # "how many other matches are there?"
        facets[facet_value] = match.collapse_count + 1
      end
      facets
    end
def facets(attribute, expression)
     # return an empty hash if no search expression is given
      return {} if expression.nil? || expression.strip.empty?
      value_number         = XapianDb::DocumentBlueprint.value_number_for(attribute)
      @query_parser        ||= QueryParser.new(self)
      query                = @query_parser.parse(expression)
      enquiry              = Xapian::Enquire.new(reader)
      enquiry.query        = query
      enquiry.collapse_key = value_number
      facets = {}
      enquiry.mset(0, size).matches.each do |match|
        facet_value = match.document.value(value_number)
        # We must add 1 to the collapse_count since collapse_count means
        # "how many other matches are there?"
        facets[facet_value] = match.collapse_count + 1
      end
      facets
    end
A very simple implementation of facets using Xapian collapse key.
 @param [Symbol, String] attribute the name of an attribute declared in one ore more blueprints
 @param [String] expression A valid search expression (see {#search} for examples).
 @return [Hash<Class, Integer>] A hash containing the classes and the hits per class