vendor/plugins/acts_as_solr/lib/parser_methods.rb
# Method used by mostly all the ClassMethods when doing a search
Method used by mostly all the ClassMethods when doing a search
Method used by mostly all the ClassMethods when doing a search
def parse_query(query=nil, options={}, models=nil)
      valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :include]
      query_options = {}
      return if query.nil?
      raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty?
      begin
        Deprecation.validate_query(options)
        query_options[:start] = options[:offset]
        query_options[:rows] = options[:limit]
        query_options[:operator] = options[:operator]
        if options[:facets]
          query_options[:facets] = {}
          query_options[:facets][:limit] = -1  
          query_options[:facets][:sort] = :count if options[:facets][:sort]
          query_options[:facets][:mincount] = 0
          query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false
          query_options[:facets][:fields] = options[:facets][:fields].collect{|k| "#{k}_facet"} if options[:facets][:fields]
          query_options[:filter_queries] = replace_types(options[:facets][:browse].collect{|k| "#{k.sub!(/ *: */,"_facet:")}"}) if options[:facets][:browse]
          query_options[:facets][:queries] = replace_types(options[:facets][:query].collect{|k| "#{k.sub!(/ *: */,"_t:")}"}) if options[:facets][:query]
        end
        if models.nil?
          models = "AND #{solr_type_condition}"
          field_list = solr_configuration[:primary_key_field]
        else
          field_list = "id"
        end
        query_options[:field_list] = [field_list, 'score']
        query = "(#{query.gsub(/ *: */,"_t:")}) #{models}"
        order = options[:order].split(/\s*,\s*/).collect{|e| e.gsub(/\s+/,'_t ').gsub(/\bscore_t\b/, 'score')  }.join(',') if options[:order] 
        query_options[:query] = replace_types([query])[0] 
        if options[:order]
          query_options[:query] << ';' << replace_types([order], false)[0]
        end
        ActsAsSolr::Post.execute(Solr::Request::Standard.new(query_options))
      rescue
        raise "There was a problem executing your search: #{$!}"
      end            
    end
def parse_query ( query = nil , options = { } , models = nil ) valid_options = [ :offset , :limit , :facets , :models , :results_format , :order , :scores , :operator , :include ] query_options = { } return if query . nil? raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless ( options . keys - valid_options ) . empty? begin Deprecation . validate_query ( options ) query_options [ :start ] = options [ :offset ] query_options [ :rows ] = options [ :limit ] query_options [ :operator ] = options [ :operator ] if options [ :facets ] query_options [ :facets ] = { } query_options [ :facets ] [ :limit ] = - 1 query_options [ :facets ] [ :sort ] = :count if options [ :facets ] [ :sort ] query_options [ :facets ] [ :mincount ] = 0 query_options [ :facets ] [ :mincount ] = 1 if options [ :facets ] [ :zeros ] == false query_options [ :facets ] [ :fields ] = options [ :facets ] [ :fields ] . collect { | k | "#{k}_facet" } if options [ :facets ] [ :fields ] query_options [ :filter_queries ] = replace_types ( options [ :facets ] [ :browse ] . collect { | k | "#{k.sub!(/ *: */,"_facet:")}" } ) if options [ :facets ] [ :browse ] query_options [ :facets ] [ :queries ] = replace_types ( options [ :facets ] [ :query ] . collect { | k | "#{k.sub!(/ *: */,"_t:")}" } ) if options [ :facets ] [ :query ] end if models . nil? models = "AND #{solr_type_condition}" field_list = solr_configuration [ :primary_key_field ] else field_list = "id" end query_options [ :field_list ] = [ field_list , 'score' ] query = "(#{query.gsub(/ *: */,"_t:")}) #{models}" order = options [ :order ] . split ( / \s *, \s * / ) . collect { | e | e . gsub ( / \s + / , '_t ' ) . gsub ( / \b score_t \b / , 'score' ) } . join ( ',' ) if options [ :order ] query_options [ :query ] = replace_types ( [ query ] ) [ 0 ] if options [ :order ] query_options [ :query ] << ';' << replace_types ( [ order ] , false ) [ 0 ] end ActsAsSolr :: Post . execute ( Solr :: Request :: Standard . new ( query_options ) ) rescue raise "There was a problem executing your search: #{$!}" end end
Method used by mostly all the ClassMethods when doing a search
Method used by mostly all the ClassMethods when doing a search
# first steps on the facet parameter processing # TODO: make this configurable # TODO: use a filter query for type, allowing Solr to cache it individually # TODO adjust replace_types to work with String or Array   # TODO: set the sort parameter instead of the old ;order. style.
query
<not_specific>
options
<not_specific>
models
<not_specific>