I am attempting to search for any premises that contains the animal 'cattle'. A premises can have multiple different animals. This search will work in any scenario apart from when the animal 'cattle' is not first in the field. E.g. if I search for 'Cattle' in the dropdown I will see all premises that contain cattle, only if it is listed first in the field. E.g. one field is 'Cattle', Horse'. This premises will still be found however, if it was 'Horse', 'Cattle' the premises will not be found in the search.
View:
= hidden_field_tag(:species, @species)
= text_field_tag(:search, @search, class: 'input-large search-query', placeholder: 'Search')
Controller
@species = params[:species].presence
if @species
prem_ids = StatevetDoc.unmatched.select(:holdings_match).where(default_species: @species).limit(@lines_per_page).collect { |doc| doc.holdings_match.values }.flatten.uniq[0,999]
@prems = @prems.where(id: prem_ids)
end