fyptt search fix

Bare keyword queries no longer hijack to a category archive when the
query matches a category name (sexy/ass/tiktok/...); only an explicit
cat:/category: prefix or the categories filter routes to an archive.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Simon
2026-06-19 21:47:21 +00:00
parent 1bd06db894
commit d21c36e585
2 changed files with 13 additions and 8 deletions

View File

@@ -123,15 +123,16 @@ impl FypttProvider {
if let Some(query) = query {
let q = query.trim();
if !q.is_empty() {
// Only an explicit `cat:`/`category:` prefix routes to a category
// archive. Bare category-name words ("sexy", "ass", "tiktok", ...)
// are far more common as real search terms on this site, so they
// must fall through to keyword search rather than being hijacked.
if let Some(slug) = q.strip_prefix("cat:").or_else(|| q.strip_prefix("category:")) {
if let Some(known) = Self::category_slug_for(slug) {
return Target::Category { slug: known.to_string() };
}
return Target::Category { slug: slug.trim().to_string() };
}
if let Some(slug) = Self::category_slug_for(q) {
return Target::Category { slug: slug.to_string() };
}
return Target::Search { query: q.to_string() };
}
}
@@ -460,10 +461,14 @@ mod tests {
}
#[test]
fn picks_category_target_from_title_match() {
match FypttProvider::pick_target(Some("Boobs")) {
Target::Category { slug } => assert_eq!(slug, "tiktok-boobs"),
other => panic!("expected Category, got {:?}", other),
fn category_name_word_routes_to_search_not_category() {
// "Boobs"/"sexy"/"tiktok" are category names but also common search
// terms; a bare query must search, not hijack to the category archive.
for word in ["Boobs", "sexy", "tiktok", "ass"] {
match FypttProvider::pick_target(Some(word)) {
Target::Search { query } => assert_eq!(query, word),
other => panic!("expected Search for {word:?}, got {:?}", other),
}
}
}