Sha256: 6e1023fe8fbf4a08dbe5f41bda6f0bcf19a125dc40067b5e3c3f497324cc72db

Contents?: true

Size: 1.62 KB

Versions: 21

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8
#
require 'spec_helper'

describe 'similarity' do
  it 'does Soundex' do
    index = Picky::Index.new :phonetic do
      indexing removes_characters: /[^a-z\s]/i
      category :text, similarity: Picky::Similarity::Soundex.new(1)
    end

    index.replace_from id: 1, text: "Peter"

    try = Picky::Search.new index

    # No ~, no similarity.
    #
    try.search("text:petor").ids.should == []

    # Finds soundex-similar text.
    #
    try.search("text:petor~").ids.should == [1]

    # Finds the identity.
    #
    try.search("text:peter~").ids.should == [1]
  end
  it 'does Metaphone' do
    index = Picky::Index.new :phonetic do
      indexing removes_characters: /[^a-z\s]/i
      category :text, similarity: Picky::Similarity::Metaphone.new(1)
    end

    index.replace_from id: 1, text: "Peter"

    try = Picky::Search.new index

    # No ~, no similarity.
    #
    try.search("text:pdr").ids.should == []

    # Finds soundex-similar text.
    #
    try.search("text:pdr~").ids.should == [1]

    # Finds the identity.
    #
    try.search("text:peter~").ids.should == [1]
  end
  it 'does DoubleMetaphone' do
    index = Picky::Index.new :phonetic do
      indexing removes_characters: /[^a-z\s]/i
      category :text, similarity: Picky::Similarity::DoubleMetaphone.new(1)
    end

    index.replace_from id: 1, text: "Peter"

    try = Picky::Search.new index

    # No ~, no similarity.
    #
    try.search("text:pdr").ids.should == []

    # Finds soundex-similar text.
    #
    try.search("text:pdr~").ids.should == [1]

    # Finds the identity.
    #
    try.search("text:peter~").ids.should == [1]
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
picky-4.31.3 spec/functional/similarity_spec.rb
picky-4.31.2 spec/functional/similarity_spec.rb
picky-4.31.1 spec/functional/similarity_spec.rb
picky-4.31.0 spec/functional/similarity_spec.rb
picky-4.30.0 spec/functional/similarity_spec.rb
picky-4.29.0 spec/functional/similarity_spec.rb
picky-4.28.1 spec/functional/similarity_spec.rb
picky-4.27.1 spec/functional/similarity_spec.rb
picky-4.27.0 spec/functional/similarity_spec.rb
picky-4.26.2 spec/functional/similarity_spec.rb
picky-4.26.1 spec/functional/similarity_spec.rb
picky-4.26.0 spec/functional/similarity_spec.rb
picky-4.25.3 spec/functional/similarity_spec.rb
picky-4.25.2 spec/functional/similarity_spec.rb
picky-4.25.1 spec/functional/similarity_spec.rb
picky-4.25.0 spec/functional/similarity_spec.rb
picky-4.24.0 spec/functional/similarity_spec.rb
picky-4.23.2 spec/functional/similarity_spec.rb
picky-4.23.1 spec/functional/similarity_spec.rb
picky-4.23.0 spec/functional/similarity_spec.rb