Browse Source

bug-fixes

imwald
Silberengel 3 weeks ago
parent
commit
69d95384b2
  1. 34
      src/lib/dtag-search.ts
  2. 5
      src/pages/secondary/NoteListPage/index.tsx

34
src/lib/dtag-search.ts

@ -6,13 +6,41 @@ export function getDTagValue(event: Event): string | undefined { @@ -6,13 +6,41 @@ export function getDTagValue(event: Event): string | undefined {
return t
}
/** d-tag contains needle or note content contains needle (case-insensitive). */
const TEXT_META_TAG_NAMES = new Set(['title', 'summary', 'description', 'subject', 'name'])
/**
* d-tag, content, or common text metadata tags (title, summary, description, subject, name)
* contain the needle (case-insensitive).
*
* NIP-50 full-text search can match on metadata tags not in the `d` tag or `content` field,
* so we check them here to avoid incorrectly hiding those results.
*
* Also checks a space-separated variant of the needle so that a hyphenated d-tag slug like
* "bitcoin-wallet" matches content/titles written as "Bitcoin Wallet".
*/
export function eventMatchesDTagLooseQuery(needle: string, event: Event): boolean {
const q = needle.trim().toLowerCase()
if (!q) return true
// Also try the space-separated variant (e.g. "bitcoin-wallet" → "bitcoin wallet")
const qSpace = q.replace(/-/g, ' ')
const checks = qSpace !== q ? [q, qSpace] : [q]
const d = getDTagValue(event)?.toLowerCase() ?? ''
if (d.includes(q)) return true
if ((event.content ?? '').toLowerCase().includes(q)) return true
for (const c of checks) {
if (d.includes(c)) return true
}
const content = (event.content ?? '').toLowerCase()
for (const c of checks) {
if (content.includes(c)) return true
}
for (const tag of event.tags) {
if (tag[1] && TEXT_META_TAG_NAMES.has(tag[0])) {
const val = tag[1].toLowerCase()
for (const c of checks) {
if (val.includes(c)) return true
}
}
}
return false
}

5
src/pages/secondary/NoteListPage/index.tsx

@ -210,9 +210,12 @@ const NoteListPage = forwardRef<HTMLDivElement, NoteListPageProps>(({ index, hid @@ -210,9 +210,12 @@ const NoteListPage = forwardRef<HTMLDivElement, NoteListPageProps>(({ index, hid
new Set([...NIP_SEARCH_DOCUMENT_KINDS, ...(kinds.length > 0 ? kinds : [])])
).sort((a, b) => a - b)
const kindFilter = { kinds: mergedReqKinds }
// NIP-50 full-text search works better with natural-language spacing;
// convert the hyphenated slug back to a space-separated query for the search relay.
const searchQuery = domain.replace(/-/g, ' ')
setSubRequests([
{
filter: { search: domain, ...kindFilter },
filter: { search: searchQuery, ...kindFilter },
urls: [...new Set([...relayUrls, ...SEARCHABLE_RELAY_URLS])]
},
{

Loading…
Cancel
Save