fuzzily

Information about fuzzily

Published on August 11, 2014

Author: quangvutran940

Source: authorstream.com

Content

PowerPoint Presentation: FUZZILY Fuzzy string matching for ActiveRecord PowerPoint Presentation: What is fuzzy searching? - In computer science, approximate string matching (often colloquially referred to as fuzzy string searching) is the technique of finding strings that match a pattern approximately (rather than exactly). PowerPoint Presentation: About Fuzzily - Fuzzily finds misspelled, prefix, or partial needles in a haystack of strings. It's a fast, trigram-based, database-backed fuzzy string search/match engine for Rails - Tested with ActiveRecord (2.3, 3.0, 3.1, 3.2, 4.0) on various Rubies (1.8.7, 1.9.3, 2.0.0, 2.1.0) and the most common adapters (SQLite3, MySQL, and PostgreSQL) PowerPoint Presentation: Installation Add this line to your application's Gemfile: gem 'fuzzily' - And then execute: $ bundle install PowerPoint Presentation: Using fuzzily - You'll need to setup 2 things: + A trigram model (your search index) and its migration + The model you want to search for PowerPoint Presentation: Using fuzzily - Create and ActiveRecord model (this will be used to store a "fuzzy index" of all the models and fields you will be indexing): class Trigram < ActiveRecord::Base include Fuzzily::Model end - Create a migration for it: class AddTrigramsModel < ActiveRecord::Migration extend Fuzzily::Migration end - Instrument your model: class MyStuff < ActiveRecord::Base # assuming my_stuffs has a 'name' attribute fuzzily_searchable :name end PowerPoint Presentation: Indexing more than one field class MyStuff < ActiveRecord::Base fuzzily_searchable :name_fr, :name_en fuzzily_searchable :name_de end - Just list all the field you want to index, or call fuzzily_searchable more than once: PowerPoint Presentation: Custom name for the index model class CustomTrigram < ActiveRecord::Base include Fuzzily::Model end class AddTrigramsModel < ActiveRecord::Migration extend Fuzzily::Migration self.trigrams_table_name = :custom_trigrams end class MyStuff < ActiveRecord::Base fuzzily_searchable :name, :class_name => 'CustomTrigram' end - If you want or need to name your index model differently (because you already have a class called Trigram ): PowerPoint Presentation: UUID's (Universally Unique IDentifier) - When using Rails 4 with UUID's, you will need to change the owner_id column type to UUID: class AddTrigramsModel < ActiveRecord::Migration extend Fuzzily::Migration trigrams_owner_id_column_type = :uuid end PowerPoint Presentation: Searching virtual attributes class Employee < ActiveRecord::Base fuzzily_searchable :name def name "#{first_name} #{last_name}" end end - Your searchable fields do not have to be stored, they can be dynamic methods too. Just remember to add a virtual change method as well: PowerPoint Presentation: FUZZILY Thanks for watching :) -Ben-

Related presentations