Searchkick not retrieving results properly

22 Views Asked by At

I'm trying to retrieve categories using searchkick, here's the class:

class Category < ApplicationRecord
  searchkick
  has_many :localized_categories, :dependent => :destroy
  scope :search_import, -> { includes(:localized_categories) }

  def search_data
    {
      id: id,
      name: localized_categories.map{ |lc| lc.local_name(language_id) }
    }
  end

  def language_id
    # a method that returns 'en', 'es', 'it' and any other code depending on the case
  end
end

I have a category called "butterfly", when I do:

Category.reindex
Category.search(
    'butterfl',
    where: { category_type_id: 6 },
    limit: 5,
    misspellings: { edit_distance: 2 }
)

It returns the category, but when I remove more characters from the search it returns nothing

Category.reindex
Category.search(
    'butterf',
    where: { category_type_id: 6 },
    limit: 5,
    misspellings: { edit_distance: 2 }
)

I checked out with other categories and it's always the same case, with 2 character less, it doesn't return anything.

I need it to return the right categories with at least 3 characters in the query.

Things I already tried and didn't work: Partial Matches (word, word_start, word_middle and all the other ones), Exact Matches, Phrase Matches, changing the edit_distance (1, 3 and 10), join the name into a string separated by spaces (from name: ['butterfly', 'libelula'] to name: 'butterfly libelula')

0

There are 0 best solutions below