-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Manual #140
Comments
An example for http://pickyrb.com/documentation.html#tokenizing-options. It is a variant of your main example. It might be useful for the manual. It would be a good idea to mention somewhere that results would not find #!/usr/bin/env ruby
require 'picky'
# Create an index which is saved into './index' when you
# run index.dump(). Note that :id is implied - every input
# object must supply an :id!
#
index = Picky::Index.new :people do
# Tokenizing will allow indexing expressions such as `picky` as picky.
# Index only contains tokens greater than or equal to 3 characters.
indexing removes_characters: %r{[^a-z0-9\s\/\-\_\:\"\&\.]}i,
splits_text_on: %r{[\s/\-\_\:\"\&/\.]},
rejects_token_if: lambda { |token| token.size < 3 }
category :age
category :name
end
# Define a data input class. Any object that responds to
# :id, :age, :name can be added to the index.
#
Person = Struct.new :id, :age, :name
# Add some data objects to the index.
# IDs can be any unique string or integer.
#
index.add Person.new(1, 34, 'Florian is the author of `picky`')
index.add Person.new(2, 77, '[Picky] is {not} [person]')
index.add Person.new(3, 150, 'Ian likes picky')
# Create a search interface object.
#
people = Picky::Search.new index do
# Tokenizing will allow the search to find picky in expressions such as `picky`.
# Search only search for tokens greater than or equal to 3 characters.
searching removes_characters: %r{[^a-z0-9\s\/\-\_\:\"\&\.]}i,
splits_text_on: %r{[\s/\-\_\:\"\&/\.]},
rejects_token_if: lambda { |token| token.size < 3 }
end
# Do multiple searches and display the results.
#
['picky', 'pic', 'pi'].each do |word|
results = people.search word
# Show the results.
#
p results.ids # => each iteration produce one array: [3, 2, 1], [3, 2, 1], []
end |
Updated the previous post a few times. Hopefully the example is to your liking. |
Excellent! Thank you so much :) |
http://florianhanke.com/picky/documentation.html#search The following should be mentioned about the search results:
Shouldn't it return all results by default? It gave me some troubles until I figured out that it was limited. Either way, it should be stipulated in the manual. |
@backorder Probably the default should be all. Very good point, and something to do for version 5.0. |
People who offered to give feedback:
The text was updated successfully, but these errors were encountered: