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
|
class Api::V1::SearchController < Api::V1::ApiController
|
||||||
def characters
|
def characters
|
||||||
|
locale = params[:locale] || 'en'
|
||||||
|
|
||||||
if params[:query].present?
|
if params[:query].present?
|
||||||
excludes = params[:excludes] ?
|
if locale == 'ja'
|
||||||
params[:excludes].split(',').map { |e| "%#{e.gsub(/\([^()]*\)/, '').strip}%" } : ''
|
@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.where("name_en ILIKE ? AND name_en NOT ILIKE ALL(ARRAY[?])", "%#{params[:query]}%", excludes).limit(10)
|
||||||
# @characters = Character.search(query).limit(10)
|
@characters = Character.en_search(params[:query]).limit(10)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@characters = Character.all
|
@characters = Character.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def weapons
|
def weapons
|
||||||
|
locale = params[:locale] || 'en'
|
||||||
|
|
||||||
if params[:query].present?
|
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
|
else
|
||||||
@weapons = Weapon.all
|
@weapons = Weapon.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def summons
|
def summons
|
||||||
|
locale = params[:locale] || 'en'
|
||||||
|
|
||||||
if params[:query].present?
|
if params[:query].present?
|
||||||
excludes = params[:excludes] ? params[:excludes].split(',').each { |e| "!#{e}" }.join(' ') : ''
|
if locale == 'ja'
|
||||||
@summons = Summon.search(params[:query]).limit(10)
|
@summons = Summon.jp_search(params[:query]).limit(10)
|
||||||
|
else
|
||||||
|
@summons = Summon.en_search(params[:query]).limit(10)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@summons = Summon.all
|
@summons = Summon.all
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,20 @@
|
||||||
class Character < ApplicationRecord
|
class Character < ApplicationRecord
|
||||||
include PgSearch::Model
|
include PgSearch::Model
|
||||||
|
|
||||||
pg_search_scope :search,
|
pg_search_scope :en_search,
|
||||||
against: [:name_en, :name_jp],
|
against: :name_en,
|
||||||
|
using: {
|
||||||
|
trigram: {
|
||||||
|
threshold: 0.18
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pg_search_scope :jp_search,
|
||||||
|
against: :name_jp,
|
||||||
using: {
|
using: {
|
||||||
tsearch: {
|
tsearch: {
|
||||||
negation: true,
|
prefix: true,
|
||||||
prefix: true
|
dictionary: "simple"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,20 @@
|
||||||
class Summon < ApplicationRecord
|
class Summon < ApplicationRecord
|
||||||
include PgSearch::Model
|
include PgSearch::Model
|
||||||
|
|
||||||
pg_search_scope :search,
|
pg_search_scope :en_search,
|
||||||
against: [:name_en, :name_jp],
|
against: :name_en,
|
||||||
|
using: {
|
||||||
|
trigram: {
|
||||||
|
threshold: 0.18
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pg_search_scope :jp_search,
|
||||||
|
against: :name_jp,
|
||||||
using: {
|
using: {
|
||||||
tsearch: {
|
tsearch: {
|
||||||
prefix: true
|
prefix: true,
|
||||||
|
dictionary: "simple"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,20 @@
|
||||||
class Weapon < ApplicationRecord
|
class Weapon < ApplicationRecord
|
||||||
include PgSearch::Model
|
include PgSearch::Model
|
||||||
|
|
||||||
pg_search_scope :search,
|
pg_search_scope :en_search,
|
||||||
against: [:name_en, :name_jp],
|
against: :name_en,
|
||||||
|
using: {
|
||||||
|
trigram: {
|
||||||
|
threshold: 0.18
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pg_search_scope :jp_search,
|
||||||
|
against: :name_jp,
|
||||||
using: {
|
using: {
|
||||||
tsearch: {
|
tsearch: {
|
||||||
prefix: true
|
prefix: true,
|
||||||
|
dictionary: "simple"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue