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.34k stars 371 forks source link

Highlight returning strange test #455

Closed npearson72 closed 3 years ago

npearson72 commented 3 years ago

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?

npearson72 commented 3 years ago

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

results.first.pg_search_highlight_field