Module: CommonwealthVlrEngine::OcrSearchHelperBehavior

Included in:
OcrSearchHelper
Defined in:
app/helpers/commonwealth_vlr_engine/ocr_search_helper_behavior.rb

Instance Method Summary collapse

Instance Method Details

#compute_term_freq(term_freq) ⇒ Object

return the term frequency as an integer if Solr returns 0, change to 1 (most likely phrase search)



6
7
8
# File 'app/helpers/commonwealth_vlr_engine/ocr_search_helper_behavior.rb', line 6

def compute_term_freq(term_freq)
  term_freq > 0 ? term_freq : term_freq+1
end

#has_searchable_text?(document) ⇒ Boolean

determine of the item has text content that can be searched

Returns:

  • (Boolean)


11
12
13
# File 'app/helpers/commonwealth_vlr_engine/ocr_search_helper_behavior.rb', line 11

def has_searchable_text?(document)
  document['has_searchable_text_bsi']
end

#ocr_q_params(current_search_session) ⇒ Object

if current_search_session exists, return query_params, otherwise return nil



17
18
19
20
21
22
23
# File 'app/helpers/commonwealth_vlr_engine/ocr_search_helper_behavior.rb', line 17

def ocr_q_params(current_search_session)
  if current_search_session
    current_search_session.query_params['q']
  else
    nil
  end
end

#render_ocr_snippets(options = {}) ⇒ Object

print the ocr snippets. if more than one, separate with <br/>



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/commonwealth_vlr_engine/ocr_search_helper_behavior.rb', line 26

def render_ocr_snippets options={}
  snippets = options[:value]
  snippets_content = [('div',
                                  "... #{snippets.first} ...".html_safe,
                                  class: 'ocr_snippet first_snippet')]
  if snippets.length > 1
    snippets_content << render(partial: 'ocr_search/snippets_more',
                               locals: {snippets: snippets.drop(1),
                                        counter: options[:counter]})
  end
  snippets_content.join("\n").html_safe
end

link to the book viewer, using page number or image index



43
44
45
46
47
48
49
50
# File 'app/helpers/commonwealth_vlr_engine/ocr_search_helper_behavior.rb', line 43

def render_page_link(document, image_pid_list, book_id)
  index_of_doc = image_pid_list.index(document.id)
  page_num = document[blacklight_config.page_num_field.to_sym]
  link_to page_num ? "Page #{page_num}" : "Image #{index_of_doc+1}",
          "#{book_viewer_path(book_id)}?ocr_q=#{url_encode(params[:ocr_q])}#1/#{index_of_doc+1}",
          class: 'book_page_link',
          rel: 'nofollow'
end