Searchkick without stemming

481 views Asked by At

I am indexing some of my data with searchkick (https://github.com/ankane/searchkick) as an array and it works almost fine :)

def search_data
  {isbn: isbn, 
   title: title, 
   abstract_long: abstract_long,
   authors: authors.map(&:name)}
end

The field I'm interested in is authors. What I'd like to accomplish is to search for "Marias" and find all the authors that actually have that exact string in their surname like (Javier Marias) and not all the Maria/Mario/Marais that Searchkick returns, and have them with a much bigger priority.

This is how I search right now

Book.search(@search_key,
            fields: [:authors, :title, {isbn: :exact}],
            boost_by: {authors: 10, title: 5, isbn: 1})

Is this possible at all? TIA

1

There are 1 answers

0
brookz On

In Elasticsearch it has a regular match to deal with this case, but abandoned by Searchkick. You could choose a walk around way for this case:

def search_data
  {
    isbn: isbn, 
    title: title, 
    abstract_long: abstract_long,
    author_ids: authors.map(&:id)
  }
end

For search:

author_ids = Author.where(surname: 'Marias').map(&:id)
Book.search(
  @search_key,
  where: {author_ids: {in: author_ids}},
  fields: [:title, {isbn: :exact}],
  boost_by: {title: 5, isbn: 1}
)