Created
October 26, 2011 06:29
-
-
Save floere/1315618 to your computer and use it in GitHub Desktop.
Running Picky e.g. in a single script.
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
# Possible since Picky 3.2.0. | |
# | |
require 'picky' | |
include Picky | |
Thing = Struct.new :id, :name | |
index = Index.new :test do | |
category :name, similarity: Similarity::DoubleMetaphone.new(3) | |
end | |
index.replace Thing.new(1, 'Picky') | |
index.replace Thing.new(2, 'Parslet') | |
things = Search.new(index) do | |
boost [:name] => +3 | |
end | |
p things.search("Pick").ids | |
p things.search("Pic").to_hash | |
p things.search("Parsley~").allocations |
Author
floere
commented
Oct 27, 2011
# Or even, replace them with.
#
class Proxy
def initialize things
@things = things
end
def search text
@things.search(text).to_hash
end
end
require 'msgpack/rpc'
svr = MessagePack::RPC::Server.new
svr.listen '127.0.0.1', 18800, Proxy.new(things)
svr.run
# Run it, and then open another file with
#
require 'msgpack/rpc'
c = MessagePack::RPC::Client.new '127.0.0.1', 18800
require 'benchmark'
p Benchmark.realtime { 1000.times { c.call :search, "Picky" } } # => 0.231717
# And run that :)
#
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment