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

@ -1,133 +1,139 @@
class Api::V1::SearchController < Api::V1::ApiController class Api::V1::SearchController < Api::V1::ApiController
def characters def characters
filters = search_params[:filters] filters = search_params[:filters]
locale = search_params[:locale] || 'en' locale = search_params[:locale] || 'en'
conditions = {} conditions = {}
if filters if filters
conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty? conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty?
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty? conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty?
conditions[:proficiency1] = filters['proficiency1'] unless filters['proficiency1'].blank? || filters['proficiency1'].empty? conditions[:proficiency1] = filters['proficiency1'] unless filters['proficiency1'].blank? || filters['proficiency1'].empty?
conditions[:proficiency2] = filters['proficiency2'] unless filters['proficiency2'].blank? || filters['proficiency2'].empty? conditions[:proficiency2] = filters['proficiency2'] unless filters['proficiency2'].blank? || filters['proficiency2'].empty?
# conditions[:series] = filters['series'] unless filters['series'].blank? || filters['series'].empty? # conditions[:series] = filters['series'] unless filters['series'].blank? || filters['series'].empty?
end
if search_params[:query].present? && search_params[:query].length >= 2
if locale == 'ja'
@characters = Character.jp_search(search_params[:query]).where(conditions)
else
@characters = Character.en_search(search_params[:query]).where(conditions)
end
else
@characters = Character.where(conditions)
end
@count = @characters.length
@characters = @characters.paginate(page: search_params[:page], per_page: 10)
end end
def weapons @characters = if search_params[:query].present? && search_params[:query].length >= 2
filters = search_params[:filters] if locale == 'ja'
locale = search_params[:locale] || 'en' Character.jp_search(search_params[:query]).where(conditions)
conditions = {} else
Character.en_search(search_params[:query]).where(conditions)
end
else
Character.where(conditions)
end
if filters @count = @characters.length
conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty? @characters = @characters.paginate(page: search_params[:page], per_page: 10)
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty? end
conditions[:proficiency] = filters['proficiency1'] unless filters['proficiency1'].blank? || filters['proficiency1'].empty?
conditions[:series] = filters['series'] unless filters['series'].blank? || filters['series'].empty?
end
if search_params[:query].present? && search_params[:query].length >= 2 def weapons
if locale == 'ja' filters = search_params[:filters]
@weapons = Weapon.jp_search(search_params[:query]).where(conditions) locale = search_params[:locale] || 'en'
else conditions = {}
@weapons = Weapon.en_search(search_params[:query]).where(conditions)
end
else
@weapons = Weapon.where(conditions)
end
@count = @weapons.length if filters
@weapons = @weapons.paginate(page: search_params[:page], per_page: 10) conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty?
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty?
conditions[:proficiency] = filters['proficiency1'] unless filters['proficiency1'].blank? || filters['proficiency1'].empty?
conditions[:series] = filters['series'] unless filters['series'].blank? || filters['series'].empty?
end end
def summons @weapons = if search_params[:query].present? && search_params[:query].length >= 2
filters = search_params[:filters] if locale == 'ja'
locale = search_params[:locale] || 'en' Weapon.jp_search(search_params[:query]).where(conditions)
conditions = {} else
Weapon.en_search(search_params[:query]).where(conditions)
end
else
Weapon.where(conditions)
end
if filters @count = @weapons.length
conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty? @weapons = @weapons.paginate(page: search_params[:page], per_page: 10)
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty? end
end
if search_params[:query].present? && search_params[:query].length >= 2 def summons
if locale == 'ja' filters = search_params[:filters]
@summons = Summon.jp_search(search_params[:query]).where(conditions) locale = search_params[:locale] || 'en'
else conditions = {}
@summons = Summon.en_search(search_params[:query]).where(conditions)
end
else
@summons = Summon.where(conditions)
end
@count = @summons.length if filters
@summons = @summons.paginate(page: search_params[:page], per_page: 10) conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty?
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty?
end end
def job_skills @summons = if search_params[:query].present? && search_params[:query].length >= 2
raise Api::V1::NoJobProvidedError unless search_params[:job].present? if locale == 'ja'
Summon.jp_search(search_params[:query]).where(conditions)
else
Summon.en_search(search_params[:query]).where(conditions)
end
else
Summon.where(conditions)
end
# Set up basic parameters we'll use @count = @summons.length
job = Job.find(search_params[:job]) @summons = @summons.paginate(page: search_params[:page], per_page: 10)
locale = search_params[:locale] || 'en' end
# Set the conditions based on the group requested def job_skills
conditions = {} raise Api::V1::NoJobProvidedError unless search_params[:job].present?
if search_params[:filters].present? && search_params[:filters]["group"].present?
group = search_params[:filters]["group"].to_i
if (group >= 0 && group < 4) # Set up basic parameters we'll use
conditions[:color] = group job = Job.find(search_params[:job])
conditions[:emp] = false locale = search_params[:locale] || 'en'
conditions[:base] = false
elsif (group == 4)
conditions[:emp] = true
elsif (group == 5)
conditions[:base] = true
end
end
# Perform the query # Set the conditions based on the group requested
if search_params[:query].present? && search_params[:query].length >= 2 conditions = {}
@skills = JobSkill.method("#{locale}_search").(search_params[:query]) if search_params[:filters].present? && search_params[:filters]['group'].present?
.where(conditions) group = search_params[:filters]['group'].to_i
.where(job: job.id, main: false)
.or(
JobSkill.method("#{locale}_search").(search_params[:query])
.where(conditions)
.where(sub: true)
)
else
@skills = JobSkill.all
.where(conditions)
.where(job: job.id, main: false)
.or(
JobSkill.all
.where(conditions)
.where(sub:true)
)
end
@count = @skills.length if group >= 0 && group < 4
@skills = @skills.paginate(page: search_params[:page], per_page: 10) conditions[:color] = group
conditions[:emp] = false
conditions[:base] = false
elsif group == 4
conditions[:emp] = true
elsif group == 5
conditions[:base] = true
end
end end
private # Perform the 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").call(search_params[:query])
.where(conditions)
.where(sub: true)
)
else
JobSkill.all
.where(conditions)
.where(job: job.id, main: false)
.or(
JobSkill.all
.where(conditions)
.where(sub: true)
)
.or(
JobSkill.all
.where(conditions)
.where(job: job.base_job.id, base: true)
.where.not(job: job.id)
)
end
# Specify whitelisted properties that can be modified. @count = @skills.length
def search_params @skills = @skills.paginate(page: search_params[:page], per_page: 10)
params.require(:search).permit! end
end
private
# Specify whitelisted properties that can be modified.
def search_params
params.require(:search).permit!
end
end end