Module: Stanford::SearchworksHelper
- Includes:
- SolrHelper
- Included in:
- ApplicationHelper
- Defined in:
- lib/stanford/searchworks_helper.rb
Instance Method Summary (collapse)
-
- (Object) get_856(doc)
Generate unordered list of Online Access Links (IE marc 856s).
- - (Object) get_advanced_search_filter_terms(params)
- - (Object) get_advanced_search_query_terms(params)
- - (Object) get_callnum(doc)
-
- (Object) get_data_with_label(doc, label, field_string, opts = {})
Generate a dt/dd pair given a Solr field If you provide a :default value in the opts hash, then when the solr field is empty, the default value will be used.
-
- (Object) get_data_with_label_from_marc(doc, label, field, sFields = [])
generate an dt/dd pair given a marc field.
- - (Object) get_facet_tag_cloud(facet, response)
-
- (Object) get_nearby_items(document, response, how_many)
Generate display text for “nearby” selections according to call number.
-
- (Object) get_refine_facet(solr_fname, response)
given the solr field name of a refinement facet (e.g. lc_alpha_facet), return a string containing appropriate html to display the given facet heading and its values.
-
- (Object) get_relevance_bar(score, label)
Genrate dt/dd with a relevance.
- - (Object) get_search_breadcrumb_terms(q_param)
-
- (Object) get_subjects(doc)
Generate hierarchical structure of subject headings from marc.
- - (Object) get_suppl_urls(doc)
-
- (Object) get_toc(doc)
Generate dt/dd pair with an unordered list from the table of contents (IE marc 505s).
- - (Object) get_vernacular(doc, field)
- - (Object) home_facet_field_labels
- - (Object) home_facet_field_names
-
- (Object) link_back_to_catalog(opts = {:label=>'Back to Search'})
link_back_to_catalog(:label=>’Back to Search’) Create a link back to the index screen, keeping the user’s facet, query and paging choices intact by using session.
-
- (Object) link_to_contributor_from_marc(doc)
Generate dt/dd pair of contributors with translations.
-
- (Object) link_to_data_with_label(doc, label, field_string, url)
Generate a dt/dd pair with a link with a label given a field in the SolrDocument.
-
- (Object) link_to_data_with_label_from_marc(doc, label, field, url, sFields = [])
Generate dt/dd pair with a link with a label given a marc field.
-
- (Object) link_to_next_document(next_document)
overriding because we need to escape the ‘Next >’ at the linking level.
-
- (Object) link_to_previous_document(previous_document)
overriding because we need to escape the ’< Previous’ at the linking level.
-
- (Object) link_to_with_data(*args, &block)
This is an updated link_to that allows you to pass a data hash along with the html_options which are then written to the generated form for non-GET requests.
-
- (Boolean) params_facet_has_value?(field)
true or false, depending on whether the field and a value is in params[:f].
- - (Boolean) previous_search_is_referrer?
- - (Object) referrer_params
-
- (Object) remove_query_params(value, source_params = params)
copies the current params (or whatever is passed in as the 3rd arg) removes the field value from params[:f] removes the field if there are no more values in params[:f][field] removes additional params (page, id, etc..).
-
- (Object) results_text(pp, p, result_num)
Generate the # - # of # results text.
-
- (Object) show_formats(field)
Generate a dt/dd pair with a comma separated list of formats given an array of format strings.
- - (Object) title_change_data_from_marc(doc)
-
- (Object) url_back_to_catalog
url back to catalog show the url back to the search result, keeping the user’s facet, query and paging choices intact by using session.
-
- (Object) vern_document_heading
def application_name.
Instance Method Details
- (Object) get_856(doc)
Generate unordered list of Online Access Links (IE marc 856s)
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/stanford/searchworks_helper.rb', line 484 def get_856(doc) if doc.marc['856'] text = '' int = 1 text += "<ul class='online'>" text += "<li>" text += "<ol>" doc.marc.find_all{|f| ('856') === f.tag }.each do |field| if !field['u'].nil? # Not sure why I need this, but it fails on certain URLs w/o it. The link printed still has character in it fixed_url = field['u'].gsub("^","").strip url = URI.parse(fixed_url) sub3 = "" subz = [] suby = "" field.each{|subfield| if subfield.code == "3" sub3 = subfield.value elsif subfield.code == "z" subz << subfield.value elsif subfield.code == "y" suby = subfield.value end } if int > 3 text += "<li class='more' style='display:none;'>#{!sub3.blank? ? sub3 << ' ' : ''}#{!subz[0].blank? ? subz[0] << ' ' : ''}<a href='#{field['u']}'>#{(subz[1] and field['x'] == "eLoaderURL") ? subz[1] : !suby.blank? ? suby : url.host}</a></li>" else text += "<li>#{!sub3.blank? ? sub3 << ' ' : ''}#{!subz[0].blank? ? subz[0] << ' ' : ''}<a href='#{field['u']}'>#{(subz[1] and field['x'] == "eLoaderURL") ? subz[1] : !suby.blank? ? suby : url.host}</a></li>" end if int == 3 and field != doc.marc.find_all{|f| ('856') === f.tag }.last text += "<li class='more_link' id='more_link'><a href=''>more<span class='off_screen'> links</span></a></li>" end int += 1 end end if int > 3 text += "<li id='less_link' class='less_link' style='display:none;'><a href=''>less<span class='off_screen'> links</span></a></li>" end text += "</ol>" text += "</li>" text += "</ul>" text end end |
- (Object) get_advanced_search_filter_terms(params)
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
# File 'lib/stanford/searchworks_helper.rb', line 740 def get_advanced_search_filter_terms(params) # Modifying the fq param to be what the UI is expecting from the f param, then setting the f param to this modified hash # Note that the query to Solr has already been made, anything beyond this will just be modifying how the UI interperets the query unless params[:fq].to_s.empty? a_hash = {} fq_params = params[:fq].split("), ") fq_params.each do |fq_param| fq_fields = fq_param.split(":") fq_field = fq_fields[0] fq_values = fq_fields[1][1,fq_fields[1].length][0,fq_fields[1].length-2].split('" OR "') fq_values.each do |value| if a_hash.has_key?("#{fq_field}") a_hash["#{fq_field}"] << value.gsub('"',"") else a_hash["#{fq_field}"] = [value.gsub('"',"")] end end end a_hash end end |
- (Object) get_advanced_search_query_terms(params)
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/stanford/searchworks_helper.rb', line 717 def get_advanced_search_query_terms(params) # if using the standard query parser and have an actual query we need to modify the q param after the search results are requested to something more visually friendly if params[:qt] == "standard" and params[:q] != "collection:sirsi" str = [] fields = [] new_query = params[:q][1,params[:q].length-2] new_query.gsub!(") AND (", " -|- ") new_query.gsub!(") OR (", " -|- ") new_query.gsub!(/\^\d+ OR /, " -|- ") new_query.split(" -|- ").each do |query_string| fields << query_string.split(":")[0] query = query_string.split(":")[1][/\(.*\)/] Blacklight.config[:advanced].each do |key,value| if value.keys.collect{|x| x.to_s}.sort == fields.sort str << "#{key.to_s == "description_checked" ? "Description-TOC" : key.to_s.capitalize} = #{query[1,query.length][0,query.length-2]}" unless str.include?("#{key.to_s == "description_checked" ? "Description-TOC" : key.to_s.capitalize} = #{query[1,query.length][0,query.length-2]}") fields = [] end end end h str.join(" #{params[:op]} ") end end |
- (Object) get_callnum(doc)
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/stanford/searchworks_helper.rb', line 575 def get_callnum(doc) test_hash = {} if doc['item_display'] doc['item_display'].each do |item| item_array = item.split(' -|- ') if test_hash.has_key?(item_array[1]) if test_hash[item_array[1]].has_key?(item_array[2]) if params[:action] == 'index' test_hash[item_array[1]][item_array[2]] << [item_array[3],item_array[0],item_array[6],item_array[4],item_array[7]] unless test_hash[item_array[1]][item_array[2]].flatten.include?(item_array[3]) else test_hash[item_array[1]][item_array[2]] << [item_array[3],item_array[0],item_array[6],item_array[4],item_array[7]] #|Commenting out so that multiple copies show up on record view| unless test_hash[item_array[1]][item_array[2]].flatten.include?(item_array[6]) end else test_hash[item_array[1]][item_array[2]] = [[item_array[3],item_array[0],item_array[6],item_array[4],item_array[7]]] end else test_hash[item_array[1]] = {item_array[2] => [[item_array[3],item_array[0],item_array[6],item_array[4],item_array[7]]]} end end end test_hash end |
- (Object) get_data_with_label(doc, label, field_string, opts = {})
Generate a dt/dd pair given a Solr field If you provide a :default value in the opts hash, then when the solr field is empty, the default value will be used. If you don’t provide a default value, this method will not generate html when the field is empty.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/stanford/searchworks_helper.rb', line 136 def get_data_with_label(doc, label, field_string, opts={}) if opts[:default] && !doc[field_string] doc[field_string] = opts[:default] end if doc[field_string] field = doc[field_string] text = "<dt>#{label}</dt><dd>" if field.is_a?(Array) field.each do |l| text += "#{h(l)}" if l != h(field.last) text += "<br/>" end end else text += h(field) end #Does the field have a vernacular equivalent? if doc["vern_#{field_string}"] vern_field = doc["vern_#{field_string}"] text += "<br/>" if vern_field.is_a?(Array) vern_field.each do |l| text += "#{h(l)}" if l != h(vern_field.last) text += "<br/>" end end else text += h(vern_field) end end text += "</dd>" text end end |
- (Object) get_data_with_label_from_marc(doc, label, field, sFields = [])
generate an dt/dd pair given a marc field
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/stanford/searchworks_helper.rb', line 174 def get_data_with_label_from_marc(doc,label,field,sFields=[]) if doc.marc[field] text = "<dt>#{label}</dt><dd>" doc.marc.find_all{|f| (field) === f.tag}.each do |l| if sFields.length > 0 l.each{|sl| sFields.include?(sl.code) ? text << "#{h(sl.value)} " : ""} else temp_text = "" # get_vern method should be here? In each loop below? After? l.each {|sl| ['w','0', '5', '6', '8'].include?(sl.code) ? nil : temp_text += "#{sl.value} "} vernacular = get_vernacular(doc,l) text += h(temp_text) end vernacular = get_vernacular(doc,l) text += "<br/>#{vernacular}" unless vernacular.nil? text += "<br/>" unless l == doc.marc.find_all{|f| (field) === f.tag}.last end text += "</dd>" text else # The below if statement is attempting to find unmatched vernacular fields that match the supplied field string if doc.marc['880'] doc.marc.find_all{|f| ('880') === f.tag}.each do |l| if l['6'].split("-")[1].gsub("//r","") == "00" and l['6'].split("-")[0] == field text = "<dt>#{label}</dt><dd>" l.each {|sl| ['w','0', '5', '6', '8'].include?(sl.code) ? nil : text += "#{sl.value} "} text += "</dd>" end end text end end end |
- (Object) get_facet_tag_cloud(facet, response)
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# File 'lib/stanford/searchworks_helper.rb', line 598 def get_facet_tag_cloud(facet,response) text = "" display_facet = response.facets.detect {|f| f.name == facet } facet_arr = [] display_facet.items.each do |item| facet_arr << [item.hits,item.value] end facet_arr = facet_arr.sort_by {rand} text += "<div class='cloud_div' id='cloud_#{facet}'>" facet_arr.each do |l| if l[0] > 500000 #font_size = "3" font_size = "jumbo" elsif l[0] > 100000 #font_size = "2.2" font_size = "large" elsif l[0] > 75000 #font_size = "1.8" font_size = "medium" elsif l[0] > 50000 #font_size = "1.4" font_size = "small" else #font_size = "1" font_size = "tiny" end if facet == 'building_facet' and translate_lib.has_key?(l[1]) value = translate_lib[l[1]] else value = l[1] end text += " <span class='tag_cloud #{font_size}'>#{link_to h(value), add_facet_params(facet, l[1])}</span> " end text += "</div>" end |
- (Object) get_nearby_items(document, response, how_many)
Generate display text for “nearby” selections according to call number
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
# File 'lib/stanford/searchworks_helper.rb', line 814 def get_nearby_items(document, response, how_many) text = "<ul id='nearby_objects'>" # TODO: how choose if there are multiple call numbers for this document? # 1. VALID call numbers only # 2. if only one, use it # 3. if only one LC, use it # 4. if multiple LC, do someting # 5. if no LC, do something if !document[:callnum_sort].nil? =begin num = document[:callnum_sort].length if num == 1 this_item_shelfkey = document[:callnum_sort][0].downcase elsif # only one LC, use it elsif # mult LC, use ... one of them? else # no LC ... do something end =end #puts('DEBUG: document has callnum_sort ' + document[:callnum_sort].to_s) this_item_shelfkey = document[:callnum_sort][0].downcase # this_item_reverse_shelfkey = reverse_alphanum(this_item_shelfkey) # FIXME: don't have the right conversion yet .. this_item_reverse_shelfkey = document[:callnum_reverse_sort][0].downcase # TODO: need to take all the returned <li> and sort them by shelfkey, then by title, then by author # get preceding bookspines # terms is array of one element hashes with key=term and value=count terms_array = get_next_terms(this_item_reverse_shelfkey, "callnum_reverse_sort", how_many+1) reverse_shelfkeys_b4 = [] num_docs = 0 puts "num rev terms is " + terms_array.length.to_s terms_array.each { |term_hash| reverse_shelfkeys_b4 << term_hash.keys[0] unless term_hash.keys[0] == this_item_reverse_shelfkey num_docs = num_docs + term_hash.values[0] } text << get_spines_from_field(reverse_shelfkeys_b4, "callnum_reverse_sort").join =begin # preceding shelfkeys are in the reverse order of what we need to display - # they are returned as closest, next closest, ... , furthest # but b/c they are displayed BEFORE the current result, they # need to be ordered furthest to closest # also, don't display THIS document's stuff yet. # reverse_shelfkeys_b4.reverse_each do |r_shelfkey| reverse_shelfkeys_b4.each do |r_shelfkey| if r_shelfkey != reverse_shelfkeys_b4.first # text << get_spines_from_field(reverse_shelfkeys_b4, "callnum_reverse_sort").join text << get_spines_from_field([r_shelfkey], "callnum_reverse_sort").join end end =end # display spine for THIS doc's shelfkey text << "<br/>" if terms_array[0].values[0] == 1 # orig document is only instance of its shelfkey spines = get_spines_from_doc(document, [this_item_shelfkey]) unless spines.nil? spines.each { |spine| text << spine unless text.include?(spine) } end else text << get_spines_from_field([this_item_shelfkey], "callnum_sort").join end text << "<br/>" # get following bookspines terms_array = get_next_terms(this_item_shelfkey, "callnum_sort", how_many+1) shelfkeys_after = [] num_docs = 0 puts "num terms is " + terms_array.length.to_s terms_array.each { |term_hash| shelfkeys_after << term_hash.keys[0] unless term_hash.keys[0] == this_item_shelfkey num_docs = num_docs + term_hash.values[0] } text << get_spines_from_field(shelfkeys_after, "callnum_sort").join =begin shelfkeys_after.each do |shelfkey| if shelfkey != shelfkeys_after.first # text << get_spines_from_field(shelfkeys_after, "callnum_sort").join text << get_spines_from_field(shelfkey[0], "callnum_sort").join end end =end end text << "</ul>" return text unless text == "<ul id='nearby_objects'><br/><br/></ul>" end |
- (Object) get_refine_facet(solr_fname, response)
given the solr field name of a refinement facet (e.g. lc_alpha_facet), return a string containing appropriate html to display the given facet heading and its values
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 |
# File 'lib/stanford/searchworks_helper.rb', line 637 def get_refine_facet(solr_fname, response) text = "" display_facet = response.facets.detect {|f| f.name == solr_fname} if !display_facet.nil? && !display_facet.items.nil? && display_facet.items.length > 0 text = "<li>" text << " <h3 class='facet_selected'>" + facet_field_labels[solr_fname] + "</h3>" text << " <ul>" item_count = 0 display_facet.items.each do |item| if facet_in_params? solr_fname, item.value text << "<li>" text << "<span class='selected'>" + h(item.value) + " (" + item.hits.to_s + ")</span>" text << "[#{link_to 'remove', remove_facet_params(solr_fname, item.value), :class=>'remove'}]" text << "</li>" # accommodate further call number levels case solr_fname when "lc_alpha_facet" text << get_refine_facet("lc_b4cutter_facet", response) when "dewey_2digit_facet" text << get_refine_facet("dewey_b4cutter_facet", response) when "dewey_1digit_facet" text << get_refine_facet("dewey_2digit_facet", response) end else # display the value as a link unless it is at the peer level of a selected call number facet -%> if !( display_facet.name.match(/^(lc_|dewey_|gov_)/i) && params_facet_has_value?(display_facet.name) ) if item_count > 4 text << " <li class=\"more\">" else text << " <li>" end if params[:qt] == 'standard' text << " #{h(item.value)} (" + item.hits.to_s + ")" else text << " #{link_to h(item.value), add_facet_params(solr_fname, item.value)} (" + item.hits.to_s + ")" end text << " </li>" item_count += 1 end end end if display_facet.items.length > 5 if !( display_facet.name.match(/^(lc_|dewey_|gov_)/i) && params_facet_has_value?(display_facet.name) ) text << "<li class='more_li'><a href='' class='more_link' alt='more' #{home_facet_field_labels[solr_fname]}>more...</a></li>" text << "<li class='less_li' style='display:none;'><a href='' class='more_link' alt='less' #{home_facet_field_labels[solr_fname]}>less...</a></li>" end end text << " </ul>" text << "</li>" end # have facet to display text end |
- (Object) get_relevance_bar(score, label)
Genrate dt/dd with a relevance
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/stanford/searchworks_helper.rb', line 115 def (score,label) score_mod = (score * 9).round(2) if score_mod > 100 score_mod = 100 elsif score_mod == 0.0 score_mod = (score * 9).round(4) end text = "<dt>#{label}</dt>" text += "<dd>" text += "<div class='relevance_container'>" text += "<span>#{score_mod}%</span>" text += "<div class='relevance_bar' style='width:#{score_mod}%'>" text += "</div>" text += "</div>" text += "</dd>" end |
- (Object) get_search_breadcrumb_terms(q_param)
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'lib/stanford/searchworks_helper.rb', line 700 def (q_param) if q_param.scan(/"([^"\r\n]*)"/) q_arr = [] old_q = q_param.dup q_param.scan(/"([^"\r\n]*)"/).each{|t| q_arr << "\"#{h(t)}\""} q_arr.each do |l| old_q.gsub!(l,'') end unless old_q.blank? old_q.split(' ').each {|q| q_arr << h(q) } end q_arr else q_arr = q_param.split(' ') end end |
- (Object) get_subjects(doc)
Generate hierarchical structure of subject headings from marc
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/stanford/searchworks_helper.rb', line 423 def get_subjects(doc) text = "<ul id='related_subjects'>" subs = ['600','610','611','630','650','651','653','654','655','656','657','658','690','691','693','696', '697','698','699'] data = [] subs.each do |s| if doc.marc[s] doc.marc.find_all{|f| (s) === f.tag }.each do |l| multi_a = [] temp_data_array = [] temp_subs_text = "" temp_xyv_array = [] unless (s == "690" and l['a'].downcase.include?("collection")) l.each{|sf| unless ['w','0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].include?(sf.code) if sf.code == "a" multi_a << sf.value unless sf.code == "a" and sf.value[0,1] == "%" end if ["v","x","y","z"].include?(sf.code) temp_xyv_array << sf.value else temp_subs_text << "#{sf.value} " unless (sf.code == "a" or (sf.code == "a" and sf.value[0,1] == "%")) end end } if multi_a.length > 1 multi_a.each do |a| data << [a] end elsif multi_a.length == 1 str = multi_a.to_s << " " << temp_subs_text unless (temp_subs_text.blank? and multi_a.empty?) temp_data_array << str else temp_data_array << temp_subs_text unless temp_subs_text.blank? end temp_data_array.concat(temp_xyv_array) unless temp_xyv_array.empty? data << temp_data_array unless temp_data_array.empty? end end end end i = 0 data.each do |fields| text << "<li>" link_text = "" title_text = "Search: " fields.each do |field| link_text << " " unless field == data[i].first link_text << "\"#{field.strip}\"" title_text << " - " unless field == data[i].first title_text << "#{field.strip}" text << link_to(field.strip, {:controller => 'catalog', :action => 'index', :q => link_text, :qt => 'search_subject'}, :title => title_text) text << " > " unless field == data[i].last end text << "</li>" i += 1 end text << "</ul>" return text unless text == "<ul id='related_subjects'></ul>" end |
- (Object) get_suppl_urls(doc)
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/stanford/searchworks_helper.rb', line 529 def get_suppl_urls(doc) text = "" if doc['url_fulltext'] urls = doc['url_fulltext'] text << "<dt>Online:</dt><dd>" #urls.each do |url| fixed_url = urls[0].gsub("^","").strip url_host = URI.parse(fixed_url).host text << "<a href='#{urls[0].strip}'>#{url_host}</a>" if urls.length > 1 text << " + #{pluralize(urls.length - 1, 'more source')}" end #end text << "</dd>" end text rescue URI::InvalidURIError return "" end |
- (Object) get_toc(doc)
Generate dt/dd pair with an unordered list from the table of contents (IE marc 505s)
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/stanford/searchworks_helper.rb', line 260 def get_toc(doc) if doc.marc['505'] text = "<dt>Contents:</dt><dd>" doc.marc.find_all{|f| ('505') === f.tag}.each do |l| text << "<ul class='toc'><li>" l.each{|sl| ['w','0', '5', '6', '8'].include?(sl.code) ? nil : text << "#{sl.value.gsub(' -- ','</li><li>')} " } text << "</li></ul>" text << "<ul class='toc'><li>#{get_vernacular(doc,l).gsub('--','</li><li>')}</li></ul>" unless get_vernacular(doc,l).nil? end text << "</dd>" else if doc.marc['880'] doc.marc.find_all{|f| ('880') === f.tag}.each do |l| if l['6'].split("-")[1].gsub("//r","") == "00" and l['6'].split("-")[0] == "505" text = "<dt>Contents:</dt><dd><ul class='toc'><li>" l.each {|sl| ['w','0', '5', '6', '8'].include?(sl.code) ? nil : text << "#{sl.value.gsub('--','</li><li>')} "} text << "</li></dd>" end end text end end end |
- (Object) get_vernacular(doc, field)
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
# File 'lib/stanford/searchworks_helper.rb', line 550 def get_vernacular(doc,field) return_text = "" if field['6'] field_original = field.tag match_original = field['6'].split("-")[1] doc.marc.find_all{|f| ('880') === f.tag}.each do |l| if l['6'] field_880 = l['6'].split("-")[0] match_880 = l['6'].split("-")[1].gsub("//r","") if match_original == match_880 and field_original == field_880 return_text = "" l.each{ |sl| if !['w','0', '5', '6', '8'].include?(sl.code) return_text += "#{sl.value} " end } end end end end return nil if return_text.blank? return_text end |
- (Object) home_facet_field_labels
15 16 17 |
# File 'lib/stanford/searchworks_helper.rb', line 15 def home_facet_field_labels Blacklight.config[:home_facet][:labels] end |
- (Object) home_facet_field_names
12 13 14 |
# File 'lib/stanford/searchworks_helper.rb', line 12 def home_facet_field_names Blacklight.config[:home_facet][:solr] end |
- (Object) link_back_to_catalog(opts = {:label=>'Back to Search'})
link_back_to_catalog(:label=>’Back to Search’) Create a link back to the index screen, keeping the user’s facet, query and paging choices intact by using session.
52 53 54 55 56 57 58 |
# File 'lib/stanford/searchworks_helper.rb', line 52 def link_back_to_catalog(opts={:label=>'Back to Search'}) query_params = session[:search].dup || {} query_params.delete :counter query_params.delete :total link_url = root_path(query_params) link_to opts[:label], link_url end |
- (Object) link_to_contributor_from_marc(doc)
Generate dt/dd pair of contributors with translations
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/stanford/searchworks_helper.rb', line 323 def link_to_contributor_from_marc(doc) text = "<dt>Contributor:</dt><dd>" ['700', '710', '711', '720'].each do |field| if doc.marc[field] doc.marc.find_all{|f| (field) === f.tag}.each do |l| link_text = '' relator_text = [] l.each {|sl| sl.code == '4' ? relator_text << " #{relator_terms[sl.value]}" : sl.code == '6' ? nil : link_text << "#{sl.value} "} text << link_to(link_text.strip, :q => "\"#{link_text}\"", :controller => 'catalog', :action => 'index', :qt => 'search_author' ) text << relator_text.join(", ") unless relator_text.empty? vernacular = get_vernacular(doc,l) temp_vern = "\"#{vernacular}\"" text << "<br/>#{link_to vernacular, :q => temp_vern, :controller => 'catalog', :action => 'index', :qt => 'search_author'}" unless vernacular.nil? text << "<br/>" end else if doc.marc['880'] doc.marc.find_all{|f| ('880') === f.tag}.each do |l| if l['6'].split("-")[1].gsub("//r","") == "00" and l['6'].split("-")[0] == field text = "<dt>Contributor:</dt><dd>" link_text = '' relator_text = [] l.each {|sl| sl.code == '4' ? relator_text << " #{relator_terms[sl.value]}" : link_text << "#{sl.value} "} text << link_to(link_text.strip,:q => "\"#{link_text}\"", :action => 'index', :qt => 'author_search') text << relator_text.join(", ") unless relator_text.empty? end end end end end text << "</dd>" text unless text == "<dt>Contributor:</dt><dd></dd>" end |
- (Object) link_to_data_with_label(doc, label, field_string, url)
Generate a dt/dd pair with a link with a label given a field in the SolrDocument
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/stanford/searchworks_helper.rb', line 226 def link_to_data_with_label(doc,label,field_string,url) if doc[field_string] field = doc[field_string] text = "<dt>#{label}</dt><dd>" if field.is_a?(Array) field.each do |l| text += link_to l, url.merge!(:q => "\"#{l}\"") if l != field.last text += "<br/>" end end else text += link_to field, url.merge!(:q => "\"#{field}\"") end if doc["vern_#{field_string}"] vern_field = doc["vern_#{field_string}"] text += "<br/>" if vern_field.is_a?(Array) vern_field.each do |l| text += link_to l, url.merge!(:q => "\"#{l}\"") if l != vern_field.last text += "<br/>" end end else text += link_to vern_field, url.merge!(:q => "\"#{vern_field}\"") end end text += "</dd>" text end end |
- (Object) link_to_data_with_label_from_marc(doc, label, field, url, sFields = [])
Generate dt/dd pair with a link with a label given a marc field
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/stanford/searchworks_helper.rb', line 284 def link_to_data_with_label_from_marc(doc,label,field,url,sFields=[]) if doc.marc[field] text = "<dt>#{label}</dt><dd>" doc.marc.find_all{|f| (field) === f.tag}.each do |l| if sFields.length > 0 link_text = "" sFields.each do |sf| if l.find{|s| s.code == sf.to_s} link_text << "#{l.find{|s| s.code == sf.to_s}.value} " end end text += link_to link_text, url.merge!(:q => "\"#{link_text}\"") else link_text = '' l.each {|sl| ['w','0', '5', '6', '8'].include?(sl.code) ? nil : link_text += "#{sl.value} " unless (sl.code == 'a' and sl.value[0,1] == "%") } text += link_to link_text, url.merge!(:q => "\"#{link_text}\"") end vernacular = get_vernacular(doc,l) temp_vern = "\"#{vernacular}\"" text += "<br/>#{link_to vernacular, url.merge!(:q => temp_vern)}" unless vernacular.nil? text += "<br/>" unless l == doc.marc.find_all{|f| (field) === f.tag}.last end text += "</dd>" else if doc.marc['880'] doc.marc.find_all{|f| ('880') === f.tag}.each do |l| if l['6'].split("-")[1].gsub("//r","") == "00" and l['6'].split("-")[0] == field text = "<dt>#{label}</dt><dd>" link_text = '' l.each {|sl| ['w','0', '5', '6', '8'].include?(sl.code) ? nil : link_text += "#{sl.value} "} text += link_to link_text, url.merge!(:q => "\"#{link_text}\"") text += "</dd>" end end text end end end |
- (Object) link_to_next_document(next_document)
overriding because we need to escape the ‘Next >’ at the linking level
24 25 26 27 |
# File 'lib/stanford/searchworks_helper.rb', line 24 def link_to_next_document(next_document) return if next_document == nil link_to_document next_document, :label=>'Next »', :counter => session[:search][:counter].to_i + 1 end |
- (Object) link_to_previous_document(previous_document)
overriding because we need to escape the ’< Previous’ at the linking level
19 20 21 22 |
# File 'lib/stanford/searchworks_helper.rb', line 19 def link_to_previous_document(previous_document) return if previous_document == nil link_to_document previous_document, :label=>'« Previous', :counter => session[:search][:counter].to_i - 1 end |
- (Object) link_to_with_data(*args, &block)
This is an updated link_to that allows you to pass a data hash along with the html_options which are then written to the generated form for non-GET requests. The key is the form element name and the value is the value:
link_to_with_data('Name', some_path(some_id), :method => :post, :html)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/stanford/searchworks_helper.rb', line 65 def link_to_with_data(*args, &block) if block_given? = args.first || {} = args.second concat(link_to(capture(&block), , )) else name = args.first = args.second || {} = args.third url = url_for() if = .stringify_keys href = ['href'] (, url) = () else = nil end href_attr = "href=\"#{url}\"" unless href "<a #{href_attr}#{tag_options}>#{name || url}</a>" end end |
- (Boolean) params_facet_has_value?(field)
true or false, depending on whether the field and a value is in params[:f]
691 692 693 694 695 696 697 |
# File 'lib/stanford/searchworks_helper.rb', line 691 def params_facet_has_value?(field) if params[:f] and params[:f][field] !params[:f][field].compact.empty? else false end end |
- (Boolean) previous_search_is_referrer?
762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
# File 'lib/stanford/searchworks_helper.rb', line 762 def previous_search_is_referrer? # If the referrer params are empty and there is no search history return false (User went directly to the record w/o a search session) if referrer_params.empty? and url_back_to_catalog.empty? false # If the search history == the referrer params return true. elsif url_back_to_catalog == referrer_params true # If the referrer includes the base URL (ie, <Prev | Next> links on record view) then return true elsif request.referrer.include?(url_for({:controller => 'catalog', :only_path => false})) true else false end end |
- (Object) referrer_params
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/stanford/searchworks_helper.rb', line 777 def referrer_params request_params = {} if request.referrer.to_s.include?("&") or request.referrer.to_s.include?("?") request.referrer.to_s[/\/\?.*/].split("&").each do |paramater| unless paramater == "/?" key = CGI::unescape(paramater.split("=")[0].gsub(/\/\?/,"")).to_sym key.to_s[0,2] == "/?" ? key.to_s.gsub!("/?","").to_sym : "" value = paramater.split("=").length > 1 ? h(paramater.split("=")[1].gsub("+"," ")) : "" if request_params.has_key?(key) request_params[key] << CGI::unescape(value) else request_params[key] = CGI::unescape(value) end end end end request_params end |
- (Object) remove_query_params(value, source_params = params)
copies the current params (or whatever is passed in as the 3rd arg) removes the field value from params[:f] removes the field if there are no more values in params[:f][field] removes additional params (page, id, etc..)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/stanford/searchworks_helper.rb', line 33 def remove_query_params(value, source_params=params) p = source_params.dup.symbolize_keys! # need to dup the facet values too, # if the values aren't dup'd, then the values # from the session will get remove in the show view... p[:q] = p[:q].dup p.delete :page p.delete :id p.delete :total p.delete :counter p.delete :commit #return p unless p[field] p[:q] = p[:q].gsub(value,"").strip p.delete(:q) if p[:q].size == 0 p end |
- (Object) results_text(pp, p, result_num)
Generate the # - # of # results text
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/stanford/searchworks_helper.rb', line 91 def results_text(pp, p, result_num) if pp.nil? per_page = Blacklight.config[:index][:num_per_page].to_i else per_page = pp.to_i end if p.nil? start_num = 1 p = 1 else start_num = (p.to_i * per_page) - (per_page - 1) end if p == 1 and per_page < result_num end_num = per_page elsif ((per_page * p.to_i) > result_num) end_num = result_num else end_num = per_page * p.to_i end "#{start_num} - #{end_num} of " end |
- (Object) show_formats(field)
Generate a dt/dd pair with a comma separated list of formats given an array of format strings
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/stanford/searchworks_helper.rb', line 210 def show_formats(field) if field text = "<dt>Format:</dt><dd>" field.each do |l| text += "<span class='iconSpan #{l.downcase.gsub(" ","").gsub("/","_")}'>" text += h(l) text += ", " unless l == field.last text += "</span>" end text += "</dd>" text end end |
- (Object) title_change_data_from_marc(doc)
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/stanford/searchworks_helper.rb', line 357 def title_change_data_from_marc(doc) if doc.marc['780'] or doc.marc['785'] text = "" if doc.marc['780'] doc.marc.find_all{|f| ('780') === f.tag}.each do |field| text << "<dt>#{name_change_780_translations[field.indicator2]}:</dt>" temp_text = "" field.each{|subfield| if subfield.code == "w" nil elsif subfield.code == "t" query = "\"#{subfield.value}\"" temp_text << "#{link_to(subfield.value, params.dup.merge!(:action=>'index', :qt=>'search_title', :q=>query))} " elsif subfield.code == "x" temp_text << "(#{link_to(subfield.value, params.dup.merge!(:action=>'index', :qt=>'search', :q=>subfield.value))}) " else temp_text << "#{subfield.value} " end } text << "<dd>#{temp_text}</dd>" end end if doc.marc['785'] special_handler = [] doc.marc.find_all{|f| ('785') === f.tag}.each do |field| if field.indicator2 == "7" special_handler << field end end doc.marc.find_all{|f| ('785') === f.tag}.each do |field| text << "<dt>" if field.indicator2 == "7" and field == special_handler.first text << "Merged with:" elsif field.indicator2 == "7" and field == special_handler.last text << "to form:" elsif field.indicator2 == "7" and field != special_handler.first and field != special_handler.last text << "and with:" else text << "#{name_change_785_translations[field.indicator2]}:" end text << "</dt>" temp_text = "" field.each{|subfield| if subfield.code == "w" nil elsif subfield.code == "t" query = "\"#{subfield.value}\"" temp_text << "#{link_to(subfield.value, params.dup.merge!(:action=>'index', :qt=>'search_title', :q=>query))} " elsif subfield.code == "x" temp_text << "(#{link_to(subfield.value, params.dup.merge!(:action=>'index', :qt=>'search', :q=>subfield.value))}) " else temp_text << "#{subfield.value} " end } text << "<dd>#{temp_text}</dd>" end end text end end |
- (Object) url_back_to_catalog
url back to catalog show the url back to the search result, keeping the user’s facet, query and paging choices intact by using session. this is to match against the http.referrer
799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/stanford/searchworks_helper.rb', line 799 def url_back_to_catalog query_params = session[:search].dup || {} query_params.delete :counter query_params.delete :total if query_params.has_key?(:f) query_params[:f].each do |key,val| query_params["f[#{key}][]".to_sym] = val.to_s end query_params.delete(:f) end query_params end |
- (Object) vern_document_heading
def application_name
'SearchWorks (SULAIR)'
end
9 10 11 |
# File 'lib/stanford/searchworks_helper.rb', line 9 def vern_document_heading @document[Blacklight.config[:show][:vern_heading]] end |