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



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

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



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

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

#only_works?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 42

def only_works?
  true
end

#show_only_other_works(solr_parameters) ⇒ Object



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

def show_only_other_works(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq] += [
    "-" + ActiveFedora::SolrQueryBuilder.construct_query_for_ids([@id])
  ]
end

#show_only_works_not_child(solr_parameters) ⇒ Object



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

def show_only_works_not_child(solr_parameters)
  ids = ActiveFedora::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]  += [
    "-" + ActiveFedora::SolrQueryBuilder.construct_query_for_ids(ids)
  ]
end

#show_only_works_not_parent(solr_parameters) ⇒ Object



35
36
37
38
39
40
# File 'app/search_builders/hyrax/my/find_works_search_builder.rb', line 35

def show_only_works_not_parent(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq]  += [
    "-" + ActiveFedora::SolrQueryBuilder.construct_query(member_ids_ssim: @id)
  ]
end