Last active
December 12, 2015 03:48
-
-
Save rogerbraun/4709109 to your computer and use it in GitHub Desktop.
Picky Realtime Indexing
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
require 'bundler' | |
Bundler.require | |
BookIndex = Picky::Index.new :books do | |
category "titel" | |
category "autor" | |
category "hrsg" | |
category "signatur" | |
category "jahr" | |
category "kommentar" | |
category "anmerkungen" | |
category "auflage" | |
category "baende" | |
category "bearbeiter" | |
category "bestelladresse" | |
category "drehbuch" | |
category "format" | |
category "inhalt" | |
category "sprache" | |
category "literaturvorlage" | |
category "nebensignatur" | |
category "ort" | |
category "platz" | |
category "preis" | |
category "publikationsart" | |
category "reihe" | |
category "seiten" | |
category "stifter" | |
category "verlag" | |
category "standort" | |
category "datensatz" | |
category "aufnahmedatum" | |
category "issn" | |
category "isbn" | |
category "invent" | |
category "autor_japanisch" | |
category "hrsg_japanisch" | |
category "drehbuch_japanisch" | |
category "reihe_japanisch" | |
category "titel_japanisch" | |
category "verlag_japanisch" | |
category "literaturvorlage_japanisch" | |
category "nacsis_japanisch" | |
category "jid" | |
category "nacsis_url" | |
category "interne_notizen" | |
category "created_at" | |
category "updated_at" | |
category "vormerken" | |
category "altes_datum" | |
indexing removes_characters: /[^\p{Han}\p{Hiragana}\p{Katakana}a-zA-Z0-9\.\s]/u, | |
substitutes_characters_with: Picky::CharacterSubstituters::WestEuropean.new, | |
splits_text_on: /\s/u | |
end | |
class TestApp < Sinatra::Base | |
extend Picky::Sinatra::IndexActions | |
end | |
require 'rack/test' | |
class TestRunner | |
include Rack::Test::Methods | |
def app | |
@app ||= TestApp | |
end | |
def rand_data i | |
h = {} | |
BookIndex.categories.each do |c| | |
h[c.name] = "Lorem ipsum dolor sit amet #{c.name} #{i}" | |
end | |
h[:id] = i | |
MultiJson.encode(h) | |
end | |
def generate_data | |
@data = [] | |
0.upto(100) do |i| | |
@data << rand_data(i) | |
end | |
end | |
def fill_index backend | |
BookIndex.backend backend | |
@data.each do |datum| | |
put "/", {index: "books", data: datum} | |
end | |
end | |
def run | |
puts "\n" | |
backends = [Picky::Backends::Memory.new, Picky::Backends::Redis.new({realtime: true})] | |
backends.each do |backend| | |
puts "Trying #{backend.class}" | |
generate_data | |
start_time = Time.now | |
fill_index backend | |
stop_time = Time.now | |
puts "Time in seconds:" | |
puts stop_time - start_time | |
end | |
end | |
end | |
TestRunner.new.run | |
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
gem 'picky' | |
gem 'redis' | |
gem 'sinatra', require: 'sinatra/base' | |
gem 'rack-test' | |
gem 'pry' |
LOL.
Complete fail on my part – of course it is fast on 4.12.7: the server does not use PUT with that version, resulting in 404s. Please ignore all comments.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
4.12.8 is bad also, the change has been introduced in 4.12.8.