|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
module DocumentSearch |
|
|
|
|
def document_search(search_params) |
|
|
|
|
search_params.each { |k, v| params[k] = v.gsub(/“|”/, '"') if v.is_a?(String) } |
|
|
|
|
fulltext_fields = %i[reference_number title short_title].freeze |
|
|
|
|
|
|
|
|
|
search = Cdao::Document.search do |
|
|
|
|
@ -13,7 +14,7 @@ module DocumentSearch
|
|
|
|
|
|
|
|
|
|
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present? |
|
|
|
|
|
|
|
|
|
with(:citation_finders_names).any_of([search_params[:citation_finder]]) if search_params[:citation_finder].present? |
|
|
|
|
with(:citation_finders_names).any_of(sanitize_citer_finder_param(search_params[:citation_finder])) if search_params[:citation_finder].present? |
|
|
|
|
|
|
|
|
|
with(:is_only_in_premium_libraries, false) |
|
|
|
|
|
|
|
|
|
@ -28,4 +29,44 @@ module DocumentSearch
|
|
|
|
|
|
|
|
|
|
search |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def sanitize_citer_finder_param(citation_finder_param) |
|
|
|
|
citation_finder = [] |
|
|
|
|
params_vol = [] |
|
|
|
|
params_type = [] |
|
|
|
|
params_page = [] |
|
|
|
|
params[:citation_finder].scan(/\b((\d+\-?\w?)\s(SCRA|PhilRep|Phil|\S+)\.?,?\s?([-,\d\s]+)?)\b/i).map do |cit_fin| |
|
|
|
|
params_vol << cit_fin[1].gsub(/\s+/, "").gsub(/\A0*/, "") |
|
|
|
|
params_type.concat(case cit_fin[2] |
|
|
|
|
when /SCRA/i |
|
|
|
|
["SCRA"] |
|
|
|
|
when /(PhilRep|Phil)\.?,?/i |
|
|
|
|
["Phil"] |
|
|
|
|
else |
|
|
|
|
[] |
|
|
|
|
end |
|
|
|
|
) |
|
|
|
|
cit_fin[3].scan(/\d+-?\d*/).each do |page| |
|
|
|
|
if page.match?(/-/) |
|
|
|
|
page_range = [] |
|
|
|
|
page.scan(/\d+?\d*/).each do |each_page| |
|
|
|
|
page_range << each_page.to_i |
|
|
|
|
end |
|
|
|
|
params_page.concat((page_range[0]..page_range[1]).to_a) |
|
|
|
|
else |
|
|
|
|
params_page << page.to_i if params_page.index(page.to_i).blank? |
|
|
|
|
end |
|
|
|
|
end if cit_fin[3].present? |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
params_type.compact.each do |type| |
|
|
|
|
citation_finder << "#{params_vol[0] if params_vol.present?} #{type}" if params_page.blank? |
|
|
|
|
params_page.compact.uniq.each do |page| |
|
|
|
|
citation_finder << "#{params_vol[0] if params_vol.present?} #{type} #{page}" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
return [] if citation_finder.blank? |
|
|
|
|
citation_finder |
|
|
|
|
end |
|
|
|
|
end |