Module: Alchemy::PgSearch::SearchHelper

Defined in:
app/helpers/alchemy/pg_search/search_helper.rb

Instance Method Summary collapse

Instance Method Details

#highlighted_excerpt(text, phrase, radius = 50) ⇒ Object



48
49
50
# File 'app/helpers/alchemy/pg_search/search_helper.rb', line 48

def highlighted_excerpt(text, phrase, radius = 50)
  highlight(excerpt(text, phrase, radius: radius).to_s, phrase)
end

#render_search_form(options = {}) ⇒ Object

Renders a search form

It queries the controller and then redirects to the search result page.

Example search results page layout

Only performs the search if ferret is enabled in your config/alchemy/config.yml and a page is present that is flagged with searchresults true.

# config/alchemy/page_layouts.yml
- name: search
  searchresults: true # Flag as search result page

Note

The search result page will not be cached.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • html5 (Boolean) — default: true

    Should the search form be of type search or not?

  • class (String) — default: fulltext_search

    The default css class of the form

  • id (String) — default: search

    The default css id of the form



26
27
28
29
30
31
32
33
# File 'app/helpers/alchemy/pg_search/search_helper.rb', line 26

def render_search_form(options={})
  default_options = {
    html5: false,
    class: 'fulltext_search',
    id: 'search'
  }
  render 'alchemy/search/form', options: default_options.merge(options), search_result_page: search_result_page
end

#render_search_results(options = {}) ⇒ Object

Renders the search results partial within app/views/alchemy/search/_results.html

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • show_result_count (Boolean) — default: true

    Should the count of results be displayed or not?

  • show_heading (Boolean) — default: true

    Should the heading be displayed or not?



40
41
42
43
44
45
46
# File 'app/helpers/alchemy/pg_search/search_helper.rb', line 40

def render_search_results(options={})
  default_options = {
    show_result_count: true,
    show_heading: true
  }
  render 'alchemy/search/results', options: default_options.merge(options)
end