Skip to content

Instantly share code, notes, and snippets.

@janko
Created April 4, 2015 20:53
Show Gist options
  • Save janko/9823f7b9d9f0a272dda3 to your computer and use it in GitHub Desktop.
Save janko/9823f7b9d9f0a272dda3 to your computer and use it in GitHub Desktop.
Sequel's vritual rows are awesome
Movie.select(
:year,
"ts_headline(title, to_tsquery('#{query}'), 'StartSel = <strong>, StopSel = </strong>, HighlightAll = true') AS title",
"ts_headline(plot, to_tsquery('#{query}'), 'StartSel = <strong>, StopSel = </strong>, HighlightAll = true') AS plot",
"ts_headline(episode, to_tsquery('#{query}'), 'StartSel = <strong>, StopSel = </strong>, HighlightAll = true') AS episode"
)
# It's all Ruby now, so you can use all of the tricks you know :)
Movie.select{[
year,
*[:title, :plot, :episode].map do |column|
ts_headline(
__send__(column),
to_tsquery(query),
"StartSel = <strong>, StopSel = </strong>, HighlightAll = true"
).as(column)
end
]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment