Skip to content

@floere /picky_in_a_script.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Running Picky e.g. in a single script.
# 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
@floere
Owner
# Or, replace the three last lines with:
#
require 'benchmark'

p Benchmark.measure { 1000.times { things.search("Picky") } }    # Exact, ... (  0.112894)
p Benchmark.measure { 1000.times { things.search("Pic") } }      # Partial, ... (  0.118742)
p Benchmark.measure { 1000.times { things.search("Parsley~") } } # Similar, ... (  0.203989)
@floere
Owner
# 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
Something went wrong with that request. Please try again.