Implement JP search and trigram for EN
This commit is contained in:
parent
0661b5a50d
commit
88f316d6a7
4 changed files with 58 additions and 18 deletions
|
|
@ -1,28 +1,42 @@
|
|||
class Api::V1::SearchController < Api::V1::ApiController
|
||||
def characters
|
||||
locale = params[:locale] || 'en'
|
||||
|
||||
if params[:query].present?
|
||||
excludes = params[:excludes] ?
|
||||
params[:excludes].split(',').map { |e| "%#{e.gsub(/\([^()]*\)/, '').strip}%" } : ''
|
||||
|
||||
@characters = Character.where("name_en ILIKE ? AND name_en NOT ILIKE ALL(ARRAY[?])", "%#{params[:query]}%", excludes).limit(10)
|
||||
# @characters = Character.search(query).limit(10)
|
||||
if locale == 'ja'
|
||||
@characters = Character.jp_search(params[:query]).limit(10)
|
||||
else
|
||||
# @characters = Character.where("name_en ILIKE ? AND name_en NOT ILIKE ALL(ARRAY[?])", "%#{params[:query]}%", excludes).limit(10)
|
||||
@characters = Character.en_search(params[:query]).limit(10)
|
||||
end
|
||||
else
|
||||
@characters = Character.all
|
||||
end
|
||||
end
|
||||
|
||||
def weapons
|
||||
locale = params[:locale] || 'en'
|
||||
|
||||
if params[:query].present?
|
||||
@weapons = Weapon.search(params[:query]).limit(10)
|
||||
if locale == 'ja'
|
||||
@weapons = Weapon.jp_search(params[:query]).limit(10)
|
||||
else
|
||||
@weapons = Weapon.en_search(params[:query]).limit(10)
|
||||
end
|
||||
else
|
||||
@weapons = Weapon.all
|
||||
end
|
||||
end
|
||||
|
||||
def summons
|
||||
locale = params[:locale] || 'en'
|
||||
|
||||
if params[:query].present?
|
||||
excludes = params[:excludes] ? params[:excludes].split(',').each { |e| "!#{e}" }.join(' ') : ''
|
||||
@summons = Summon.search(params[:query]).limit(10)
|
||||
if locale == 'ja'
|
||||
@summons = Summon.jp_search(params[:query]).limit(10)
|
||||
else
|
||||
@summons = Summon.en_search(params[:query]).limit(10)
|
||||
end
|
||||
else
|
||||
@summons = Summon.all
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,12 +1,20 @@
|
|||
class Character < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
pg_search_scope :search,
|
||||
against: [:name_en, :name_jp],
|
||||
pg_search_scope :en_search,
|
||||
against: :name_en,
|
||||
using: {
|
||||
trigram: {
|
||||
threshold: 0.18
|
||||
}
|
||||
}
|
||||
|
||||
pg_search_scope :jp_search,
|
||||
against: :name_jp,
|
||||
using: {
|
||||
tsearch: {
|
||||
negation: true,
|
||||
prefix: true
|
||||
prefix: true,
|
||||
dictionary: "simple"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,20 @@
|
|||
class Summon < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
pg_search_scope :search,
|
||||
against: [:name_en, :name_jp],
|
||||
pg_search_scope :en_search,
|
||||
against: :name_en,
|
||||
using: {
|
||||
trigram: {
|
||||
threshold: 0.18
|
||||
}
|
||||
}
|
||||
|
||||
pg_search_scope :jp_search,
|
||||
against: :name_jp,
|
||||
using: {
|
||||
tsearch: {
|
||||
prefix: true
|
||||
prefix: true,
|
||||
dictionary: "simple"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,20 @@
|
|||
class Weapon < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
pg_search_scope :search,
|
||||
against: [:name_en, :name_jp],
|
||||
pg_search_scope :en_search,
|
||||
against: :name_en,
|
||||
using: {
|
||||
trigram: {
|
||||
threshold: 0.18
|
||||
}
|
||||
}
|
||||
|
||||
pg_search_scope :jp_search,
|
||||
against: :name_jp,
|
||||
using: {
|
||||
tsearch: {
|
||||
prefix: true
|
||||
prefix: true,
|
||||
dictionary: "simple"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue