Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search

Home Page:http://www.casebook.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Highlight returning strange test

npearson72 opened this issue · comments

Here is my pg_seach_scope

  pg_search_scope :search,
                  against: [:tsv],
                  using: {
                    tsearch: {
                      prefix: true,
                      negation: true,
                      dictionary: 'english',
                      tsvector_column: 'tsv',
                      highlight: {
                        StartSel: '<b>',
                        StopSel: '</b>',
                        MaxWords: 123,
                        MinWords: 456,
                        ShortWord: 4,
                        HighlightAll: true,
                        MaxFragments: 3,
                        FragmentDelimiter: '&hellip;'
                      }
                    }
                  }

I'm getting query logs in my results when I use highlight:

[6] pry(main)> results.highlight
=> "(ts_headline('english', (coalesce(\"searches\".\"tsv\"::text, '')), (to_tsquery('english', ''' ' || 'zapat' || ' ''' || ':*') && to_tsquery('english', ''' ' || 'restaurant' || ' ''' || ':*')), 'StartSel = \"<b>\", StopSel = \"</b>\", MaxFragments = 3, MaxWords = 123, MinWords = 456, ShortWord = 4, FragmentDelimiter = \"&hellip;\", HighlightAll = TRUE'))"
[7] pry(main)> results.pg_search_highlight_field
=> "((ts_headline('english', (coalesce(\"searches\".\"tsv\"::text, '')), (to_tsquery('english', ''' ' || 'zapat' || ' ''' || ':*') && to_tsquery('english', ''' ' || 'restaurant' || ' ''' || ':*')), 'StartSel = \"<b>\", StopSel = \"</b>\", MaxFragments = 3, MaxWords = 123, MinWords = 456, ShortWord = 4, FragmentDelimiter = \"&hellip;\", HighlightAll = TRUE'))) AS pg_search_highlight, searches.*"

Any ideas?

Turns out I needed to work with the individual records, not the relation. Calling the following works:

results.first.pg_search_highlight_field