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



36
37
38
# File 'app/helpers/alchemy/pg_search/search_helper.rb', line 36

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
34
# 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",
  }
  search_result_page = Alchemy::Search::SearchPage.search_result_page
  render "alchemy/search/form", options: default_options.merge(options), search_result_page:
end