Skip to content

Instantly share code, notes, and snippets.

@ch1c0t
Last active June 17, 2017 19:57
Show Gist options
  • Save ch1c0t/b8ad141012e5ae7076961819142f2809 to your computer and use it in GitHub Desktop.
Save ch1c0t/b8ad141012e5ae7076961819142f2809 to your computer and use it in GitHub Desktop.
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