Created
January 31, 2012 12:17
-
-
Save Overbryd/1710233 to your computer and use it in GitHub Desktop.
Picky on MacRuby example script
This file contains 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
# 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', '🐒', 'MONKEY'), | |
Utf8Symbol.new(2, '๐ต', 'f09f90b5', '🐵', 'MONKEY FACE'), | |
Utf8Symbol.new(3, '๐', 'f09f9988', '🙈', 'SEE-NO-EVIL MONKEY'), | |
Utf8Symbol.new(4, '๐', 'f09f9989', '🙉', 'HEAR-NO-EVIL MONKEY'), | |
Utf8Symbol.new(5, '๐', 'f09f998a', '🙊', '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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
So that's where those evil monkeys are...!