Project

fuzzzy

0.0
No commit activity in last 3 years
No release in over 3 years
Fuzzy Search client and server
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.4.7
>= 0
>= 2
~> 0.6.0

Runtime

 Project Readme

Fuzzzy

The fuzzy search with redis-stored indexes.

Build Status

Install and configuration

Add to Gemfile:

gem 'fuzzzy'

and run bundle install

Configuration is very simple:

Fuzzzy.configure do |config|
  config.logger = Logger.new($stdout)
  config.redis = Redis.new(
    :host => 'localhost',
    :port => 6379,
    :database => 0
  )
  config.stopwords = %w{the stopwords list}
end

Put this code in initializers folder if you use rails or at the beginning of the application otherwise.

Usage

There are several ways to use:

  • As standalone module.

  • As MongoId module.

  • As HTTP server.

As standalone module

class CitySearch
  include Fuzzzy::Index
  
  def search context
    _searcher.search(context)
  end
  
  def create_index context
    _indexer.create_index(context)
  end
  
  def delete_index context
    _indexer.delete_index(context)
  end
end

s = CitySearch.new
s.create_index(
  :method => :ngram,
  :index_name => 'city',
  :dictionary_string => 'Moscow',
  :id => '1'
)
s.create_index(
  :method => :ngram,
  :index_name => 'city',
  :dictionary_string => 'Rom',
  :id => '2'
)

result = s.search({
  :method => :ngram,
  :index_name => 'city',
  :query => 'Moskow',
  :distance => 1
})

puts result # 1

As MongoId module

class City
  include Mongoid::Document
  include Fuzzzy::Mongoid::Index

  field :name, :type => String
  
  define_fuzzzy_index :name, :method => :ngram
end

City.create(:name => 'Moscow')
City.create(:name => 'Rom')

pp City.search(:query => 'Moskow', :distance => 1)

As HTTP server