Add exclusion for characters
This commit is contained in:
parent
e95baf7ee6
commit
75702ac4d2
2 changed files with 9 additions and 1 deletions
|
|
@ -1,7 +1,13 @@
|
|||
class Api::V1::SearchController < Api::V1::ApiController
|
||||
def characters
|
||||
if params[:query].present?
|
||||
@characters = Character.search(params[:query]).limit(10)
|
||||
excludes = params[:excludes] ?
|
||||
params[:excludes].split(',').map { |e| "%#{e.gsub(/\([^()]*\)/, '').strip}%" } : ''
|
||||
|
||||
ap excludes
|
||||
|
||||
@characters = Character.where("name_en ILIKE ? AND name_en NOT ILIKE ALL(ARRAY[?])", "%#{params[:query]}%", excludes).limit(10)
|
||||
# @characters = Character.search(query).limit(10)
|
||||
else
|
||||
@characters = Character.all
|
||||
end
|
||||
|
|
@ -17,6 +23,7 @@ class Api::V1::SearchController < Api::V1::ApiController
|
|||
|
||||
def summons
|
||||
if params[:query].present?
|
||||
excludes = params[:excludes] ? params[:excludes].split(',').each { |e| "!#{e}" }.join(' ') : ''
|
||||
@summons = Summon.search(params[:query]).limit(10)
|
||||
else
|
||||
@summons = Summon.all
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ class Character < ApplicationRecord
|
|||
against: [:name_en, :name_jp],
|
||||
using: {
|
||||
tsearch: {
|
||||
negation: true,
|
||||
prefix: true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue