Compare commits
12 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 12544bd8ad | |||
| 3f734a0389 | |||
| b5f9889c00 | |||
| 70e820b781 | |||
| a82e1512c2 | |||
| 645fc07327 | |||
| c0b2c9502f | |||
| 193b1b7b2d | |||
| 56bb2ccf03 | |||
| 3ff89796d4 | |||
| 197aad8a8d | |||
| f154e898bc |
14 changed files with 148 additions and 30 deletions
10
app/blueprints/api/v1/search_blueprint.rb
Normal file
10
app/blueprints/api/v1/search_blueprint.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class SearchBlueprint < Blueprinter::Base
|
||||
identifier :searchable_id
|
||||
fields :searchable_type, :granblue_id, :name_en, :name_jp, :element
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -32,16 +32,18 @@ module Api
|
|||
|
||||
def update_uncap_level
|
||||
summon = @summon.summon
|
||||
max_uncap_level = if summon.flb && !summon.ulb
|
||||
max_uncap_level = if summon.flb && !summon.ulb && !summon.xlb
|
||||
4
|
||||
elsif summon.ulb
|
||||
elsif summon.ulb && !summon.xlb
|
||||
5
|
||||
elsif summon.xlb
|
||||
6
|
||||
else
|
||||
3
|
||||
end
|
||||
|
||||
greater_than_max_uncap = summon_params[:uncap_level].to_i > max_uncap_level
|
||||
can_be_transcended = summon.xlb && summon_params[:transcendence_step] && summon_params[:transcendence_step]&.to_i.positive?
|
||||
can_be_transcended = summon.xlb && summon_params[:transcendence_step] && summon_params[:transcendence_step]&.to_i&.positive?
|
||||
|
||||
uncap_level = if greater_than_max_uncap || can_be_transcended
|
||||
max_uncap_level
|
||||
|
|
@ -130,8 +132,8 @@ module Api
|
|||
|
||||
def render_grid_summon_view(grid_summon, conflict_position = nil)
|
||||
GridSummonBlueprint.render(grid_summon, view: :nested,
|
||||
root: :grid_summon,
|
||||
meta: { replaced: conflict_position })
|
||||
root: :grid_summon,
|
||||
meta: { replaced: conflict_position })
|
||||
end
|
||||
|
||||
def authorize
|
||||
|
|
|
|||
|
|
@ -23,19 +23,6 @@ module Api
|
|||
party.user = current_user if current_user
|
||||
party.attributes = party_params if party_params
|
||||
|
||||
# unless party_params.empty?
|
||||
# party.attributes = party_params
|
||||
#
|
||||
# # TODO: Extract this into a different method
|
||||
# job = Job.find(party_params['job_id']) if party_params['job_id'].present?
|
||||
# if job
|
||||
# job_skills = JobSkill.where(job: job.id, main: true)
|
||||
# job_skills.each_with_index do |skill, index|
|
||||
# party["skill#{index}_id"] = skill.id
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
if party.save!
|
||||
return render json: PartyBlueprint.render(party, view: :created, root: :party),
|
||||
status: :created
|
||||
|
|
@ -76,8 +63,8 @@ module Api
|
|||
new_party.local_id = party_params[:local_id] if !party_params.nil?
|
||||
|
||||
if new_party.save
|
||||
render json: PartyBlueprint.render(new_party, view: :created, root: :party,
|
||||
meta: { remix: true })
|
||||
render json: PartyBlueprint.render(new_party, view: :created, root: :party),
|
||||
status: :created
|
||||
else
|
||||
render_validation_error_response(new_party)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,49 @@
|
|||
module Api
|
||||
module V1
|
||||
class SearchController < Api::V1::ApiController
|
||||
TRIGRAM = {
|
||||
trigram: {
|
||||
threshold: 0.3
|
||||
}
|
||||
}.freeze
|
||||
|
||||
TSEARCH_WITH_PREFIX = {
|
||||
tsearch: {
|
||||
prefix: true,
|
||||
dictionary: 'simple'
|
||||
}
|
||||
}.freeze
|
||||
|
||||
def all
|
||||
locale = search_params[:locale] || 'en'
|
||||
|
||||
case locale
|
||||
when 'en'
|
||||
results = search_all_en
|
||||
when 'ja'
|
||||
results = search_all_ja
|
||||
end
|
||||
|
||||
render json: SearchBlueprint.render(results, root: :results)
|
||||
end
|
||||
|
||||
def search_all_en
|
||||
PgSearch.multisearch_options = { using: TRIGRAM }
|
||||
results = PgSearch.multisearch(search_params[:query]).limit(10)
|
||||
|
||||
if (results.length < 5) && (search_params[:query].length >= 2)
|
||||
PgSearch.multisearch_options = { using: TSEARCH_WITH_PREFIX }
|
||||
results = PgSearch.multisearch(search_params[:query]).limit(10)
|
||||
end
|
||||
|
||||
results
|
||||
end
|
||||
|
||||
def search_all_ja
|
||||
PgSearch.multisearch_options = { using: TSEARCH_WITH_PREFIX }
|
||||
PgSearch.multisearch(search_params[:query]).limit(10)
|
||||
end
|
||||
|
||||
def characters
|
||||
filters = search_params[:filters]
|
||||
locale = search_params[:locale] || 'en'
|
||||
|
|
@ -24,7 +67,7 @@ module Api
|
|||
|
||||
characters = if search_params[:query].present? && search_params[:query].length >= 2
|
||||
if locale == 'ja'
|
||||
Character.jp_search(search_params[:query]).where(conditions)
|
||||
Character.ja_search(search_params[:query]).where(conditions)
|
||||
else
|
||||
Character.en_search(search_params[:query]).where(conditions)
|
||||
end
|
||||
|
|
@ -62,7 +105,7 @@ module Api
|
|||
|
||||
weapons = if search_params[:query].present? && search_params[:query].length >= 2
|
||||
if locale == 'ja'
|
||||
Weapon.jp_search(search_params[:query]).where(conditions)
|
||||
Weapon.ja_search(search_params[:query]).where(conditions)
|
||||
else
|
||||
Weapon.en_search(search_params[:query]).where(conditions)
|
||||
end
|
||||
|
|
@ -95,7 +138,7 @@ module Api
|
|||
|
||||
summons = if search_params[:query].present? && search_params[:query].length >= 2
|
||||
if locale == 'ja'
|
||||
Summon.jp_search(search_params[:query]).where(conditions)
|
||||
Summon.ja_search(search_params[:query]).where(conditions)
|
||||
else
|
||||
Summon.en_search(search_params[:query]).where(conditions)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -167,11 +167,11 @@ module Api
|
|||
|
||||
# Specify whitelisted properties that can be modified.
|
||||
def set
|
||||
@user = User.where('username = ?', params[:id].downcase).first
|
||||
@user = User.find_by('lower(username) = ?', params[:id].downcase)
|
||||
end
|
||||
|
||||
def set_by_id
|
||||
@user = User.where('id = ?', params[:id]).first
|
||||
@user = User.find_by('id = ?', params[:id])
|
||||
end
|
||||
|
||||
def user_params
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ module Api
|
|||
end
|
||||
|
||||
def to_hash
|
||||
ap @data
|
||||
{
|
||||
message: message,
|
||||
code: code,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,16 @@
|
|||
class Character < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
multisearchable against: %i[name_en name_jp],
|
||||
additional_attributes: lambda { |character|
|
||||
{
|
||||
name_en: character.name_en,
|
||||
name_jp: character.name_jp,
|
||||
granblue_id: character.granblue_id,
|
||||
element: character.element
|
||||
}
|
||||
}
|
||||
|
||||
pg_search_scope :en_search,
|
||||
against: :name_en,
|
||||
using: {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Job < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
belongs_to :party
|
||||
has_many :skills, class_name: 'JobSkill'
|
||||
|
||||
multisearchable against: %i[name_en name_jp],
|
||||
additional_attributes: lambda { |job|
|
||||
{
|
||||
name_en: job.name_en,
|
||||
name_jp: job.name_jp,
|
||||
granblue_id: job.granblue_id,
|
||||
element: 0
|
||||
}
|
||||
}
|
||||
|
||||
belongs_to :base_job,
|
||||
foreign_key: 'base_job_id',
|
||||
class_name: 'Job',
|
||||
|
|
|
|||
|
|
@ -3,6 +3,16 @@
|
|||
class Summon < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
multisearchable against: %i[name_en name_jp],
|
||||
additional_attributes: lambda { |summon|
|
||||
{
|
||||
name_en: summon.name_en,
|
||||
name_jp: summon.name_jp,
|
||||
granblue_id: summon.granblue_id,
|
||||
element: summon.element
|
||||
}
|
||||
}
|
||||
|
||||
pg_search_scope :en_search,
|
||||
against: :name_en,
|
||||
using: {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,16 @@
|
|||
class Weapon < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
multisearchable against: %i[name_en name_jp],
|
||||
additional_attributes: lambda { |weapon|
|
||||
{
|
||||
name_en: weapon.name_en,
|
||||
name_jp: weapon.name_jp,
|
||||
granblue_id: weapon.granblue_id,
|
||||
element: weapon.element
|
||||
}
|
||||
}
|
||||
|
||||
pg_search_scope :en_search,
|
||||
against: :name_en,
|
||||
using: {
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@
|
|||
Rails.application.config.middleware.insert_before 0, Rack::Cors do
|
||||
allow do
|
||||
if Rails.env.production?
|
||||
origins %w[app.granblue.team hensei-web-production.up.railway.app]
|
||||
origins %w[granblue.team app.granblue.team hensei-web-production.up.railway.app]
|
||||
else
|
||||
origins %w[staging.granblue.team 127.0.0.1:1234]
|
||||
end
|
||||
|
||||
resource "*",
|
||||
resource '*',
|
||||
headers: :any,
|
||||
methods: [:get, :post, :put, :patch, :delete, :options, :head]
|
||||
methods: %i[get post put patch delete options head]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ Rails.application.routes.draw do
|
|||
post 'check/email', to: 'users#check_email'
|
||||
post 'check/username', to: 'users#check_username'
|
||||
|
||||
post 'search', to: 'search#all'
|
||||
post 'search/characters', to: 'search#characters'
|
||||
post 'search/weapons', to: 'search#weapons'
|
||||
post 'search/summons', to: 'search#summons'
|
||||
|
|
|
|||
21
db/migrate/20230705065015_create_pg_search_documents.rb
Normal file
21
db/migrate/20230705065015_create_pg_search_documents.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class CreatePgSearchDocuments < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
say_with_time('Creating table for pg_search multisearch') do
|
||||
create_table :pg_search_documents do |t|
|
||||
t.text :content
|
||||
t.string :granblue_id
|
||||
t.string :name_en
|
||||
t.string :name_jp
|
||||
t.integer :element
|
||||
t.belongs_to :searchable, type: :uuid, polymorphic: true, index: true
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
say_with_time('Dropping table for pg_search multisearch') do
|
||||
drop_table :pg_search_documents
|
||||
end
|
||||
end
|
||||
end
|
||||
15
db/schema.rb
15
db/schema.rb
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_07_02_035508) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_07_05_065015) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "btree_gin"
|
||||
enable_extension "pg_trgm"
|
||||
|
|
@ -361,6 +361,19 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_02_035508) do
|
|||
t.index ["user_id"], name: "index_parties_on_user_id"
|
||||
end
|
||||
|
||||
create_table "pg_search_documents", force: :cascade do |t|
|
||||
t.text "content"
|
||||
t.string "granblue_id"
|
||||
t.string "name_en"
|
||||
t.string "name_jp"
|
||||
t.integer "element"
|
||||
t.string "searchable_type"
|
||||
t.uuid "searchable_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["searchable_type", "searchable_id"], name: "index_pg_search_documents_on_searchable"
|
||||
end
|
||||
|
||||
create_table "raid_groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "name_en", null: false
|
||||
t.string "name_jp", null: false
|
||||
|
|
|
|||
Loading…
Reference in a new issue