lib/blacklight/solr/search_builder_behavior.rb in blacklight-7.19.2 vs lib/blacklight/solr/search_builder_behavior.rb in blacklight-7.20.0

- old
+ new

@@ -8,10 +8,11 @@ :default_solr_parameters, :add_search_field_default_parameters, :add_query_to_solr, :add_facet_fq_to_solr, :add_facetting_to_solr, :add_solr_fields_to_query, :add_paging_to_solr, :add_sorting_to_solr, :add_group_config_to_solr, :add_facet_paging_to_solr, :add_adv_search_clauses, + :add_missing_field_query, :add_additional_filters ] end #### @@ -77,9 +78,22 @@ add_additional_filters(solr_parameters, search_state.query_param) end elsif search_state.query_param solr_parameters.append_query search_state.query_param end + end + + ## + # Build and append a missing field query. + ## + def add_missing_field_query(solr_parameters) + return unless solr_parameters["facet.missing"] + + solr_parameters[:fq] = [] if solr_parameters[:fq].blank? + + solr_parameters[:fq].append(*(blacklight_params["f"] || []) + .select { |f| f.match(/^-/) } + .map { |k, _v| "#{k}[* TO *]" }) end def add_additional_filters(solr_parameters, additional_filters = nil) q = additional_filters || @additional_filters