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
@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