Compare commits

...

12 commits

Author SHA1 Message Date
12544bd8ad Revert "(WIP) Add support for inclusion/exclusion + refactor"
This reverts commit b5f9889c00.
2023-07-09 22:40:01 -07:00
3f734a0389 Revert "Grid model object updates"
This reverts commit 70e820b781.
2023-07-09 22:39:59 -07:00
b5f9889c00 (WIP) Add support for inclusion/exclusion + refactor
This commit adds basic support for including/excluding objects from collection filters. There is also a refactor of the filter logic as a whole. It is only implemented in `teams` for now and is a work in progress.
2023-07-09 22:39:10 -07:00
70e820b781 Grid model object updates
* Adds has_one association to canonical objects
* GridWeapon is_mainhand refactored
* GridCharacter add_awakening refactored
2023-07-09 22:38:01 -07:00
a82e1512c2 Search is broken in Japanese! 2023-07-06 18:07:16 -07:00
645fc07327 Update grid_summons_controller.rb
Set the proper uncap level for transcended summons
2023-07-06 15:54:29 -07:00
c0b2c9502f
Implement all-entity search to support tagging objects (#117)
* Add table for multisearch

* Add new route for searching all entities

* Make models multisearchable

We're going to start with Character, Summon, Weapon and Jobs

* Add method to Search controller

This will search with trigram first, and then if there aren't enough results, search with prefixed text search

* Add support for Japanese all-entity search
2023-07-05 21:19:48 -07:00
193b1b7b2d Add granblue.team to cors
This works now!
2023-07-05 13:06:42 -07:00
56bb2ccf03 Remove ap call and unused code 2023-07-04 03:19:05 -07:00
3ff89796d4 Downcase username on db end
There was a bug where users with capital letters in their name could not access their profiles after we tried to make things case insensitive.
2023-07-04 03:18:59 -07:00
197aad8a8d Fix remix render method 2023-07-04 02:53:24 -07:00
f154e898bc Remove ap call 2023-07-04 02:53:09 -07:00
14 changed files with 148 additions and 30 deletions

View 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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -20,7 +20,6 @@ module Api
end
def to_hash
ap @data
{
message: message,
code: code,

View file

@ -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: {

View file

@ -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',

View file

@ -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: {

View file

@ -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: {

View file

@ -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

View file

@ -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'

View 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

View file

@ -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