hensei-api/app/models/weapon.rb
Justin Edmund 39a0d33bee
July 2023 Feature Release: Tagging objects (#118)
* Remove ap call

* Fix remix render method

* 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.

* Remove ap call and unused code

* Add granblue.team to cors

This works now!

* 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:51:36 -07:00

52 lines
1.3 KiB
Ruby

# frozen_string_literal: true
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: {
trigram: {
threshold: 0.18
}
}
pg_search_scope :ja_search,
against: :name_jp,
using: {
tsearch: {
prefix: true,
dictionary: 'simple'
}
}
has_many :weapon_awakenings
has_many :awakenings, through: :weapon_awakenings
def blueprint
WeaponBlueprint
end
def display_resource(weapon)
weapon.name_en
end
def compatible_with_key?(key)
key.series == series
end
# Returns whether the weapon is included in the Draconic or Dark Opus series
def opus_or_draconic?
[2, 3].include?(series)
end
end