Searchkick does not search for multiple terms when specifying fields

Can anyone give advice on the following request?

I use searchkick / elasticsearch and would like to find a key term or terms in multiple fields (name, manufacturer). For example, if I search for a product called "myproduct" made by my "somemanufacturer", I expect to see this result if I search for "myproduct", "somemanufacturer" or "myproduct somemanufacturer", because both of these conditions are included either in the namespace or manufacturer.

My problem is this:

@products = Product.search query

Allows all search terms listed above and returns the expected result, however, as soon as I add

@products = Product.search query, fields: [:name, :manufacturer_name]

It will return the result only for "myproduct" or "somecompany", but not "myproduct somecompany".

Now this does not really matter, since I can completely remove the field parameters, but I need to use the search words word_start for the name field. So my last request looks something like this:

@products = Product.search query, fields: [{name: :word_start}, :manufacturer_name]

I would like users to search for the first line of the product and be able to enter the manufacturer, for example, β€œmyprod somecompany”, unfortunately, this returns zero results when I hoped that it would return a product named myproduct made by somecompany.

Did I miss something really obvious here? I can change add

operator: 'or'

but actually I want to be able to split the search by name, add additional terms and if they are present for a particular record, it is returned.

heres

class Product < ActiveRecord::Base
 searchkick word_start: [:name]
end

+4
1

, elasticsearch, cross_fields. , query_string. , searchkick cross_fields query_string. , .

( )

searchkick merge_mappings: true, mappings: {
  product: {
    properties: {
      name: {
        type: 'string',
        analyzer: 'searchkick_word_start_index',
        copy_to: 'grouped'
      },
      manufacturer_name: {
        type: 'string',
        analyzer: 'default_index',
        copy_to: 'grouped'
      },
      grouped: {
        raw: {type: 'string', index: 'not_analyzed'}
      }
    }
  }
}

cross_fields

@products = Product.search(body: {
  query: {
     multi_match: {
                  query: query,
                  type: "cross_fields",
                  operator: "and",
                  fields: [
                      "name",
                      "manufacturer_name",
                      "grouped",
                  ]
              }
         }
}

query_string

@products = Product.search(body: {
  query: {
      query_string: {
                  query: query,
                  default_operator: "AND",
                  fields: [
                      "name",
                      "manufacturer_name",
                      "grouped",
                  ]
              }
         }
}

- , .

, elasticsearch , searchkick , , , elasticsearch.

hightlight

@products = Product.search(body: {
  query: {
    ...
  }, highlight: {
    fields: {
      name: {},
      manufacturer_name: {}
    }
  }

@products = Product.search(body: {
  query: {
    bool: {
      must: {
        dis_max: {
          queries: {
            query_string: {
              ...
            }
          }
        }
      },
      should: {
        nested: {
          path: 'conversions',
          score_mode: 'sum',
          query: {
            function_score: {
              boost_mode: 'replace',
              query: {
                match: {
                  "conversions.query": query
                }
              },
              field_value_factor: {
                field: 'conversions.count'
              }
            }
          }
        }
      }
    }
  }
+4

Source: https://habr.com/ru/post/1608696/


All Articles