Created
April 4, 2015 20:53
-
-
Save janko/9823f7b9d9f0a272dda3 to your computer and use it in GitHub Desktop.
Sequel's vritual rows are awesome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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