From 52e81557c235a629075b5b9429b0cf57ddc48e63 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sun, 25 Feb 2024 12:57:04 -0800 Subject: [PATCH] Update search filters to consider NP and PB mutually exclusive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `is:np` now means "is not NC and is not PB". Note that it might be good to make NC and PB explicitly mutually exclusive too? It would complicate queries though, and not matter in most cases… the Burlap Usul Bow is the only item that we currently return for `is:pb is:nc`, which is probably because of a rarity issue? --- app/models/item.rb | 8 +++++++- app/models/item/search/query.rb | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index ea223afc..e31d5356 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -39,10 +39,16 @@ class Item < ApplicationRecord i = Item.arel_table where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc].eq(true))) } - scope :is_np, -> { + scope :is_not_nc, -> { i = Item.arel_table where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc].eq(true)).not) } + scope :is_np, -> { + self.is_not_nc.is_not_pb + } + scope :is_not_np, -> { + self.merge Item.is_nc.or(Item.is_pb) + } scope :is_pb, -> { where('description LIKE ?', '%' + sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%') diff --git a/app/models/item/search/query.rb b/app/models/item/search/query.rb index 4f235837..203679ec 100644 --- a/app/models/item/search/query.rb +++ b/app/models/item/search/query.rb @@ -120,6 +120,10 @@ class Item Filter.name_excludes(value, locale)) when 'is_nc' filters << (is_positive ? Filter.is_nc : Filter.is_not_nc) + when 'is_pb' + filters << (is_positive ? Filter.is_pb : Filter.is_not_pb) + when 'is_np' + filters << (is_positive ? Filter.is_np : Filter.is_not_np) when 'occupied_zone_set_name' filters << (is_positive ? Filter.occupies(value, locale) : @@ -255,7 +259,7 @@ class Item end def self.is_not_nc - self.new Item.is_np, '-is:nc' + self.new Item.is_not_nc, '-is:nc' end def self.is_np @@ -263,7 +267,7 @@ class Item end def self.is_not_np - self.new Item.is_nc, '-is:np' + self.new Item.is_not_np, '-is:np' end def self.is_pb