@@ -2,21 +2,25 @@ import { defineQuery } from "groq";
22
33/**
44 * Hybrid semantic search utilizing Sanity dataset embeddings (text::semanticSimilarity)
5- * combined with boost() scoring on title, excerpt, and transcript content.
5+ * combined with heavy boost() scoring on title, name, and excerpt to guarantee
6+ * direct title/name matches strictly outrank long transcript matches.
67 */
78export const semanticSearchQuery = defineQuery ( `
89 *[_type in ["post", "podcast", "author", "guest"] && defined(slug.current) && ($type == null || $type == "all" || _type == $type)]
910 | score(
10- boost(title match $searchTerm + "*", 5),
11- boost(excerpt match $searchTerm + "*", 2),
11+ boost(lower(coalesce(title, name)) == lower($searchTerm), 100),
12+ boost(coalesce(title, name) match $searchTerm + "*", 50),
13+ boost(coalesce(title, name) match $searchTerm, 30),
14+ boost(_type in ["author", "guest"] && coalesce(name, title) match $searchTerm + "*", 20),
15+ boost(excerpt match $searchTerm + "*", 8),
1216 boost(transcript->summary match $searchTerm + "*", 3),
1317 boost(transcript->fullText match $searchTerm + "*", 1),
1418 text::semanticSimilarity($searchTerm)
1519 )
1620 | order(_score desc)[0...24] {
1721 _id,
1822 _type,
19- title,
23+ " title": coalesce(title, name, "Untitled") ,
2024 "slug": slug.current,
2125 "excerpt": coalesce(excerpt, transcript->summary),
2226 "transcriptSummary": transcript->summary,
@@ -31,21 +35,25 @@ export const semanticSearchQuery = defineQuery(`
3135 */
3236export const textSearchFallbackQuery = defineQuery ( `
3337 *[_type in ["post", "podcast", "author", "guest"] && defined(slug.current) && ($type == null || $type == "all" || _type == $type) && (
34- title match $searchTerm + "*" ||
38+ coalesce(title, name) match $searchTerm + "*" ||
39+ coalesce(title, name) match $searchTerm ||
3540 excerpt match $searchTerm + "*" ||
3641 transcript->summary match $searchTerm + "*" ||
3742 transcript->fullText match $searchTerm + "*"
3843 )]
3944 | score(
40- boost(title match $searchTerm + "*", 5),
41- boost(excerpt match $searchTerm + "*", 2),
45+ boost(lower(coalesce(title, name)) == lower($searchTerm), 100),
46+ boost(coalesce(title, name) match $searchTerm + "*", 50),
47+ boost(coalesce(title, name) match $searchTerm, 30),
48+ boost(_type in ["author", "guest"] && coalesce(name, title) match $searchTerm + "*", 20),
49+ boost(excerpt match $searchTerm + "*", 8),
4250 boost(transcript->summary match $searchTerm + "*", 3),
4351 boost(transcript->fullText match $searchTerm + "*", 1)
4452 )
4553 | order(_score desc)[0...24] {
4654 _id,
4755 _type,
48- title,
56+ " title": coalesce(title, name, "Untitled") ,
4957 "slug": slug.current,
5058 "excerpt": coalesce(excerpt, transcript->summary),
5159 "transcriptSummary": transcript->summary,
0 commit comments