From 421f2ce39f61fa9046c367f7cb1cb36fd73daaa0 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 27 Feb 2024 15:51:27 -0800 Subject: [PATCH] Use `fits:nostalgic-faerie-draik` filter format when we can This only *really* shows up right now in the case where you construct an Advanced Search form query (which only the wardrobe-2020 app does now, and in limited form), and we return the query back (which only gets used by the HTML view for item search, which doesn't have any way to build one of these requests against it). This is because, if you just type in `fits:alt-style-87305`, we always keep your search string the same when outputting it back to you, to avoid the weirdness of canonicalizing it and changing it up on you in surprising ways! But idk, this is just looking forward a bit, and keeping the system's semantics in place. I hope someday we can bring robust text filter and Advanced Search stuff back into the main app again, maybe! --- app/models/item/search/query.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/item/search/query.rb b/app/models/item/search/query.rb index cf3d4362..3a635ff4 100644 --- a/app/models/item/search/query.rb +++ b/app/models/item/search/query.rb @@ -63,6 +63,7 @@ class Item is_positive ? Filter.restricts(value) : Filter.not_restricts(value) when 'fits' # First, try the `fits:blue-acara` case. + # NOTE: This will also work for `fits:"usuki girl-usul"`! match = value.match(/^([^-]+)-([^-]+)$/) if match.present? color_name, species_name = match.captures @@ -83,6 +84,7 @@ class Item end # Next, try the `fits:nostalgic-faerie-draik` case. + # NOTE: This will also work for `fits:"nostalgic-usuki girl-usul"`! match = value.match(/^([^-]+)-([^-]+)-([^-]+)$/) if match.present? series_name, color_name, species_name = match.captures @@ -362,7 +364,17 @@ class Item end def self.alt_style_to_filter_text(alt_style) - "alt-style-#{alt_style.id}" + # If the real series name has been set in the database by support + # staff, use that for the canonical filter text for this alt style. + # Otherwise, represent this alt style by ID. + if alt_style.has_real_series_name? + series_name = alt_style.series_name.downcase + color_name = alt_style.color.name.downcase + species_name = alt_style.species.name.downcase + "#{series_name}-#{color_name}-#{species_name}" + else + "alt-style-#{alt_style.id}" + end end end end