Searchkick Enhances Exact Matching

I have 15,000 courses, and I would like to increase the name of each class, so the exact match of the class rises above everything else.

When I do Course.seach_kick ("theory of interest", 1) The correct search returns with the course "theory of interest" as the first result.

However, when I do Course.search_kick ("theory of interest 3618", 1)
3618 is a catalog; results are not returned. I was expecting a return to the theory of interest and returned first. The search seems to be looking for a complete theory of interest 3618, which will be included in the heading of the course.

I understand that "and" is the default operator. Is the requirement to use the "or" operator mandatory? I hesitate to use the "or" operator due to unexpected results.

Thank you, I really enjoy using the gem.

search method:

def self.search_kick(query, page) search(query, fields: ["title^10", "description", "crse_id", "subject", "catalog_number" ], facets: [:subject], misspellings: false, page: page, per_page: 20 ) end def search_data { title: title, description: description, crse_id: crse_id, subject: subject, catalog_number: catalog_nbr } end 
+6
source share
1 answer

Why not filter catalog_number in the where section:

 search(query, fields: ["title^10", "description", "crse_id", "subject" ], facets: [:subject], misspellings: false, where: {catalog_number: 3618}, page: page, per_page: 20 ) 

In most cases, the where clause comes from IF:

 conditions = {} if params[:catalog_number].present? conditions[:catalog_number] = params[:catalog_number].to_i end search(query, fields: ["title^10", "description", "crse_id", "subject" ], facets: [:subject], misspellings: false, where: conditions, page: page, per_page: 20 ) 

You can insert as many filters as possible into the where clause, just like ActiveRecord.where ()

docs ref: https://github.com/ankane/searchkick#queries

+2
source

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


All Articles