Skip to content

Instantly share code, notes, and snippets.

@Overbryd
Created January 31, 2012 12:17
Show Gist options
  • Save Overbryd/1710233 to your computer and use it in GitHub Desktop.
Save Overbryd/1710233 to your computer and use it in GitHub Desktop.
Picky on MacRuby example script
# coding: utf-8
require 'rubygems'
# require fileutils to use FileUtils. Otherwise an error gets raised.
# uninitialized constant Picky::Backends::Helpers::File::FileUtils (NameError)
# from /Volumes/Home/Projects/utf8/picky/server/lib/picky/backends/prepared/text.rb:66:in `open'
#
require 'fileutils'
require 'picky'
include Picky
Utf8Symbol = Struct.new(:id, :symbol, :bytecode, :html_entity, :description)
symbols = [
Utf8Symbol.new(1, '๐Ÿ’', 'f09f9092', '&#128018', 'MONKEY'),
Utf8Symbol.new(2, '๐Ÿต', 'f09f90b5', '&#128053', 'MONKEY FACE'),
Utf8Symbol.new(3, '๐Ÿ™ˆ', 'f09f9988', '&#128584', 'SEE-NO-EVIL MONKEY'),
Utf8Symbol.new(4, '๐Ÿ™‰', 'f09f9989', '&#128585', 'HEAR-NO-EVIL MONKEY'),
Utf8Symbol.new(5, '๐Ÿ™Š', 'f09f998a', '&#128586', 'SPEAK-NO-EVIL MONKEY')
]
monkey_index = Index.new(:monkey_index) do
source { symbols }
indexing removes_characters: /[^a-z0-9\-\s\"\~\*\:\,]/i,
splits_text_on: /[\s\-]/
category :description
end
monkey_search = Search.new(monkey_index) do
searching removes_characters: /[^a-z0-9\-\s\/\_\&\.\"\~\*\:\,]/i, # Picky needs control chars *"~:, to pass through.
stopwords: /\b(and|the|of|it|in|for)\b/i,
splits_text_on: /[\s\/\-\&]+/
end
monkey_index.load rescue monkey_index.index
p evil_monkeys = monkey_search.search("evil").ids
@Overbryd
Copy link
Author

Overbryd commented Feb 1, 2012

Haha, shame on me... I've overseen the problem with the Struct initialization too. I'm more used to OpenStruct these days...
And indeed removes_characters: must keep the hyphen. So I changed those on indexing and searching.
Anyways, it works now! Thank you so much for your time you spend helping me out with this.

$ rm -rf index/; macruby picky-tryout.rb
.Picky is indexing using a single process: TD Done in 0s.
[3, 4, 5]

So that's where those evil monkeys are...!

@floere
Copy link

floere commented Feb 1, 2012

Now worries, glad to help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment