Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search
http://www.casebook.net
MIT License
1.3k stars 369 forks source link

Enhance Highlight Customization using the columns Option #516

Open mmarusyk opened 1 year ago

mmarusyk commented 1 year ago

Enhance Highlight Customization using the columns Option

This pull request introduces the utilization of the columns option to create customized highlighting for search results in the PgSearch module. The enhancement offers a more flexible and tailored way to generate pg_search_<custom_name>_highlight columns based on specified columns within the model.

Example:


pg_search_scope :search_by_keyword, against: {
    title: 'A',
    body: 'B',
    summary: 'C'
  }, using: {
    tsearch: {
      prefix: true,
      highlight: {
        fields: {
          title: :title,
          content: %i[body summary]
        }
        StartSel: '<mark>',
        StopSel: '</mark>'
      }
    }
  }

Article.by_keyword('account').first.pg_search_title_highlight
=> "How to create <mark>account</mark>?"

Article.by_keyword('account').first.pg_search_content_highligh
 => Select New Agency <mark>Account</mark> and after you create your agency, the <mark>Account</mark> is here."