1

I have used gem searchkick & gem neo4j

class User
  include Neo4j::ActiveNode

  property :first_name
  property :last_name
  property :email

  searchkick callbacks: :async

  def search_data
    {
      first_name: first_name,
      last_name: last_name,
      email: email
    }
  end
end

(User.search 'suresh', fields: [:first_name, :last_name]).count => 22

(User.search 'sures', fields: [:first_name, :last_name]).count => 0

I want to have all result even if I type Su , please help me?

Brian suggestion

(User.search('su', fields: [:first_name, :last_name], misspellings: {edit_distance: 2})).map(&:first_name)

=> ["Sam", "Marilet", "aa", "asd", "Maricel"]

(User.search('sure', fields: [:first_name, :last_name], misspellings: {edit_distance: 3})).map(&:first_name)

=> ["Herlinda", "Brent", "Andy", "suresh"]

Vishal G
  • 1,521
  • 11
  • 30

2 Answers2

1

You should be able to use the edit_distance option:

https://github.com/ankane/searchkick#misspellings

Example:

User.search('suresh', fields: [:first_name, :last_name], misspellings: {edit_distance: 2})
Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
0

After looking at @brains suggestion and bit more research I was able to achieve it by following changes

Updated Model looks like :

class User
  include Neo4j::ActiveNode

  property :first_name
  property :last_name
  property :email

  searchkick word_start: [:first_name, :last_name]


  def search_data
    {
      first_name: first_name,
      last_name: last_name
    }
end

Updated query looks like :

  users = User.search('su', operator: "or",
                                    fields: [:first_name, :last_name],
                                    misspellings: {below: 5},
                                    match: :word_start,
                                    where: {id: mutual_stay_pal_ids},
                                    page: params[:page], per_page: 10)

After changes do not forget to re-index the data User.reindex

Vishal G
  • 1,521
  • 11
  • 30