Fix search for base skills

Before they didn't really show up at all, then they showed up on everything, then they showed up on EX1 and EX2, now they only show up on EX2.
This commit is contained in:
Justin Edmund 2022-12-03 18:34:38 -08:00
parent fc7cde4c5a
commit a8301019f5

View file

@ -12,14 +12,14 @@ class Api::V1::SearchController < Api::V1::ApiController
# conditions[:series] = filters['series'] unless filters['series'].blank? || filters['series'].empty?
end
if search_params[:query].present? && search_params[:query].length >= 2
@characters = if search_params[:query].present? && search_params[:query].length >= 2
if locale == 'ja'
@characters = Character.jp_search(search_params[:query]).where(conditions)
Character.jp_search(search_params[:query]).where(conditions)
else
@characters = Character.en_search(search_params[:query]).where(conditions)
Character.en_search(search_params[:query]).where(conditions)
end
else
@characters = Character.where(conditions)
Character.where(conditions)
end
@count = @characters.length
@ -38,14 +38,14 @@ class Api::V1::SearchController < Api::V1::ApiController
conditions[:series] = filters['series'] unless filters['series'].blank? || filters['series'].empty?
end
if search_params[:query].present? && search_params[:query].length >= 2
@weapons = if search_params[:query].present? && search_params[:query].length >= 2
if locale == 'ja'
@weapons = Weapon.jp_search(search_params[:query]).where(conditions)
Weapon.jp_search(search_params[:query]).where(conditions)
else
@weapons = Weapon.en_search(search_params[:query]).where(conditions)
Weapon.en_search(search_params[:query]).where(conditions)
end
else
@weapons = Weapon.where(conditions)
Weapon.where(conditions)
end
@count = @weapons.length
@ -62,14 +62,14 @@ class Api::V1::SearchController < Api::V1::ApiController
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty?
end
if search_params[:query].present? && search_params[:query].length >= 2
@summons = if search_params[:query].present? && search_params[:query].length >= 2
if locale == 'ja'
@summons = Summon.jp_search(search_params[:query]).where(conditions)
Summon.jp_search(search_params[:query]).where(conditions)
else
@summons = Summon.en_search(search_params[:query]).where(conditions)
Summon.en_search(search_params[:query]).where(conditions)
end
else
@summons = Summon.where(conditions)
Summon.where(conditions)
end
@count = @summons.length
@ -85,38 +85,44 @@ class Api::V1::SearchController < Api::V1::ApiController
# Set the conditions based on the group requested
conditions = {}
if search_params[:filters].present? && search_params[:filters]["group"].present?
group = search_params[:filters]["group"].to_i
if search_params[:filters].present? && search_params[:filters]['group'].present?
group = search_params[:filters]['group'].to_i
if (group >= 0 && group < 4)
if group >= 0 && group < 4
conditions[:color] = group
conditions[:emp] = false
conditions[:base] = false
elsif (group == 4)
elsif group == 4
conditions[:emp] = true
elsif (group == 5)
elsif group == 5
conditions[:base] = true
end
end
# Perform the query
if search_params[:query].present? && search_params[:query].length >= 2
@skills = JobSkill.method("#{locale}_search").(search_params[:query])
@skills = if search_params[:query].present? && search_params[:query].length >= 2
JobSkill.method("#{locale}_search").call(search_params[:query])
.where(conditions)
.where(job: job.id, main: false)
.or(
JobSkill.method("#{locale}_search").(search_params[:query])
JobSkill.method("#{locale}_search").call(search_params[:query])
.where(conditions)
.where(sub: true)
)
else
@skills = JobSkill.all
JobSkill.all
.where(conditions)
.where(job: job.id, main: false)
.or(
JobSkill.all
.where(conditions)
.where(sub:true)
.where(sub: true)
)
.or(
JobSkill.all
.where(conditions)
.where(job: job.base_job.id, base: true)
.where.not(job: job.id)
)
end