diff --git a/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb b/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb index 71df846163..e79b79ec7e 100644 --- a/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb +++ b/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb @@ -28,7 +28,7 @@ def with_pagination(solr_parameters) def show_only_other_collections_of_the_same_collection_type(solr_parameters) solr_parameters[:fq] ||= [] solr_parameters[:fq] += [ - Hyrax::SolrQueryBuilderService.construct_query(Hyrax.config.collection_type_index_field => @collection.collection_type_gid), + Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: { Hyrax.config.collection_type_index_field => @collection.collection_type_gid }).build, "-{!graph from=id to=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_parent}}id:#{@collection.id}", "-{!graph to=id from=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_child}}id:#{@collection.id}" ] diff --git a/app/search_builders/hyrax/my/find_works_search_builder.rb b/app/search_builders/hyrax/my/find_works_search_builder.rb index cab9cea628..20bbd80614 100644 --- a/app/search_builders/hyrax/my/find_works_search_builder.rb +++ b/app/search_builders/hyrax/my/find_works_search_builder.rb @@ -15,24 +15,24 @@ def initialize(context) def filter_on_title(solr_parameters) solr_parameters[:fq] ||= [] - solr_parameters[:fq] += [Hyrax::SolrQueryBuilderService.construct_query(title_tesim: @q)] + solr_parameters[:fq] += [Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: { title_tesim: @q }).build] end def show_only_other_works(solr_parameters) solr_parameters[:fq] ||= [] - solr_parameters[:fq] += ["-#{Hyrax::SolrQueryBuilderService.construct_query_for_ids([@id])}"] + solr_parameters[:fq] += ["-#{Hyrax::SolrQueryService.new.with_ids(ids: [@id]).build}"] end def show_only_works_not_child(solr_parameters) ids = Hyrax::SolrService.query("{!field f=id}#{@id}", fl: "member_ids_ssim", rows: 10_000).flat_map { |x| x.fetch("member_ids_ssim", []) } solr_parameters[:fq] ||= [] - solr_parameters[:fq] += ["-#{Hyrax::SolrQueryBuilderService.construct_query_for_ids([ids])}"] + solr_parameters[:fq] += ["-#{Hyrax::SolrQueryService.new.with_ids(ids: [ids]).build}"] end def show_only_works_not_parent(solr_parameters) solr_parameters[:fq] ||= [] solr_parameters[:fq] += [ - "-" + Hyrax::SolrQueryBuilderService.construct_query(member_ids_ssim: @id) + "-" + Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: { member_ids_ssim: @id }).build ] end diff --git a/app/search_builders/hyrax/my/highlights_search_builder.rb b/app/search_builders/hyrax/my/highlights_search_builder.rb index c2478db39c..d8503b459c 100644 --- a/app/search_builders/hyrax/my/highlights_search_builder.rb +++ b/app/search_builders/hyrax/my/highlights_search_builder.rb @@ -8,6 +8,6 @@ class Hyrax::My::HighlightsSearchBuilder < Hyrax::SearchBuilder def show_only_highlighted_works(solr_parameters) ids = scope.current_user.trophies.pluck(:work_id) solr_parameters[:fq] ||= [] - solr_parameters[:fq] += [Hyrax::SolrQueryBuilderService.construct_query_for_ids([ids])] + solr_parameters[:fq] += [Hyrax::SolrQueryService.new.with_ids(ids: [ids]).build] end end diff --git a/app/search_builders/hyrax/parent_collection_search_builder.rb b/app/search_builders/hyrax/parent_collection_search_builder.rb index fe8e3984ed..6be925d2d0 100644 --- a/app/search_builders/hyrax/parent_collection_search_builder.rb +++ b/app/search_builders/hyrax/parent_collection_search_builder.rb @@ -7,7 +7,7 @@ class ParentCollectionSearchBuilder < Hyrax::CollectionSearchBuilder # include filters into the query to only include the collections containing this item def include_item_ids(solr_parameters) solr_parameters[:fq] ||= [] - solr_parameters[:fq] += [Hyrax::SolrQueryBuilderService.construct_query_for_ids([item.member_of_collection_ids])] + solr_parameters[:fq] += [Hyrax::SolrQueryService.new.with_ids(ids: [item.member_of_collection_ids]).build] end end end diff --git a/app/services/hyrax/solr_query_builder_service.rb b/app/services/hyrax/solr_query_builder_service.rb deleted file mode 100644 index b233738286..0000000000 --- a/app/services/hyrax/solr_query_builder_service.rb +++ /dev/null @@ -1,109 +0,0 @@ -# frozen_string_literal: true -module Hyrax - ## - # @deprecated - # This class is being replaced by Hyrax::SolrQueryService. - # - # Methods in this class are from/based on ActiveFedora::SolrQueryBuilder - # - # @see Hyrax::SolrQueryService - class SolrQueryBuilderService - class << self - # Construct a solr query for a list of ids - # This is used to get a solr response based on the list of ids in an object's RELS-EXT relationhsips - # If the id_array is empty, defaults to a query of "id:NEVER_USE_THIS_ID", which will return an empty solr response - # @param [Array] id_array the ids that you want included in the query - # @return [String] a solr query - # @example - # construct_query_for_ids(['a1', 'b2']) - # # => "{!terms f=id}a1,b2" - # @deprecated - def construct_query_for_ids(id_array) - Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \ - "Instead, use 'Hyrax::SolrQueryService.new.with_ids'.") - ids = id_array.reject(&:blank?) - return "id:NEVER_USE_THIS_ID" if ids.empty? - Hyrax::SolrQueryService.new.with_ids(ids: id_array).build - end - - # Construct a solr query from a list of pairs (e.g. [field name, values]) - # @param [Hash] field_pairs a list of pairs of property name and values - # @param [String] join_with the value we're joining the clauses with (default: ' AND ') - # @param [String] type of query to run. Either 'raw' or 'field' (default: 'field') - # @return [String] a solr query - # @example - # construct_query([['library_id_ssim', '123'], ['owner_ssim', 'Fred']]) - # # => "_query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\"" - # @deprecated - def construct_query(field_pairs, join_with = default_join_with, type = 'field') - Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \ - "Instead, use 'Hyrax::SolrQueryService.new.with_field_pairs'.") - Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs, - join_with: join_with, - type: type).build - end - - # @deprecated - def default_join_with - Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \ - "There will not be a replacement for this method. See Hyrax::SolrQueryService which is replacing this class.") - ' AND ' - end - - # Construct a solr query from a list of pairs (e.g. [field name, values]) including the model (e.g. Collection, Monograph) - # @param [Class] model class - # @param [Hash] field_pairs a list of pairs of property name and values - # @param [String] join_with the value we're joining the clauses with (default: ' AND ') - # @param [String] type of query to run. Either 'raw' or 'field' (default: 'field') - # @return [String] a solr query - # @example - # construct_query(Collection, [['library_id_ssim', '123'], ['owner_ssim', 'Fred']]) - # # => "_query_:\"{!field f=has_model_ssim}Collection\" AND _query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\"" - # @deprecated - def construct_query_for_model(model, field_pairs, join_with = default_join_with, type = 'field') - Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \ - "Instead, use 'Hyrax::SolrQueryService.new.with_model'.") - field_pairs["has_model_ssim"] = model.to_s - Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs, - join_with: join_with, - type: type).build - end - - private - - # @param [Array] pairs a list of (key, value) pairs. The value itself may - # @param [String] type The type of query to run. Either 'raw' or 'field' - # @return [Array] a list of solr clauses - def pairs_to_clauses(pairs, type) - pairs.flat_map do |field, value| - condition_to_clauses(field, value, type) - end - end - - # @param [String] field - # @param [String, Array] values - # @param [String] type The type of query to run. Either 'raw' or 'field' - # @return [Array] - def condition_to_clauses(field, values, type) - values = Array(values) - values << nil if values.empty? - values.map do |value| - if value.present? - query_clause(type, field, value) - else - # Check that the field is not present. In SQL: "WHERE field IS NULL" - "-#{field}:[* TO *]" - end - end - end - - # Create a raw query clause suitable for sending to solr as an fq element - # @param [String] type The type of query to run. Either 'raw' or 'field' - # @param [String] key - # @param [String] value - def query_clause(type, key, value) - "_query_:\"{!#{type} f=#{key}}#{value.gsub('"', '\"')}\"" - end - end - end -end diff --git a/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb b/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb index 252bbccf49..3af66a97bf 100644 --- a/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb +++ b/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb @@ -30,7 +30,7 @@ it "is successful" do subject - expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryBuilderService.construct_query_for_ids([work.id])] + expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryService.new.with_ids(ids: [work.id]).build] end end @@ -40,7 +40,7 @@ it "is successful" do subject ids = Hyrax::SolrService.query("{!field f=id}#{work.id}", fl: "member_ids_ssim").flat_map { |x| x.fetch("member_ids_ssim", []) } - expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryBuilderService.construct_query_for_ids([ids])] + expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryService.new.with_ids(ids: [ids]).build] end end diff --git a/spec/services/hyrax/solr_query_builder_service_spec.rb b/spec/services/hyrax/solr_query_builder_service_spec.rb deleted file mode 100644 index f0dbdd9584..0000000000 --- a/spec/services/hyrax/solr_query_builder_service_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true -require 'spec_helper' - -RSpec.describe Hyrax::SolrQueryBuilderService do - describe '.construct_query_for_ids' do - it "generates a useable solr query from an array of Fedora ids" do - expect(described_class.construct_query_for_ids(["my:_ID1_", "my:_ID2_", "my:_ID3_"])).to eq '{!terms f=id}my:_ID1_,my:_ID2_,my:_ID3_' - end - it "returns a valid solr query even if given an empty array as input" do - expect(described_class.construct_query_for_ids([""])).to eq "id:NEVER_USE_THIS_ID" - end - end - - describe ".construct_query" do - it "generates a query clause" do - expect(described_class.construct_query('id' => "my:_ID1_")).to eq '_query_:"{!field f=id}my:_ID1_"' - end - end - - describe ".construct_query_for_model" do - it "generates a query clause" do - expect(described_class.construct_query_for_model(::Collection, 'id' => "my:_ID1_")).to eq '(_query_:"{!field f=id}my:_ID1_" AND _query_:"{!field f=has_model_ssim}Collection")' - end - end -end