diff --git a/Gemfile b/Gemfile index af60b6fba..7518ec4d0 100644 --- a/Gemfile +++ b/Gemfile @@ -9,8 +9,6 @@ gem 'babel-transpiler' gem 'bcrypt_pbkdf' # Blacklight gem 'blacklight', '~> 7.38.0' -# advanced search functionality -gem 'blacklight_advanced_search', '~> 7.0' gem 'blacklight_dynamic_sitemap' gem 'blacklight-marc', '~>8.1' # slider limit support diff --git a/Gemfile.lock b/Gemfile.lock index a34e567e3..04dc9defa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,9 +145,6 @@ GEM marc-fastxmlwriter rails traject (~> 3.0) - blacklight_advanced_search (7.0.0) - blacklight (~> 7.0) - parslet blacklight_dynamic_sitemap (1.0.0) blacklight (> 7.0) rails @@ -414,7 +411,6 @@ GEM parser (3.3.4.2) ast (~> 2.4.1) racc - parslet (2.0.0) pg (1.5.7) popper_js (1.16.1) pry (0.14.2) @@ -706,7 +702,6 @@ DEPENDENCIES bixby (~> 5.0) blacklight (~> 7.38.0) blacklight-marc (~> 8.1) - blacklight_advanced_search (~> 7.0) blacklight_dynamic_sitemap blacklight_range_limit (~> 8.2) bootstrap (~> 4.6) diff --git a/app/components/location_code_facet_component.rb b/app/components/location_code_facet_component.rb index 09de2e1c3..4796c7a51 100644 --- a/app/components/location_code_facet_component.rb +++ b/app/components/location_code_facet_component.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class LocationCodeFacetComponent < ViewComponent::Base - include BlacklightAdvancedSearch::AdvancedHelperBehavior include Blacklight::FacetsHelperBehavior include ApplicationHelper diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 54b5550c2..e26dd8631 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: false class CatalogController < ApplicationController - include BlacklightAdvancedSearch::Controller include Blacklight::Catalog include Blacklight::Marc::Catalog @@ -674,11 +673,7 @@ class CatalogController < ApplicationController config.add_results_document_tool(:bookmark, partial: 'bookmark_control') config.filter_search_state_fields = true - config.search_state_fields = config.search_state_fields + [ - :advanced_type, :f1, :f2, :f3, - :op1, :op2, :op3, - :q1, :q2, :q3 - ] + config.search_state_fields = config.search_state_fields + [:advanced_type, :clause] config.index.constraints_component = Orangelight::ConstraintsComponent @@ -705,7 +700,7 @@ def index def numismatics unless request.method == :post @response = search_service.search_results do |search_builder| - search_builder.except(:add_advanced_search_to_solr).append(:facets_for_advanced_search_form) + search_builder end.first end respond_to do |format| diff --git a/app/helpers/advanced_helper.rb b/app/helpers/advanced_helper.rb index d96b43610..1e040a91f 100644 --- a/app/helpers/advanced_helper.rb +++ b/app/helpers/advanced_helper.rb @@ -2,8 +2,6 @@ # Helper methods for the advanced search form module AdvancedHelper - include BlacklightAdvancedSearch::AdvancedHelperBehavior - # Fill in default from existing search, if present # -- if you are using same search fields for basic # search and advanced, will even fill in properly if existing @@ -85,127 +83,3 @@ def first_search_field?(key) [:q1, :clause_0_query].include? key end end - -module BlacklightAdvancedSearch - class QueryParser - include AdvancedHelper - def keyword_op - # for guided search add the operations if there are queries to join - # NOTs get added to the query. Only AND/OR are operations - @keyword_op = [] - unless @params[:q1].blank? || @params[:q2].blank? || @params[:op2] == 'NOT' - @keyword_op << @params[:op2] if @params[:f1] != @params[:f2] - end - unless @params[:q3].blank? || @params[:op3] == 'NOT' || (@params[:q1].blank? && @params[:q2].blank?) - @keyword_op << @params[:op3] unless [@params[:f1], @params[:f2]].include?(@params[:f3]) && ((@params[:f1] == @params[:f3] && @params[:q1].present?) || (@params[:f2] == @params[:f3] && @params[:q2].present?)) - end - @keyword_op - end - - def keyword_queries - unless @keyword_queries - @keyword_queries = {} - - return @keyword_queries unless @params[:search_field] == ::AdvancedController.blacklight_config.advanced_search[:url_key] - - # Spaces need to be stripped from the query because they don't get properly stripped in Solr - q1 = %w[left_anchor in_series].include?(@params[:f1]) ? prep_left_anchor_search(@params[:q1]) : odd_quotes(@params[:q1]) - q2 = @params[:f2] == 'left_anchor' ? prep_left_anchor_search(@params[:q2]) : odd_quotes(@params[:q2]) - q3 = @params[:f3] == 'left_anchor' ? prep_left_anchor_search(@params[:q3]) : odd_quotes(@params[:q3]) - - @been_combined = false - @keyword_queries[@params[:f1]] = q1 if @params[:q1].present? - @keyword_queries[@params[:f2]] = prepare_q2(q2) if @params[:q2].present? - @keyword_queries[@params[:f3]] = prepare_q3(q3) if @params[:q3].present? - end - @keyword_queries - end - - private - - # Remove stray quotation mark if there are an odd number of them - # @param query [String] the query - # @return [String] the query with an even number of quotation marks - def odd_quotes(query) - if query&.count('"')&.odd? - query.sub(/"/, '') - else - query - end - end - - # Escape spaces for left-anchor search fields and adds asterisk if not present - # Removes quotation marks - # @param query [String] the query within which whitespace is being escaped - # @return [String] the escaped query - def prep_left_anchor_search(query) - if query - cleaned_query = query.gsub(/(\s)/, '\\\\\\\\\1') - cleaned_query = cleaned_query.delete('"') - cleaned_query = cleaned_query.gsub(/(["\{\}\[\]\^\~\(\)])/, '\\\\\\\\\1') - if cleaned_query.end_with?('*') - cleaned_query - else - cleaned_query + '*' - end - end - end - - def prepare_q2(q2) - if @keyword_queries.key?(@params[:f2]) - @been_combined = true - "(#{@keyword_queries[@params[:f2]]}) " + @params[:op2] + " (#{q2})" - elsif @params[:op2] == 'NOT' - 'NOT ' + q2 - else - q2 - end - end - - def prepare_q3(q3) - if @keyword_queries.key?(@params[:f3]) - kq3 = @keyword_queries[@params[:f3]] - kq3 = "(#{kq3})" unless @been_combined - "#{kq3} " + @params[:op3] + " (#{q3})" - elsif @params[:op3] == 'NOT' - 'NOT ' + q3 - else - q3 - end - end - end -end - -module BlacklightAdvancedSearch - module ParsingNestingParser - # Iterates through the keyword queries and appends each operator the extracting queries - # @param [ActiveSupport::HashWithIndifferentAccess] _params - # @param [Blacklight::Configuration] config - # @return [Array] - def process_query(_params, config) - if config.advanced_search.nil? - Blacklight.logger.error "Failed to parse the advanced search, config. settings are not accessible for: #{config}" - return [] - end - - queries = [] - ops = keyword_op - keyword_queries.each do |field, query| - query_parser_config = config.advanced_search[:query_parser] - begin - parsed = ParsingNesting::Tree.parse(query, query_parser_config) - rescue Parslet::ParseFailed => parse_failure - Blacklight.logger.warn "Failed to parse the query: #{query}: #{parse_failure}" - next - end - - # Test if the field is valid - next unless config.search_fields[field] - local_param = local_param_hash(field, config) - queries << parsed.to_query(local_param) - queries << ops.shift - end - queries.join(' ') - end - end -end diff --git a/app/helpers/blacklight_helper.rb b/app/helpers/blacklight_helper.rb index c8037f260..aee52891d 100644 --- a/app/helpers/blacklight_helper.rb +++ b/app/helpers/blacklight_helper.rb @@ -238,7 +238,7 @@ def lccn_resolve(lccn) # Links to correct advanced search page based on advanced_type parameter value def edit_search_link - url = BlacklightAdvancedSearch::Engine.routes.url_helpers.advanced_search_path(params.permit!.except(:controller, :action).to_h) + url = advanced_path(params.permit!.except(:controller, :action).to_h) if params[:advanced_type] == 'numismatics' url.gsub('/advanced', '/numismatics') else diff --git a/app/models/search_builder.rb b/app/models/search_builder.rb index 5f054585e..02947063a 100644 --- a/app/models/search_builder.rb +++ b/app/models/search_builder.rb @@ -3,12 +3,11 @@ class SearchBuilder < Blacklight::SearchBuilder include Blacklight::Solr::SearchBuilderBehavior include BlacklightRangeLimit::RangeLimitBuilder - include BlacklightAdvancedSearch::AdvancedSearchBuilder include BlacklightHelper default_processor_chain.unshift(:conditionally_configure_json_query_dsl) - self.default_processor_chain += %i[parslet_trick cleanup_boolean_operators add_advanced_search_to_solr + self.default_processor_chain += %i[parslet_trick cleanup_boolean_operators cjk_mm wildcard_char_strip excessive_paging_error only_home_facets prepare_left_anchor_search series_title_results pul_holdings html_facets @@ -17,7 +16,6 @@ class SearchBuilder < Blacklight::SearchBuilder # mutate the solr_parameters to remove words that are # boolean operators, but not intended as such. def cleanup_boolean_operators(solr_parameters) - return add_advanced_parse_q_to_solr(solr_parameters) if run_advanced_parse?(solr_parameters) solr_parameters[:q] = cleaned_query(solr_parameters[:q]) return solr_parameters unless using_json_query_dsl(solr_parameters) diff --git a/app/services/advanced_search_constraint.rb b/app/services/advanced_search_constraint.rb deleted file mode 100644 index 6d0831e15..000000000 --- a/app/services/advanced_search_constraint.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true -class AdvancedSearchConstraint - def matches?(_request) - Flipflop.view_components_advanced_search? - end -end diff --git a/app/services/deprecated_advanced_search_constraint.rb b/app/services/deprecated_advanced_search_constraint.rb deleted file mode 100644 index 621a05480..000000000 --- a/app/services/deprecated_advanced_search_constraint.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true -class DeprecatedAdvancedSearchConstraint - def matches?(_request) - !Flipflop.view_components_advanced_search? - end -end diff --git a/app/views/advanced/_advanced_search_facets_as_select.html.erb b/app/views/advanced/_advanced_search_facets_as_select.html.erb deleted file mode 100644 index 9f19f534d..000000000 --- a/app/views/advanced/_advanced_search_facets_as_select.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -<% facet_field_names.each do |facet_field_name| %> - <%= render partial: 'facet_as_select', locals: { facet_field_name: facet_field_name } %> -<% end %> -<%# Publication Date is a range input %> -<% pub_date = facet_configuration_for_field('pub_date_start_sort') %> -
- <%= label_tag pub_date.field.parameterize, :class => "col-sm-4 control-label advanced-facet-label" do %> - <%= pub_date.label %> - <% end %> -
- - <%= range_form_component(pub_date.field).render_range_input(:begin) %> - - <%= range_form_component(pub_date.field).render_range_input(:end) %> -
-
diff --git a/app/views/advanced/_advanced_search_submit_btns.html.erb b/app/views/advanced/_advanced_search_submit_btns.html.erb deleted file mode 100644 index 32a69fb74..000000000 --- a/app/views/advanced/_advanced_search_submit_btns.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= hidden_field_tag(:search_field, blacklight_config.advanced_search[:url_key]) %> -
- <%= submit_tag t('blacklight.advanced_search.form.search_btn_html'), :class=>'btn btn-primary advanced-search-submit', :id => "advanced-search-submit" %> -
diff --git a/app/views/advanced/_facet_as_select.html.erb b/app/views/advanced/_facet_as_select.html.erb deleted file mode 100644 index 655b99463..000000000 --- a/app/views/advanced/_facet_as_select.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% display_facet = @response.aggregations[facet_field_name] %> - <% if display_facet&.items.present? %> - <% if display_facet.name == 'advanced_location_s' %> - <%= render 'location_code_facet', display_facet: %> - <% else %> - <% query_parser = BlacklightAdvancedSearch::QueryParser.new(params, blacklight_config) %> - <%= render MultiselectComboboxComponent.new( - label: facet_field_label(display_facet.name), - dom_id: display_facet.name.parameterize, - field_name: display_facet.name, - values: display_facet.items.map do |facet_item| - { - value: facet_item.value, - label: "#{facet_item.value} (#{number_with_delimiter facet_item.hits})", - selected: query_parser.filters_include_value?(display_facet.name, facet_item.value) - } - end) %> - <% end %> - <% end %> diff --git a/app/views/advanced/_guided_search_fields.html.erb b/app/views/advanced/_guided_search_fields.html.erb deleted file mode 100644 index c222b36e9..000000000 --- a/app/views/advanced/_guided_search_fields.html.erb +++ /dev/null @@ -1,37 +0,0 @@ - -
-
- - <%= select_tag('f1', options_for_select(advanced_key_value, guided_field(:f1, 'all_fields')), :class=>"search_field") %> -
- - <%= text_field_tag "q1", label_tag_default_for(:q1), :class => 'form-control', autocorrect: "off", autocapitalize: "off", autocomplete: "off", spellcheck: "false" %> -
-
-
- - - -
-
- - <%= select_tag('f2', options_for_select(advanced_key_value, guided_field(:f2, 'author')), :class=>"search_field") %> -
- - <%= text_field_tag "q2", label_tag_default_for(:q2), :class => 'form-control', autocorrect: "off", autocapitalize: "off", autocomplete: "off", spellcheck: "false" %> -
-
-
- - - -
-
- - <%= select_tag('f3', options_for_select(advanced_key_value, guided_field(:f3, 'title')), :class=>"search_field") %> -
- - <%= text_field_tag "q3", label_tag_default_for(:q3), :class => 'form-control', autocorrect: "off", autocapitalize: "off", spellcheck: "false" %> -
-
-
diff --git a/app/views/advanced/_location_code_facet.html.erb b/app/views/advanced/_location_code_facet.html.erb deleted file mode 100644 index 5bf9eb7b2..000000000 --- a/app/views/advanced/_location_code_facet.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render LocationCodeFacetComponent.new(label: facet_field_label(display_facet.name), display_facet:, blacklight_config:, search_state:) %> diff --git a/app/views/advanced/_numismatics_advanced_search_form.html.erb b/app/views/advanced/_numismatics_advanced_search_form.html.erb deleted file mode 100644 index 4dc79d95d..000000000 --- a/app/views/advanced/_numismatics_advanced_search_form.html.erb +++ /dev/null @@ -1,62 +0,0 @@ -<%= form_tag search_catalog_path, :class => 'advanced form-horizontal', :method => :get do %> -
- <% unless (search_context_str = render(Blacklight::ConstraintsComponent.for_search_history(search_state:))).blank? %> -
-

<%= t 'blacklight.advanced_search.form.search_context' %>

- <%= search_context_str %> -
- <% end %> -
- <%= render Blacklight::HiddenSearchStateComponent.new(params: search_state.params_for_search(advanced_search_context.except(:model, :rpp, :start)).except(:f_inclusive)) %> - <%# Indicate that this a numismatics advanced search %> - <%= render Blacklight::HiddenSearchStateComponent.new(params: {'advanced_type' => 'numismatics'}) %> -
- <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'issue_object_type_s' } %> - <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'issue_denomination_s' } %> - <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'issue_metal_s' } %> - <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'issue_city_s' } %> - <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'issue_state_s' } %> - <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'issue_region_s' } %> -
-
-
- <%= render Blacklight::HiddenSearchStateComponent.new(params: search_state.params_for_search(advanced_search_context.except(:model, :rpp, :start)).except(:f_inclusive)) %> -
- <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'issue_ruler_s' } %> - <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'issue_artists_s' } %> - <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'find_place_s' } %> - <%= render partial: 'advanced/facet_as_select', locals: { facet_field_name: 'donor_s' } %> -
- <%# Publication Date is a range input %> - <% pub_date = facet_configuration_for_field('pub_date_start_sort') %> -
- <%= label_tag pub_date.field.parameterize, :class => "col-sm-4 control-label advanced-facet-label" do %> - Year - <% end %> -
- - <%= range_form_component(pub_date.field).render_range_input(:begin) %> – - - <%= range_form_component(pub_date.field).render_range_input(:end) %> -
-
-
- <%= select_tag('f1', options_for_select(advanced_key_value, guided_field(:f1, 'all_fields')), style: "display: none;", class: "search_field") %> - -
- <%= text_field_tag "q1", label_tag_default_for(:q1), - class: 'form-control', - autocorrect: "off", - autocapitalize: "off", - autocomplete: "off", - spellcheck: "false", - "aria-label": "Keyword Search" %> -
-
-
-
- -
- <%= render 'advanced/advanced_search_submit_btns' %> -
-<% end %> diff --git a/app/views/advanced/index.html.erb b/app/views/advanced/index.html.erb deleted file mode 100644 index ac2e40d9f..000000000 --- a/app/views/advanced/index.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -<% @page_title = "Advanced Search - #{application_name}" %> - -<%= render 'shared/start_over_row' %> - -
-

- <%= t('blacklight.advanced_search.form.title') %> - - <%= link_to t('blacklight.advanced_search.form.start_over'), '/advanced', :class =>"btn pull-right clear-form" %> -

-
-<%= render 'advanced_search_form' %> diff --git a/app/views/advanced/numismatics.html.erb b/app/views/advanced/numismatics.html.erb index d0bf9fa7e..38bf2ce2f 100644 --- a/app/views/advanced/numismatics.html.erb +++ b/app/views/advanced/numismatics.html.erb @@ -14,13 +14,9 @@ contact Alan Stahl, Curator of Numismatics (astahl@princeton.edu)

-<% if Flipflop.view_components_numismatics? %> - <%= render(NumismaticsSearchFormComponent.new( - url: search_action_url, - classes: ['advanced', 'form-horizontal'], - params: search_state.params_for_search.except(:qt), - response: @response - )) %> -<% else %> - <%= render 'advanced/numismatics_advanced_search_form' %> -<% end %> +<%= render(NumismaticsSearchFormComponent.new( + url: search_action_url, + classes: ['advanced', 'form-horizontal'], + params: search_state.params_for_search.except(:qt), + response: @response + )) %> diff --git a/app/views/blacklight_advanced_search/_facet_limit.html.erb b/app/views/blacklight_advanced_search/_facet_limit.html.erb deleted file mode 100644 index b699735f0..000000000 --- a/app/views/blacklight_advanced_search/_facet_limit.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<% # Override facet limit partial to use facet_field.key instread of solr_field -%> -
-
-
Any of:
-
    - <% advanced_query.filters[facet_field.key].each do |value| %> -
  • - <%= h(value) %> - <%= link_to(remove_advanced_facet_param(facet_field.key, value, params), :class => "remove") do %> - [remove] - <% end %> -
  • - <% end %> -
-
- <%= render_facet_limit display_facet, :layout => nil, :partial => advanced_search_facet_partial_name(display_facet) %> -
diff --git a/config/features.rb b/config/features.rb index a7469425b..bdee32073 100644 --- a/config/features.rb +++ b/config/features.rb @@ -30,12 +30,6 @@ group :blacklight_8 do feature :json_query_dsl, description: "When on / true, use the JSON query DSL for search fields in the advanced search. When off / false, use query params" - - feature :view_components_numismatics, - description: "When on / true, use the built-in advanced search form for numismatics. When off / false, use the traditional one" - - feature :view_components_advanced_search, - description: "When on / true, use the built-in advanced search form. When off / false, use the traditional one" end group :search_and_race do diff --git a/config/routes.rb b/config/routes.rb index 559f64896..7b6bc8e47 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,8 +55,7 @@ end end - mount BlacklightAdvancedSearch::Engine => '/', constraints: DeprecatedAdvancedSearchConstraint.new - get '/advanced', to: 'catalog#advanced_search', constraints: AdvancedSearchConstraint.new + get '/advanced', to: 'catalog#advanced_search' get '/numismatics', to: 'catalog#numismatics' devise_for :users, diff --git a/spec/features/advanced_searching_spec.rb b/spec/features/advanced_searching_spec.rb index 018017119..3c74896ca 100644 --- a/spec/features/advanced_searching_spec.rb +++ b/spec/features/advanced_searching_spec.rb @@ -5,6 +5,7 @@ describe 'advanced searching', advanced_search: true do before do stub_holding_locations + allow(Flipflop).to receive(:json_query_dsl?).and_return(true) end it 'does not have a basic search bar' do @@ -60,24 +61,18 @@ expect(page).to have_content('Aomen') end - context 'with the old advanced search form' do - before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(false) - allow(Flipflop).to receive(:json_query_dsl?).and_return(false) - visit '/advanced' - end - it 'can exclude terms from the search' do - # defaults to keyword - fill_in(id: 'q1', with: 'gay') - choose(id: 'op3_NOT') - # defaults to title - fill_in(id: 'q3', with: 'RenoOut') - click_button('advanced-search-submit') - expect(page.find(".page_entries").text).to eq('1 entry found') - expect(page).to have_content('Seeking sanctuary') - expect(page).to have_content('Title NOT RenoOut') - expect(page).not_to have_content('Reno Gay Press and Promotions') - end + it 'can exclude terms from the search' do + visit '/advanced' + # defaults to keyword + fill_in(id: 'clause_0_query', with: 'gay') + choose(id: 'clause_2_op_must_not') + # defaults to title + fill_in(id: 'clause_2_query', with: 'RenoOut') + click_button('advanced-search-submit') + expect(page.find(".page_entries").text).to eq('1 entry found') + expect(page).to have_content('Seeking sanctuary') + expect(page).to have_content('Title NOT RenoOut') + expect(page).not_to have_content('Reno Gay Press and Promotions') end context 'when editing the search', js: true do @@ -95,7 +90,6 @@ context 'with the built-in advanced search form' do before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true) allow(Flipflop).to receive(:json_query_dsl?).and_return(true) visit '/advanced' end diff --git a/spec/features/more_in_this_series_spec.rb b/spec/features/more_in_this_series_spec.rb index 2f7a365e3..dd94d3cfe 100644 --- a/spec/features/more_in_this_series_spec.rb +++ b/spec/features/more_in_this_series_spec.rb @@ -6,25 +6,8 @@ before do stub_holding_locations end - context 'with the BlacklightAdvancedSearch gem' do - before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(false) - allow(Flipflop).to receive(:json_query_dsl?).and_return(false) - end - - it 'does not appear for 490 series titles' do - visit '/catalog/9955253113506421' - expect(page.all('a.more-in-series').length).to eq 0 - end - it 'link to search for 8xx series titles' do - visit '/catalog/9946871913506421' - expect(page.all('a.more-in-series').length).to eq 2 - all('a.more-in-series').first.click - expect(page.body).to include('/catalog/9946871913506421') - end - end - context 'without the BlacklightAdvancedSearch gem' do + context 'with the built-in advanced search' do let(:search_builder_without_gem) do SearchBuilder.default_processor_chain - [:add_advanced_search_to_solr] end @@ -32,7 +15,6 @@ search_builder_without_gem stub_holding_locations allow(SearchBuilder).to receive(:default_processor_chain).and_return(search_builder_without_gem) - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true) allow(Flipflop).to receive(:json_query_dsl?).and_return(true) end diff --git a/spec/helpers/blacklight_advanced_search/parsing_nesting_spec.rb b/spec/helpers/blacklight_advanced_search/parsing_nesting_spec.rb deleted file mode 100644 index 07a19953b..000000000 --- a/spec/helpers/blacklight_advanced_search/parsing_nesting_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe BlacklightAdvancedSearch::ParsingNestingParser do - describe '#process_query' do - subject(:queries) { process_query(_params, config) } - - let(:_params) { instance_double(ActiveSupport::HashWithIndifferentAccess) } - let(:config) { Class.new } - let(:advanced_search) { instance_double(Blacklight::OpenStructWithHashAccess) } - let(:keyword_queries) do - { - 'title' => 'anything', - 'all_fields' => '(something) OR (anything)' - } - end - - before do - allow(config).to receive(:advanced_search).and_return(advanced_search) - allow(config).to receive(:search_fields).and_return(keyword_queries) - allow(self).to receive(:local_param_hash).with('all_fields', config).and_return({}) - allow(self).to receive(:local_param_hash).with('title', config).and_return("spellcheck.dictionary": 'title', qf: '$title_qf', pf: '$title_pf') - allow(self).to receive(:keyword_op).and_return([]) - allow(self).to receive(:keyword_queries).and_return(keyword_queries) - end - - it 'appends the operators to the queries' do - allow(advanced_search).to receive(:[]).with(:query_parser).and_return('edismax') - expect(queries).to include('_query_:"{!edismax spellcheck.dictionary=title qf=$title_qf pf=$title_pf}anything" _query_:"{!dismax mm=1}something anything"') - end - - context 'when the query parser is not specified in the advanced search' do - let(:advanced_search) { nil } - - before do - allow(Blacklight.logger).to receive(:error) - end - - it 'logs an error and returns an empty query' do - expect(queries).to be_empty - expect(Blacklight.logger).to have_received(:error).with(/Failed to parse the advanced search, config\. settings are not accessible for\:/) - end - end - - context 'there are invalid keyword queries' do - let(:keyword_queries) do - { - 'title' => '(Yu pu za shuo) AND ("")', - 'all_fields' => '(something) OR (anything)' - } - end - - before do - allow(Rails.logger).to receive(:warn) - end - - it 'parses only the valid queries and logs a warning' do - allow(advanced_search).to receive(:[]).with(:query_parser).and_return('edismax') - expect(queries).to eq '_query_:"{!dismax mm=1}something anything" ' - expect(Rails.logger).to have_received(:warn).with('Failed to parse the query: (Yu pu za shuo) AND (""): Extra input after last repetition at line 1 char 21.') - end - end - end -end diff --git a/spec/helpers/blacklight_advanced_search/query_parser_spec.rb b/spec/helpers/blacklight_advanced_search/query_parser_spec.rb deleted file mode 100644 index 5385a8b90..000000000 --- a/spec/helpers/blacklight_advanced_search/query_parser_spec.rb +++ /dev/null @@ -1,72 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe BlacklightAdvancedSearch::QueryParser do - describe '#keyword_queries' do - subject(:query_parser) { described_class.new(params, config) } - - let(:blacklight_config) { Blacklight::Configuration.new } - let(:params) do - { - 'utf8' => '✓', - 'f1' => 'title', - 'q1' => 'Yu pu za shuo', - 'op2' => 'AND', - 'f2' => 'title', - 'q2' => '""', - 'op3' => 'AND', - 'f3' => 'title', - 'q3' => '', - 'range' => { - 'pub_date_start_sort' => { - 'begin' => '', - 'end' => '' - } - }, - 'sort' => 'score desc, pub_date_start_sort desc, title_sort asc', - 'search_field' => 'advanced', - 'commit' => 'Search', - 'controller' => 'errors', - 'action' => 'error' - } - end - - it 'generates the keyword queries' do - expect(query_parser.keyword_queries).to be_a Hash - expect(query_parser.keyword_queries).to include('title' => '(Yu pu za shuo) AND ("")') - end - - describe '#keyword query with NOT' do - let(:params) do - { - 'utf8' => '✓', - 'f1' => 'title', - 'q1' => 'Yu pu za shuo', - 'op2' => 'NOT', - 'f2' => 'title', - 'q2' => '""', - 'op3' => 'NOT', - 'f3' => 'title', - 'q3' => '', - 'range' => { - 'pub_date_start_sort' => { - 'begin' => '', - 'end' => '' - } - }, - 'sort' => 'score desc, pub_date_start_sort desc, title_sort asc', - 'search_field' => 'advanced', - 'commit' => 'Search', - 'controller' => 'errors', - 'action' => 'error' - } - end - - it 'generates the keyword query with NOTs' do - expect(query_parser.keyword_queries).to be_a Hash - expect(query_parser.keyword_queries).to include('title' => '(Yu pu za shuo) NOT ("")') - end - end - end -end diff --git a/spec/models/search_builder_spec.rb b/spec/models/search_builder_spec.rb index e83e3ff17..be96eec83 100644 --- a/spec/models/search_builder_spec.rb +++ b/spec/models/search_builder_spec.rb @@ -85,10 +85,6 @@ let(:solr_parameters) do { q: 'solr AND blacklight' } end - it 'parses the query' do - subject.cleanup_boolean_operators(solr_parameters) - expect(solr_parameters[:q]).to eq('+solr +blacklight') - end end context 'when q contains an all-caps phrase that happens to contain a boolean operator' do let(:solr_parameters) do @@ -138,28 +134,12 @@ context 'with the built-in advanced search form', advanced_search: true do before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true) allow(Flipflop).to receive(:json_query_dsl?).and_return(true) end it 'includes the advanced search facets' do solr_p = { fq: ["{!lucene}{!query v=$f_inclusive.issue_denomination_s.0} OR {!query v=$f_inclusive.issue_denomination_s.1}", nil, "format:Coin"] } - search_builder.facets_for_advanced_search_form(solr_p) - expect(solr_p[:fq]).to eq(['format:Coin']) - end - end - context 'with the gem advanced search form' do - before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(false) - allow(Flipflop).to receive(:json_query_dsl?).and_return(false) - end - - context 'when encountering a nil facet' do - it 'removes nil and facets that need to be displayed on the form' do - solr_p = { fq: ["{!lucene}{!query v=$f_inclusive.issue_denomination_s.0} OR {!query v=$f_inclusive.issue_denomination_s.1}", nil, "format:Coin"] } - search_builder.facets_for_advanced_search_form(solr_p) - expect(solr_p[:fq]).to eq(['format:Coin']) - end + expect(solr_p[:fq]).to include('format:Coin') end end end diff --git a/spec/processors/orangelight/series_link_processor_spec.rb b/spec/processors/orangelight/series_link_processor_spec.rb index 4761773c4..4dd7cb676 100644 --- a/spec/processors/orangelight/series_link_processor_spec.rb +++ b/spec/processors/orangelight/series_link_processor_spec.rb @@ -13,44 +13,8 @@ let(:processor) { described_class.new(values, config, document, {}, options, stack) } let(:rendered) { processor.render } - context 'with the old advanced search' do + context 'with the built-in advanced search' do before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(false) - allow(Flipflop).to receive(:json_query_dsl?).and_return(false) - end - it 'adds links if they also appear in the more_in_this_series_t field' do - expect(rendered.first).to eq('Offenbach, Jacques, 1819-1880. Operas. Selections (Bourg) '\ - ''\ - '[More in this series]') - end - - it "does not add links if they don't appear in the more_in_this_series_t field" do - expect(rendered.second).to eq('Collection Archive') - end - - context 'empty more_in_this_series_t field' do - let(:document) { SolrDocument.new } - it 'does not add links' do - expect(rendered.first).to eq('Offenbach, Jacques, 1819-1880. Operas. Selections (Bourg)') - end - end - - context 'more_in_this_series_t contains a shorter version of the series title' do - let(:document) { SolrDocument.new({ 'more_in_this_series_t': ['Offenbach, Jacques, 1819-1880. Operas'] }) } - it 'adds the link' do - expect(rendered.first).to eq('Offenbach, Jacques, 1819-1880. Operas. Selections (Bourg) '\ - ''\ - '[More in this series]') - end - end - end - context 'without the blacklight advanced search gem' do - before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true) allow(Flipflop).to receive(:json_query_dsl?).and_return(true) end it 'adds links if they also appear in the more_in_this_series_t field' do diff --git a/spec/requests/left_anchor_spec.rb b/spec/requests/left_anchor_spec.rb index 7a3cd3eb2..9d69ada33 100644 --- a/spec/requests/left_anchor_spec.rb +++ b/spec/requests/left_anchor_spec.rb @@ -58,25 +58,6 @@ end end - context 'solr operator characters' do - # These tests are only relevant for the standard query parser - # # TODO: remove for standard dsl deprecation - before do - allow(Flipflop).to receive(:json_query_dsl?).and_return(false) - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(false) - end - it 'are handled in simple search' do - get '/catalog.json?search_field=left_anchor&q=JSTOR%7B%7D%3A%26%26%7C%7C"%2B%5E~-%2F%3F+%5BElectronic+Resource%5D' - r = JSON.parse(response.body) - expect(r['data'].any? { |d| d['id'] == '9928379683506421' }).to eq true - end - it 'are handled in advanced search' do - get '/catalog.json?f1=left_anchor&q1=JSTOR%7B%7D%3A%26%26%7C%7C"%2B%5E~-%2F%3F+%5BElectronic+Resource%5D&search_field=advanced' - r = JSON.parse(response.body) - expect(r['data'].any? { |d| d['id'] == '9928379683506421' }).to eq true - end - end - context 'cjk characters' do it 'are searchable in simple search' do get "/catalog.json?search_field=left_anchor&q=#{CGI.escape('浄名玄論 / 京都国立博物館編 ; 解說石塚晴道 (北海道大学名誉教授)')}" diff --git a/spec/requests/request_spec.rb b/spec/requests/request_spec.rb index b8f928095..3fe2e189d 100644 --- a/spec/requests/request_spec.rb +++ b/spec/requests/request_spec.rb @@ -16,14 +16,6 @@ end end - describe 'advanced handling when multiple fields' do - it 'handles it' do - get '/catalog.json?f1=title&f2=author&f3=title&op2=AND&op3=AND&q1=&q2=Murakami%2C+Haruki&q3=1Q84&search_field=advanced' - r = JSON.parse(response.body) - expect(r['data'].length).to eq 3 - end - end - describe 'NOT tests' do it 'ignores lowercase' do get '/catalog.json?search_field=all_fields&q=demeter+does+not+remember' @@ -380,8 +372,11 @@ end describe 'series_display in search results' do + before do + allow(Flipflop).to receive(:json_query_dsl?).and_return(true) + end it 'is fetched when doing a more in this series search' do - get '/catalog.json?q1=Always+learning.&f1=in_series&search_field=advanced' + get '/catalog.json?clause%5B0%5D%5Bfield%5D=series_title&clause%5B0%5D%5Bquery%5D=Always+learning' r = JSON.parse(response.body) expect(r['data'].find { |d| d['id'] == '9979171923506421' }['attributes']['series_display']).not_to be_nil end @@ -390,7 +385,7 @@ get '/catalog/9979171923506421/raw' r = JSON.parse(response.body) series_title = r['series_display'] - get '/catalog?q3=Always+learning&f3=series_title&search_field=advanced' + get '/catalog?clause%5B0%5D%5Bquery%5D=Always+learning&clause%5B0%5D%5Bfield%5D=series_title&search_field=advanced' expect(response.body).to include(series_title.join(', ')) end it 'is not included in other search contexts' do @@ -401,8 +396,11 @@ end describe 'notes field in advanced search' do + before do + allow(Flipflop).to receive(:json_query_dsl?).and_return(true) + end it 'record with notes field is retrieved' do - get '/catalog.json?q1=minhas+entre&f1=notes&search_field=advanced' + get '/catalog.json?clause%5B0%5D%5Bfield%5D=notes&clause%5B0%5D%5Bquery%5D=minhas+entre&clause%5B1%5D%5Bop%5D=must&clause%5B1%5D%5Bfield%5D=author&clause%5B1%5D%5Bquery%5D=&clause%5B2%5D%5Bop%5D=must&clause%5B2%5D%5Bfield%5D=title&clause%5B2%5D%5Bquery%5D=&range%5Bpub_date_start_sort%5D%5Bbegin%5D=&range%5Bpub_date_start_sort%5D%5Bend%5D=&commit=Search' r = JSON.parse(response.body) expect(r['data'].count { |d| d['id'] == '991639143506421' }).to eq(1) end @@ -416,6 +414,9 @@ end describe 'numismatics advanced search' do + before do + allow(Flipflop).to receive(:json_query_dsl?).and_return(true) + end it 'only returns coin records' do get '/catalog.json?advanced_type=numismatics&q=*' r = JSON.parse(response.body) @@ -455,12 +456,10 @@ end end - context "advanced search and jsonld are enabled" do + context "with the built-in advanced search and jsonld is enabled" do before do allow(Flipflop).to receive(:json_query_dsl?).and_return(true) - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true) end - # TODO: what should this really do? Should the advanced search and jsonld get turned off when an algorithm is swapped # Should we see if we can combine the search handlers by adding a query parameter, or make a combined handler that has both? it "retuns the jsonld result not the engineering result" do diff --git a/spec/system/left_anchor_spec.rb b/spec/system/left_anchor_spec.rb index acc512a20..473f8c6e7 100644 --- a/spec/system/left_anchor_spec.rb +++ b/spec/system/left_anchor_spec.rb @@ -50,18 +50,8 @@ RSpec.describe 'left anchored searching', type: :system, left_anchor: true do before { stub_holding_locations } - context 'old query dsl and advanced search' do - before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(false) - allow(Flipflop).to receive(:json_query_dsl?).and_return(false) - end - - it_behaves_like 'a simple search' - it_behaves_like 'an advanced search' - end context 'new query dsl and advanced search' do before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true) allow(Flipflop).to receive(:json_query_dsl?).and_return(true) end diff --git a/spec/system/numismatics_form_spec.rb b/spec/system/numismatics_form_spec.rb index 080bb5d49..55076b6bc 100644 --- a/spec/system/numismatics_form_spec.rb +++ b/spec/system/numismatics_form_spec.rb @@ -5,25 +5,6 @@ before do stub_alma_holding_locations end - context 'when using the view components numismatics form' do - before { allow(Flipflop).to_receive(:view_components_numismatics?).and_return(true) } - end - it 'does not display the basic search form' do - visit '/numismatics' - expect(page).not_to have_selector('.search-query-form') - end - it 'can run a search', js: true do - visit '/numismatics' - fill_in 'issue_denomination_s', with: 'she' - find('li', text: /shekel/).click - click_button('advanced-search-submit') - expect(page.find(".page_entries").text).to eq('1 entry found') - expect(page).to have_content('Coin: 1167') - end - - context 'when using the original numismatics form' do - before { allow(Flipflop).to_receive(:view_components_numismatics?).and_return(false) } - end it 'does not display the basic search form' do visit '/numismatics' expect(page).not_to have_selector('.search-query-form') diff --git a/spec/system/searching_spec.rb b/spec/system/searching_spec.rb index cab76e39e..26acbfe60 100644 --- a/spec/system/searching_spec.rb +++ b/spec/system/searching_spec.rb @@ -103,6 +103,9 @@ end context 'searching for series title from advanced search' do + before do + allow(Flipflop).to receive(:json_query_dsl?).and_return(true) + end it 'displays the online availability' do visit 'advanced' select('Series title', from: 'Options for advanced search') @@ -122,8 +125,11 @@ end end context 'with an invalid field list parameter in the advanced search' do + before do + allow(Flipflop).to receive(:json_query_dsl?).and_return(true) + end it 'will return results without an error' do - visit '/catalog?q1=NSF%20Series&search_field=advanced&f1=in_series2121121121212.1' + visit '/catalog?clause%5B0%5D%5Bfield%5D=series_title&clause%5B0%5D%5Bquery%5D=in_series2121121121212.1' expect { page }.not_to raise_error expect(page).to have_content 'No results found for your search' expect(page).to have_link('Try Borrow Direct', href: 'https://princeton-borrowdirect.reshare.indexdata.com/Search/Results') @@ -166,7 +172,6 @@ context 'with the built-in advanced search form', advanced_search: true do before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true) allow(Flipflop).to receive(:json_query_dsl?).and_return(true) end @@ -201,7 +206,7 @@ in_the_library = page.first('.dropdown-item') in_the_library.click click_on('advanced-search-submit') - page.first('.navbar-toggler').click + page.first('.collapse-toggle').click expect(page).to have_content(/Any of:\nIn the Library/) end @@ -218,7 +223,7 @@ it 'shows facets on the advanced search results page' do visit '/advanced' - fill_in 'clause_0_query', with: 'robots' + fill_in 'clause_0_query', with: 'cats' click_button 'Search' expect(page).to have_button('Access') expect(page).to have_button('Library') diff --git a/spec/system/skip_links_spec.rb b/spec/system/skip_links_spec.rb index 6b5308e25..cfe7deb32 100644 --- a/spec/system/skip_links_spec.rb +++ b/spec/system/skip_links_spec.rb @@ -33,7 +33,6 @@ end context 'with the new advanced search' do before do - allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true) allow(Flipflop).to receive(:json_query_dsl?).and_return(true) end it 'advanced search page has only one skip link' do diff --git a/spec/views/catalog/index_spec.rb b/spec/views/catalog/index_spec.rb index 45cf09532..f46c74c71 100644 --- a/spec/views/catalog/index_spec.rb +++ b/spec/views/catalog/index_spec.rb @@ -75,7 +75,7 @@ it 'inclusive facets display when applied' do visit '/catalog?f_inclusive%5Bformat%5D%5B%5D=Audio&search_field=advanced' expect(page).to have_selector('.blacklight-format.facet-limit-active') - expect(page).to have_selector('.advanced_facet_limit') + expect(page).to have_selector('.inclusive_or.card') end end end