Created
November 6, 2012 21:42
-
-
Save floere/4027781 to your computer and use it in GitHub Desktop.
Infix search example (copy & paste)
This file contains hidden or 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 'picky' | |
Person = Struct.new :id, :age, :name | |
data = Picky::Index.new :people do | |
category :age, partial: Picky::Partial::None.new | |
category :name, partial: Picky::Partial::Infix.new(min: 1, max: -1) | |
end | |
data.replace Person.new(1, 34, 'Florian') | |
data.replace Person.new(2, 77, 'Elfriede') | |
people = Picky::Search.new data | |
p people.search '34 f' # Finds 1 (0.00013s). | |
results = people.search 'f' # Finds 1 and 2 (0.00004s). | |
p results # For logging | |
p results.allocations # => Returns ids, weight etc. |
Really cool, will try it out
🍺 to the octopus mastermind!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also give the index a source:
And call
Picky::Indexes.index
, ordata.index
before searching. This will call#each
onPerson.order('name DESC')
and index each thing it gets.