feat: use NIP-50 relay-side search with scope selection #114

Merged
hodlbod merged 4 commits from :dev into dev 2026-04-02 18:49:18 +00:00
Contributor

Summary

Replaces the local Fuse.js-based message search in SpaceSearch with NIP-50 relay-side search, allowing users to search across messages that haven't been loaded locally.

Addresses #110

Changes

src/app/components/SpaceSearch.svelte

  • Replaced local createSearch (Fuse.js) with request() using the NIP-50 search filter field
  • Added search scope selector with three options:
    • Room: searches the space relay with #h tag filter
    • Space: searches the space relay
    • Everything: searches the user's configured search relays (falls back to default relays)
  • Added 300ms debounce, AbortController for request cancellation, and search ID tracking to prevent race conditions
  • Added loading indicator and relay status display so users know which relays are being queried

How it works

  • Room/Space scopes send the NIP-50 search request to the space's relay
  • Everything scope uses relays from userSearchRelayList, falling back to DEFAULT_RELAYS if none are configured
  • Results are deduplicated and sorted by time descending
  • Previous in-flight requests are aborted when a new search is triggered
## Summary Replaces the local Fuse.js-based message search in `SpaceSearch` with NIP-50 relay-side search, allowing users to search across messages that haven't been loaded locally. Addresses #110 ## Changes **`src/app/components/SpaceSearch.svelte`** - Replaced local `createSearch` (Fuse.js) with `request()` using the NIP-50 `search` filter field - Added search scope selector with three options: - **Room**: searches the space relay with `#h` tag filter - **Space**: searches the space relay - **Everything**: searches the user's configured search relays (falls back to default relays) - Added 300ms debounce, AbortController for request cancellation, and search ID tracking to prevent race conditions - Added loading indicator and relay status display so users know which relays are being queried ## How it works - Room/Space scopes send the NIP-50 search request to the space's relay - Everything scope uses relays from `userSearchRelayList`, falling back to `DEFAULT_RELAYS` if none are configured - Results are deduplicated and sorted by time descending - Previous in-flight requests are aborted when a new search is triggered
bhavishy2801 added 1 commit 2026-04-02 05:55:53 +00:00
Author
Contributor

@hodlbod Kindly review this PR :)

@hodlbod Kindly review this PR :)
hodlbod requested changes 2026-04-02 17:35:39 +00:00
@@ -23,3 +24,1 @@
url,
h ? [{kinds: [MESSAGE], "#h": [h]}] : [{kinds: [MESSAGE]}],
)
type SearchScope = "room" | "space" | "everything"
Owner

Let's just stick to room/space, it probably doesn't make sense to add the everything category until we've integrated social media features (and it should probably go on the global search page).

Let's just stick to room/space, it probably doesn't make sense to add the everything category until we've integrated social media features (and it should probably go on the global search page).
Author
Contributor

Sure. I've removed the everything scope and kept the search UI limited to room and space only.

Sure. I've removed the `everything` scope and kept the search UI limited to room and space only.
hodlbod marked this conversation as resolved
@@ -45,0 +81,4 @@
return {kinds: [MESSAGE], "#h": [h], search: searchTerm}
}
return {kinds: [MESSAGE], search: searchTerm}
Owner

Use CONTENT_KINDS here so we can search threads, events, classifieds, etc

Use `CONTENT_KINDS` here so we can search threads, events, classifieds, etc
Author
Contributor

Sure. I've switched the search filter to CONTENT_KINDS, so room/space search now includes threads, events, classifieds, and other supported content types.

Sure. I've switched the search filter to CONTENT_KINDS, so room/space search now includes threads, events, classifieds, and other supported content types.
hodlbod marked this conversation as resolved
@@ -45,0 +104,4 @@
filters: [getFilter(searchTerm.trim())],
})
if (searchId === currentSearchId) {
Owner

This logic is redundant with the abort controller, it can be removed.

This logic is redundant with the abort controller, it can be removed.
Author
Contributor

Sure. I've removed the extra search ID/race tracking and relied on the AbortController for request cancellation, since that already covers the in-flight search case.

Sure. I've removed the extra search ID/race tracking and relied on the AbortController for request cancellation, since that already covers the in-flight search case.
hodlbod marked this conversation as resolved
bhavishy2801 added 1 commit 2026-04-02 18:15:14 +00:00
bhavishy2801 added 1 commit 2026-04-02 18:19:32 +00:00
hodlbod reviewed 2026-04-02 18:20:51 +00:00
@@ -30,0 +36,4 @@
scope === "room"
? `Using space relay: ${url} (room filter applied).`
: `Using space relay: ${url}.`,
)
Owner

Let's actually remove the room/space distinction and go back to detecting based on the presence of h tag. This search is contextual to a given room, so it doesn't really make sense to search the whole relay. #59 should solve that for us one way or another.

Let's actually remove the room/space distinction and go back to detecting based on the presence of `h` tag. This search is contextual to a given room, so it doesn't really make sense to search the whole relay. https://gitea.coracle.social/coracle/flotilla/issues/59 should solve that for us one way or another.
Author
Contributor

Sure. I've removed the room/space selector and restored the search to be contextual to the current room/space h-based.

Sure. I've removed the room/space selector and restored the search to be contextual to the current room/space h-based.
Author
Contributor

@hodlbod I've made all the requested changes. Kindly review the PR :)

@hodlbod I've made all the requested changes. Kindly review the PR :)
bhavishy2801 added 1 commit 2026-04-02 18:28:41 +00:00
Author
Contributor

@hodlbod I've made the necessary changes. Kindly have a look on them :)

@hodlbod I've made the necessary changes. Kindly have a look on them :)
hodlbod merged commit b26ab916d5 into dev 2026-04-02 18:49:18 +00:00
Sign in to join this conversation.