hensei-api/app/models/summon.rb
Justin Edmund 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

40 lines
1,014 B
Ruby

# frozen_string_literal: true
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: {
trigram: {
threshold: 0.18
}
}
pg_search_scope :ja_search,
against: :name_jp,
using: {
tsearch: {
prefix: true,
dictionary: 'simple'
}
}
def blueprint
SummonBlueprint
end
def display_resource(summon)
summon.name_en
end
end