fix: url search (#2083)

* fix: url search

* refine

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: k00b <k00b@stacker.news>
This commit is contained in:
Abhi Shandilya 2025-04-15 19:23:41 -04:00 committed by GitHub
parent 37eb0e905c
commit 66dbf2496e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,7 @@
import { decodeCursor, LIMIT, nextCursorEncoded } from '@/lib/cursor'
import { whenToFrom } from '@/lib/time'
import { getItem, itemQueryWithMeta, SELECT } from './item'
import { parse } from 'tldts'
function queryParts (q) {
const regex = /"([^"]*)"/gm
@ -253,24 +254,17 @@ export default {
// if search contains a url term, modify the query text
if (url) {
const uri = url.slice(4)
let uriObj
try {
uriObj = new URL(uri)
} catch {
try {
uriObj = new URL(`https://${uri}`)
} catch {}
}
if (uriObj) {
let uri = url.slice(4)
termQueries.push({
wildcard: { url: `*${uriObj?.hostname ?? uri}${uriObj?.pathname ?? ''}*` }
})
termQueries.push({
match: { text: `${uriObj?.hostname ?? uri}${uriObj?.pathname ?? ''}` }
match_bool_prefix: { url: { query: uri, operator: 'and', boost: 1000 } }
})
const parsed = parse(uri)
if (parsed?.subdomain?.length > 0) {
uri = uri.replace(`${parsed.subdomain}.`, '')
}
termQueries.push({
wildcard: { url: { value: `*${uri}*` } }
})
}
// if nym, items must contain nym