Module: Cul::Hydra::RisearchMembers::ClassMethods
- Included in:
- Cul::Hydra::RisearchMembers
- Defined in:
- lib/cul_hydra/risearch_members.rb
Instance Method Summary collapse
-
#get_all_pids_for_identifier(identifier) ⇒ Object
Returns the pids of ALL objects found with the given identifier.
- #get_direct_member_count(pid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
- #get_direct_member_pids(pid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
- #get_direct_member_results(pid, flush_resource_index_before_query = false, verbose_output = false, format = 'json') ⇒ Object
- #get_direct_members_with_datastream_pids(pid, dsid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
- #get_direct_members_with_datastream_results(pid, dsid, flush_resource_index_before_query = false, verbose_output = false, format = 'json') ⇒ Object
-
#get_pid_for_identifier(identifier, flush_resource_index_before_query = false) ⇒ Object
Returns the pid of the first object found with the given identifier.
- #get_project_constituent_count(pid, verbose_output = false) ⇒ Object
- #get_project_constituent_pids(pid, verbose_output = false) ⇒ Object
-
#get_project_constituent_results(pid, verbose_output = false, format = 'json') ⇒ Object
Project constituents.
- #get_publish_target_member_count(pid, verbose_output = false) ⇒ Object
- #get_publish_target_member_pids(pid, verbose_output = false) ⇒ Object
-
#get_publish_target_member_results(pid, verbose_output = false, format = 'json') ⇒ Object
Publish target members.
- #get_recursive_member_pids(pid, verbose_output = false, cmodel_type = 'all') ⇒ Object
- #log_risearch_query(query, verbose_output = false) ⇒ Object
Instance Method Details
#get_all_pids_for_identifier(identifier) ⇒ Object
Returns the pids of ALL objects found with the given identifier
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/cul_hydra/risearch_members.rb', line 173 def get_all_pids_for_identifier(identifier) find_by_identifier_query = "select $pid from <#ri> where $pid <http://purl.org/dc/elements/1.1/identifier> $identifier and $identifier <mulgara:is> '#{identifier}'" search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(find_by_identifier_query, { :type => 'tuples', :format => 'json', :limit => '', :stream => 'on' })) pids_to_return = [] if search_response['results'].present? search_response['results'].each do |result| pids_to_return << result['pid'].gsub('info:fedora/', '') end end return pids_to_return end |
#get_direct_member_count(pid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
55 56 57 58 |
# File 'lib/cul_hydra/risearch_members.rb', line 55 def get_direct_member_count(pid, flush_resource_index_before_query=false, verbose_output=false) count = get_direct_member_results(pid,flush_resource_index_before_query,verbose_output,'count/json') return count.blank? ? 0 : count[0]['count'].to_i end |
#get_direct_member_pids(pid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
50 51 52 53 |
# File 'lib/cul_hydra/risearch_members.rb', line 50 def get_direct_member_pids(pid, flush_resource_index_before_query=false, verbose_output=false) unique_pids = get_direct_member_results(pid,flush_resource_index_before_query,verbose_output,'json') unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq end |
#get_direct_member_results(pid, flush_resource_index_before_query = false, verbose_output = false, format = 'json') ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cul_hydra/risearch_members.rb', line 31 def get_direct_member_results(pid, flush_resource_index_before_query=false, verbose_output=false, format='json') direct_member_query = 'select $pid from <#ri> where $pid <http://purl.oclc.org/NET/CUL/memberOf> <fedora:' + pid + '>' log_risearch_query(direct_member_query, verbose_output) search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(direct_member_query, { :type => 'tuples', :format => format, :limit => '', :stream => 'on', :flush => flush_resource_index_before_query.to_s })) return search_response['results'] end |
#get_direct_members_with_datastream_pids(pid, dsid, flush_resource_index_before_query = false, verbose_output = false) ⇒ Object
86 87 88 89 |
# File 'lib/cul_hydra/risearch_members.rb', line 86 def get_direct_members_with_datastream_pids(pid, dsid, flush_resource_index_before_query=false, verbose_output=false) unique_pids = get_direct_members_with_datastream_results(pid, dsid, flush_resource_index_before_query, verbose_output, 'json') unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq end |
#get_direct_members_with_datastream_results(pid, dsid, flush_resource_index_before_query = false, verbose_output = false, format = 'json') ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cul_hydra/risearch_members.rb', line 60 def get_direct_members_with_datastream_results(pid, dsid, flush_resource_index_before_query=false, verbose_output=false, format='json') # Note: The query we're using below is a faster version of this query: # "select $pid from <#ri> # where $pid <http://purl.oclc.org/NET/CUL/memberOf> <fedora:#{pid}> # and $pid <fedora-view:disseminates> $ds # and $ds <fedora-view:disseminationType> <info:fedora/*/#{dsid}>" direct_members_with_ds_query = "select $pid count( select $ds from <#ri> where $pid <fedora-view:disseminates> $ds and $ds <fedora-view:disseminationType> <info:fedora/*/#{dsid}>) from <#ri> where $pid <http://purl.oclc.org/NET/CUL/memberOf> <info:fedora/#{pid}> having $k0 <http://mulgara.org/mulgara#occursMoreThan> '0.0'^^<http://www.w3.org/2001/XMLSchema#double>;" log_risearch_query(direct_members_with_ds_query, verbose_output) search_response = JSON.parse(Cul::Hydra::Fedora.repository.find_by_itql(direct_members_with_ds_query, { :type => 'tuples', :format => format, :limit => '', :stream => 'on', :flush => flush_resource_index_before_query.to_s })) return search_response['results'] end |
#get_pid_for_identifier(identifier, flush_resource_index_before_query = false) ⇒ Object
Returns the pid of the first object found with the given identifier
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/cul_hydra/risearch_members.rb', line 152 def get_pid_for_identifier(identifier, flush_resource_index_before_query=false) find_by_identifier_query = "select $pid from <#ri> where $pid <http://purl.org/dc/elements/1.1/identifier> $identifier and $identifier <mulgara:is> '#{identifier}'" search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(find_by_identifier_query, { :type => 'tuples', :format => 'json', :limit => '1', :stream => 'on', :flush => flush_resource_index_before_query.to_s })) if search_response['results'].present? return search_response['results'].first['pid'].gsub('info:fedora/', '') else return nil end end |
#get_project_constituent_count(pid, verbose_output = false) ⇒ Object
116 117 118 119 |
# File 'lib/cul_hydra/risearch_members.rb', line 116 def get_project_constituent_count(pid, verbose_output=false) count = get_project_constituent_results(pid,verbose_output,'count/json') return count.blank? ? 0 : count[0]['count'].to_i end |
#get_project_constituent_pids(pid, verbose_output = false) ⇒ Object
111 112 113 114 |
# File 'lib/cul_hydra/risearch_members.rb', line 111 def get_project_constituent_pids(pid, verbose_output=false) unique_pids = get_project_constituent_results(pid,verbose_output,'json') unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq end |
#get_project_constituent_results(pid, verbose_output = false, format = 'json') ⇒ Object
Project constituents
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cul_hydra/risearch_members.rb', line 93 def get_project_constituent_results(pid, verbose_output=false, format='json') project_constituent_query = 'select $pid from <#ri> where $pid <info:fedora/fedora-system:def/relations-external#isConstituentOf> <fedora:' + pid + '>' log_risearch_query(project_constituent_query, verbose_output) search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(project_constituent_query, { :type => 'tuples', :format => format, :limit => '', :stream => 'on' })) return search_response['results'] end |
#get_publish_target_member_count(pid, verbose_output = false) ⇒ Object
146 147 148 149 |
# File 'lib/cul_hydra/risearch_members.rb', line 146 def get_publish_target_member_count(pid, verbose_output=false) count = get_publish_target_member_results(pid,verbose_output,'count/json') return count.blank? ? 0 : count[0]['count'].to_i end |
#get_publish_target_member_pids(pid, verbose_output = false) ⇒ Object
141 142 143 144 |
# File 'lib/cul_hydra/risearch_members.rb', line 141 def get_publish_target_member_pids(pid, verbose_output=false) unique_pids = get_publish_target_member_results(pid,verbose_output,'json') unique_pids.map{|result| result['pid'].gsub('info:fedora/', '') }.uniq end |
#get_publish_target_member_results(pid, verbose_output = false, format = 'json') ⇒ Object
Publish target members
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/cul_hydra/risearch_members.rb', line 123 def get_publish_target_member_results(pid, verbose_output=false, format='json') project_constituent_query = 'select $pid from <#ri> where $pid <http://purl.org/dc/terms/publisher> <fedora:' + pid + '>' log_risearch_query(project_constituent_query, verbose_output) search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(project_constituent_query, { :type => 'tuples', :format => format, :limit => '', :stream => 'on' })) return search_response['results'] end |
#get_recursive_member_pids(pid, verbose_output = false, cmodel_type = 'all') ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cul_hydra/risearch_members.rb', line 4 def get_recursive_member_pids(pid, verbose_output=false, cmodel_type='all') recursive_member_query = 'select $child $parent from <#ri> where walk($child <http://purl.oclc.org/NET/CUL/memberOf> <fedora:' + pid + '> and $child <http://purl.oclc.org/NET/CUL/memberOf> $parent)' unless cmodel_type == 'all' recursive_member_query += ' and $child <fedora-model:hasModel> $cmodel' recursive_member_query += ' and $cmodel <mulgara:is> <info:fedora/ldpd:' + cmodel_type + '>' end log_risearch_query(recursive_member_query, verbose_output) search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(recursive_member_query, { :type => 'tuples', :format => 'json', :limit => '', :stream => 'on' })) unique_pids = search_response['results'].map{|result| result['child'].gsub('info:fedora/', '') }.uniq return unique_pids end |
#log_risearch_query(query, verbose_output = false) ⇒ Object
197 198 199 |
# File 'lib/cul_hydra/risearch_members.rb', line 197 def log_risearch_query(query, verbose_output = false) puts "Performing query:\n#{query}" if verbose_output end |