Last active
June 17, 2017 19:57
-
-
Save ch1c0t/b8ad141012e5ae7076961819142f2809 to your computer and use it in GitHub Desktop.
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
Bundler.require | |
book = Gutenberg::Book.new_from_txt 'data/pg11.txt' | |
db = Sequel.sqlite | |
db.run "CREATE VIRTUAL TABLE units USING fts5(content);" | |
units = db[:units] | |
db.transaction do | |
book.each_with_index do |unit, index| | |
units << { rowid: index, content: unit } | |
end | |
end | |
#query = '"all their simple"' | |
query = '"that would be"' | |
limit = 3 | |
db['SELECT rowid,* FROM units WHERE units MATCH ? LIMIT ?', query, limit].each do |row| | |
p row | |
end | |
# units[rowid: 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment