0
votes

I have product model that had name, gender, description etc columns and those columns are included in elasticsearch index via search_data method.

Let's assume that I have a product with following values

name: 'No Boyfriend No Problem Crop Jumper'
gender : 'women'
description: 'Best crop jumber for now'

When I search with a term "women crop jumper"

The product doesn't appear in the search result. I am trying to search the products with following query

@products = Product.search(
              params[:q],
              fields: [:gender, :name, :description],
              match: :word_start,
              page: params[:page],
              per_page: Product::PAGE
            )

How should I update my product search so that "women crop jumper" search terms result will include the product above.

Thanks

1

1 Answers

0
votes

Looks like this isn't possible as of right now. However, you could do the following and it should work:

def search_data
  {
    name: name,
    gender: gender,
    description: description,
    all_fields: [name, gender, description].compact.join(' ')
  }
end

Then you can just search the all_fields field in your query.