Sha256: 16f293c6aeefceb6b301726a994cf5f4648b36c29584aace8dc2fcb962dc4af9

Contents?: true

Size: 1.66 KB

Versions: 10

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] == ::AdvancedController.blacklight_config.advanced_search[:url_key]
        
        config.search_fields.each do | key, field_def |
          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

10 entries across 10 versions & 1 rubygems

Version Path
blacklight_advanced_search-2.2.0 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-2.1.1 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-2.1.0 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-2.1.0.rc1 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-2.0.0 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.2.4 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.2.3 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.2.2 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.2.1 lib/blacklight_advanced_search/advanced_query_parser.rb
blacklight_advanced_search-1.2.0 lib/blacklight_advanced_search/advanced_query_parser.rb