From 7ca88f64165f3b65167c009768cd3f27d8794b41 Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Mon, 25 May 2026 12:09:35 +0200 Subject: [PATCH] search testing xd --- public/s/js/f0ckm.js | 6 +++--- src/inc/routeinc/f0cklib.mjs | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/public/s/js/f0ckm.js b/public/s/js/f0ckm.js index 5d0abbc..8f84568 100644 --- a/public/s/js/f0ckm.js +++ b/public/s/js/f0ckm.js @@ -4354,7 +4354,7 @@ window.cancelAnimFrame = (function () { suggestions.style.display = 'none'; highlightIdx = -1; toggleSearch(false); - const target = `/search/?tag=title:${encodeURIComponent(s.title)}`; + const target = `/tag/${encodeURIComponent('title:' + s.title)}/`; if (typeof loadPageAjax === 'function') { loadPageAjax(target, true); } else { @@ -4535,7 +4535,7 @@ window.cancelAnimFrame = (function () { suggestions.style.display = 'none'; highlightIdx = -1; toggleSearch(false); - const target = `/search/?tag=title:${encodeURIComponent(el.dataset.title)}`; + const target = `/tag/${encodeURIComponent('title:' + el.dataset.title)}/`; if (typeof loadPageAjax === 'function') { loadPageAjax(target, true); } else { @@ -4566,7 +4566,7 @@ window.cancelAnimFrame = (function () { if (tagItems.length === 0 && titleItems.length > 0) { toggleSearch(false); const q = input.value.trim(); - const target = `/search/?tag=title:${encodeURIComponent(q)}`; + const target = `/tag/${encodeURIComponent('title:' + q)}/`; if (typeof loadPageAjax === 'function') { loadPageAjax(target, true); } else { diff --git a/src/inc/routeinc/f0cklib.mjs b/src/inc/routeinc/f0cklib.mjs index a86ec3f..4e628c6 100644 --- a/src/inc/routeinc/f0cklib.mjs +++ b/src/inc/routeinc/f0cklib.mjs @@ -97,7 +97,12 @@ const xdScoreMeta = (score) => { export default { getf0cks: async ({ user: rawUser, tag: rawTag, hall: rawHall, mime: rawMime, page, mode, fav, session, limit, strict, newer, exclude, user_id, random, userHall: rawUserHall, userHallOwner: rawUserHallOwner, minXdScore } = {}) => { const user = rawUser ? lib.escapeLike(decodeURI(rawUser)) : null; - const tag = lib.parseTag(rawTag ?? null); + + // --- title: prefix — search items.title instead of the tags table --- + const isTitleSearch = (rawTag ?? '').startsWith('title:'); + const titleQuery = isTitleSearch ? (rawTag ?? '').substring(6).trim() : null; + + const tag = isTitleSearch ? null : lib.parseTag(rawTag ?? null); let hall = rawHall ?? null; let hallObj = null; if (hall) { @@ -142,12 +147,16 @@ export default { const strictParams = ((strict || (tag && tag.includes(','))) && tag) ? tag.split(',').map(t => lib.slugify(t)).filter(t => t) : []; const isStrict = strictParams.length > 0; - const tmp = { user, tag, hall: hallObj || hall, mime, page: actPage, mode: mode, view_mode: fav ? 'favs' : 'uploads', strict: strict, userHall: userHallObj || userHallSlug, userHallOwner }; + const tmp = { user, tag: isTitleSearch ? rawTag : tag, hall: hallObj || hall, mime, page: actPage, mode: mode, view_mode: fav ? 'favs' : 'uploads', strict: strict, userHall: userHallObj || userHallSlug, userHallOwner }; const baseMode = lib.getMode(mode ?? 0); const modequery = baseMode; let tagFilter = db``; - if (tag) { + let titleFilter = db``; + if (isTitleSearch && titleQuery) { + // Title search: match items.title ILIKE '%query%' + titleFilter = db`and items.title ILIKE ${'%' + titleQuery + '%'} and items.title IS NOT NULL`; + } else if (tag) { const terms = tag.split(',').map(t => t.trim()).filter(Boolean); if (terms.length > 0) { if (isStrict) { @@ -188,6 +197,7 @@ export default { ${db.unsafe(modequery)} and items.active = true ${tagFilter} + ${titleFilter} ${fav ? db`and fav_u.user ilike ${user}` : db``} ${!fav && user ? db`and items.username ilike ${user}` : db``} ${mimeSQL} @@ -245,6 +255,7 @@ export default { ${db.unsafe(modequery)} and items.active = true ${tagFilter} + ${titleFilter} ${fav ? db`and fav_u.user ilike ${user}` : db``} ${!fav && user ? db`and items.username ilike ${user}` : db``} ${mimeSQL} @@ -291,6 +302,13 @@ export default { const link = lib.genLink({ user, tag, hall: hallObj ? hallObj.slug : hall, mime, type: fav ? 'favs' : 'uploads', path: 'p/', strict: strict }); + // Override link for title searches — pagination must use the /tag/title:... prefix + if (isTitleSearch && titleQuery) { + link.main = `/tag/${encodeURIComponent('title:' + titleQuery)}/`; + link.path = 'p/'; + link.suffix = ''; + } + // Override link for user hall context if (userHallObj && userHallOwner) { const ownerName = userHallObj.owner_name || userHallOwner;