picky icon indicating copy to clipboard operation
picky copied to clipboard

Improve Manual

Open floere opened this issue 10 years ago • 5 comments

People who offered to give feedback:

  • @BackOrder

floere avatar Feb 02 '15 20:02 floere

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 avatar Feb 04 '15 02:02 IanTrudel

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

IanTrudel avatar Feb 04 '15 02:02 IanTrudel

Excellent! Thank you so much :)

floere avatar Feb 04 '15 08:02 floere

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.

IanTrudel avatar Feb 05 '15 10:02 IanTrudel

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

floere avatar Feb 05 '15 15:02 floere