Sha256: 390994529e8897c5b7ccda987f3ac7a4dcb39071ee3028a666809bc62cb10e09

Contents?: true

Size: 1.66 KB

Versions: 9

Compression:

Stored size: 1.66 KB

Contents

module BlacklightAdvancedSearch
  class QueryParser
    include ParsingNestingParser # only one strategy currently supported. if BlacklightAdvancedSearch.config[:solr_type] == "parsing_nesting"
    include FilterParser
    attr_reader :config, :params
    
    def initialize(params,config)
      @params = HashWithIndifferentAccess.new(params)
      @config = config    
    end

    def to_solr
      @to_solr ||= begin
        {
          :q => process_query(params,config), 
          :fq => generate_solr_fq() 
        }
      end
    end
    
    # Returns "AND" or "OR", how #keyword_queries will be combined
    def keyword_op
      @params["op"] || "AND"
    end
    # returns advanced-type keyword queries, see also keyword_op
    def keyword_queries
      unless(@keyword_queries)
        @keyword_queries = {}

        return @keyword_queries unless @params[:search_field] == BlacklightAdvancedSearch.config[:url_key]
        
        @config[:search_fields].each do | field_def |
          key = field_def[:key]
          if ! @params[ key.to_sym ].blank?
            @keyword_queries[ key ] = @params[ key.to_sym ]
          end
        end
      end
      return @keyword_queries
    end
    # returns just advanced-type filters
    def filters
      unless (@filters)
        @filters = {}
        return @filters unless @params[:f_inclusive]
        @params[:f_inclusive].each_pair do |field, value_hash|
          value_hash.each_pair do |value, type|
            @filters[field] ||= []
            @filters[field] << value
          end
        end        
      end
      return @filters
    end

    def empty?
      filters.empty? && keyword_queries.empty?
    end
    
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
blacklight_advanced_search-1.1.2 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.1.1 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.1.0 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.0.0 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.0.0pre5 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.0.0pre4 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.0.0pre3 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.0.0pre2 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.0.0pre1 lib/blacklight_advanced_search/advanced_query_parser.rb