Skip to content
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

Open
floere opened this issue Feb 2, 2015 · 5 comments
Open

Improve Manual #140

floere opened this issue Feb 2, 2015 · 5 comments

Comments

@floere
Copy link
Owner

floere commented Feb 2, 2015

People who offered to give feedback:

@IanTrudel
Copy link

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 picky nor [picky] without tokenizing, the results would be [3], [3], [].

#!/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

@IanTrudel
Copy link

Updated the previous post a few times. Hopefully the example is to your liking.

@floere
Copy link
Owner Author

floere commented Feb 4, 2015

Excellent! Thank you so much :)

@IanTrudel
Copy link

http://florianhanke.com/picky/documentation.html#search

The following should be mentioned about the search results:

Default search query returns up to 20 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.

@floere
Copy link
Owner Author

floere commented Feb 5, 2015

@backorder Probably the default should be all. Very good point, and something to do for version 5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants