Skip to content

Commit 66dbf24

Browse files
abhiShandyhuumn
andauthored
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>
1 parent 37eb0e9 commit 66dbf24

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

api/resolvers/search.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { decodeCursor, LIMIT, nextCursorEncoded } from '@/lib/cursor'
22
import { whenToFrom } from '@/lib/time'
33
import { getItem, itemQueryWithMeta, SELECT } from './item'
4+
import { parse } from 'tldts'
45

56
function queryParts (q) {
67
const regex = /"([^"]*)"/gm
@@ -253,24 +254,17 @@ export default {
253254

254255
// if search contains a url term, modify the query text
255256
if (url) {
256-
const uri = url.slice(4)
257-
let uriObj
258-
try {
259-
uriObj = new URL(uri)
260-
} catch {
261-
try {
262-
uriObj = new URL(`https://${uri}`)
263-
} catch {}
264-
}
265-
266-
if (uriObj) {
267-
termQueries.push({
268-
wildcard: { url: `*${uriObj?.hostname ?? uri}${uriObj?.pathname ?? ''}*` }
269-
})
270-
termQueries.push({
271-
match: { text: `${uriObj?.hostname ?? uri}${uriObj?.pathname ?? ''}` }
272-
})
257+
let uri = url.slice(4)
258+
termQueries.push({
259+
match_bool_prefix: { url: { query: uri, operator: 'and', boost: 1000 } }
260+
})
261+
const parsed = parse(uri)
262+
if (parsed?.subdomain?.length > 0) {
263+
uri = uri.replace(`${parsed.subdomain}.`, '')
273264
}
265+
termQueries.push({
266+
wildcard: { url: { value: `*${uri}*` } }
267+
})
274268
}
275269

276270
// if nym, items must contain nym

0 commit comments

Comments
 (0)