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:
parent
37eb0e905c
commit
66dbf2496e
@ -1,6 +1,7 @@
|
|||||||
import { decodeCursor, LIMIT, nextCursorEncoded } from '@/lib/cursor'
|
import { decodeCursor, LIMIT, nextCursorEncoded } from '@/lib/cursor'
|
||||||
import { whenToFrom } from '@/lib/time'
|
import { whenToFrom } from '@/lib/time'
|
||||||
import { getItem, itemQueryWithMeta, SELECT } from './item'
|
import { getItem, itemQueryWithMeta, SELECT } from './item'
|
||||||
|
import { parse } from 'tldts'
|
||||||
|
|
||||||
function queryParts (q) {
|
function queryParts (q) {
|
||||||
const regex = /"([^"]*)"/gm
|
const regex = /"([^"]*)"/gm
|
||||||
@ -253,24 +254,17 @@ export default {
|
|||||||
|
|
||||||
// if search contains a url term, modify the query text
|
// if search contains a url term, modify the query text
|
||||||
if (url) {
|
if (url) {
|
||||||
const uri = url.slice(4)
|
let uri = url.slice(4)
|
||||||
let uriObj
|
|
||||||
try {
|
|
||||||
uriObj = new URL(uri)
|
|
||||||
} catch {
|
|
||||||
try {
|
|
||||||
uriObj = new URL(`https://${uri}`)
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uriObj) {
|
|
||||||
termQueries.push({
|
termQueries.push({
|
||||||
wildcard: { url: `*${uriObj?.hostname ?? uri}${uriObj?.pathname ?? ''}*` }
|
match_bool_prefix: { url: { query: uri, operator: 'and', boost: 1000 } }
|
||||||
})
|
|
||||||
termQueries.push({
|
|
||||||
match: { text: `${uriObj?.hostname ?? uri}${uriObj?.pathname ?? ''}` }
|
|
||||||
})
|
})
|
||||||
|
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
|
// if nym, items must contain nym
|
||||||
|
Loading…
x
Reference in New Issue
Block a user