Class: Hyrax::My::FindWorksSearchBuilder

Inherits:
SearchBuilder
  • Object
show all
Includes:
FilterByType
Defined in:
app/search_builders/hyrax/my/find_works_search_builder.rb

Overview

Search for possible works that user can edit and could be a work’s child or parent.

Instance Method Summary collapse

Methods included from FilterByType

#filter_models

Methods inherited from SearchBuilder

#show_only_resources_deposited_by_current_user

Methods included from SearchBuilderBehavior

#discovery_permissions

Constructor Details

#initialize(context) ⇒ FindWorksSearchBuilder

Excludes the id that is part of the params



9
10
11
12
13
14
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 9

def initialize(context)
  super(context)
  # Without an id this class will produce an invalid query.
  @id = context.params[:id] || raise("missing required parameter: id")
  @q = context.params[:q]
end

Instance Method Details

#filter_on_title(solr_parameters) ⇒ Object



16
17
18
19
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 16

def filter_on_title(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq] += [Hyrax::SolrQueryBuilderService.construct_query(title_tesim: @q)]
end

#only_works?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 39

def only_works?
  true
end

#parsed_idObject

Since Valkyrie objects pass is an Id object, additional parsing is needed.



44
45
46
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 44

def parsed_id
  @id.is_a?(String) ? @id : @id.id
end

#show_only_other_works(solr_parameters) ⇒ Object



21
22
23
24
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 21

def show_only_other_works(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq] += ["-#{Hyrax::SolrQueryBuilderService.construct_query_for_ids([parsed_id])}"]
end

#show_only_works_not_child(solr_parameters) ⇒ Object



26
27
28
29
30
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 26

def show_only_works_not_child(solr_parameters)
  ids = Hyrax::SolrService.query("{!field f=id}#{parsed_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])}"]
end

#show_only_works_not_parent(solr_parameters) ⇒ Object



32
33
34
35
36
37
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 32

def show_only_works_not_parent(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq]  += [
    "-" + Hyrax::SolrQueryBuilderService.construct_query(member_ids_ssim: parsed_id)
  ]
end