I have 15,000 courses and I would like to boost the title of each class so exact matches of a class are boosted above everything else.
When I do Course.seach_kick('theory of interest' , 1) The correct search is returned with the course 'theory of interest' as the first result.
However, when I do Course.search_kick('theory of interest 3618', 1)
3618 being the catalog_number, no results are returned. I expected the theory of interest course to be returned, and returned first. It seems the search is looking for the complete string 'theory of interest 3618' be included in the title of the course.
I understand 'and' is the default operator, Is it a requirement that I have to use the 'or' operator? I am hesitant to use the 'or' operator because of the unexpected results.
Thanks, 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
Why not filter catalog_number in where clause:
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, where clause comes from an 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 as possible filters into where clause, just the same as ActiveRecord.where()
docs ref: https://github.com/ankane/searchkick#queries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With