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