@@ -6,7 +6,18 @@ import { defineQuery } from "groq";
66 * direct title/name matches strictly outrank long transcript matches.
77 */
88export const semanticSearchQuery = defineQuery ( `
9- *[_type in ["post", "podcast", "author", "guest"] && defined(slug.current) && ($type == null || $type == "all" || _type == $type)]
9+ *[
10+ _type in ["post", "podcast", "course", "lesson", "transcript", "author", "guest", "sponsor", "newsletter"] &&
11+ (defined(slug.current) || _type == "transcript") &&
12+ coalesce(archived, false) != true &&
13+ (_type != "transcript" || !defined(contentRef) || contentRef->_type in ["post", "podcast", "course", "lesson"]) &&
14+ (
15+ $type == null ||
16+ $type == "all" ||
17+ ($type == "youtube" && (_type == "transcript" || defined(youtube) || defined(listenLinks.youtube) || defined(transcript->youtubeId))) ||
18+ _type == $type
19+ )
20+ ]
1021 | score(
1122 boost(title == $searchTerm, 100),
1223 boost(name == $searchTerm, 100),
@@ -15,20 +26,33 @@ export const semanticSearchQuery = defineQuery(`
1526 boost(title match $searchTerm, 30),
1627 boost(name match $searchTerm, 30),
1728 boost(excerpt match $searchTerm + "*", 8),
29+ boost(summary match $searchTerm + "*", 8),
30+ boost(description match $searchTerm + "*", 6),
1831 text::semanticSimilarity($searchTerm)
1932 )
20- | order(_score desc)[0...24 ] {
33+ | order(_score desc)[0...28 ] {
2134 _id,
2235 _type,
2336 "title": coalesce(title, name, "Untitled"),
24- "slug": slug.current,
25- "excerpt": coalesce(excerpt, transcript->summary),
26- "transcriptSummary": transcript->summary,
27- "youtube": coalesce(youtube, listenLinks.youtube, transcript->youtubeUrl),
37+ "slug": coalesce(slug.current, contentRef->slug.current, youtubeId),
38+ "courseSlug": select(
39+ _type == "lesson" => *[_type == "course" && references(^._id)][0].slug.current,
40+ contentRef->_type == "lesson" => *[_type == "course" && references(^.contentRef._ref)][0].slug.current,
41+ null
42+ ),
43+ "parentType": contentRef->_type,
44+ "parentSlug": contentRef->slug.current,
45+ "excerpt": coalesce(excerpt, summary, description, transcript->summary),
46+ "transcriptSummary": coalesce(summary, transcript->summary),
47+ "youtube": coalesce(youtubeUrl, youtube, listenLinks.youtube, transcript->youtubeUrl, contentRef->youtube),
48+ "youtubeId": coalesce(youtubeId, transcript->youtubeId),
49+ "duration": coalesce(duration, transcript->duration),
50+ "durationSeconds": coalesce(durationSeconds, transcript->durationSeconds),
51+ "viewCount": coalesce(statistics.viewCount, statistics.youtube.viewCount, transcript->statistics.viewCount),
2852 listenLinks,
2953 "spotifyLink": spotify.link,
3054 coverImage,
31- date,
55+ " date": coalesce(date, publishedAt, _createdAt) ,
3256 _score
3357 }
3458` ) ;
@@ -37,34 +61,61 @@ export const semanticSearchQuery = defineQuery(`
3761 * Fallback text-matching search query if dataset embeddings are pending or unconfigured.
3862 */
3963export const textSearchFallbackQuery = defineQuery ( `
40- *[_type in ["post", "podcast", "author", "guest"] && defined(slug.current) && ($type == null || $type == "all" || _type == $type) && (
41- title match $searchTerm + "*" ||
42- name match $searchTerm + "*" ||
43- excerpt match $searchTerm + "*" ||
44- transcript->summary match $searchTerm + "*" ||
45- transcript->fullText match $searchTerm + "*"
46- )]
64+ *[
65+ _type in ["post", "podcast", "course", "lesson", "transcript", "author", "guest", "sponsor", "newsletter"] &&
66+ (defined(slug.current) || _type == "transcript") &&
67+ coalesce(archived, false) != true &&
68+ (_type != "transcript" || !defined(contentRef) || contentRef->_type in ["post", "podcast", "course", "lesson"]) &&
69+ (
70+ $type == null ||
71+ $type == "all" ||
72+ ($type == "youtube" && (_type == "transcript" || defined(youtube) || defined(listenLinks.youtube) || defined(transcript->youtubeId))) ||
73+ _type == $type
74+ ) && (
75+ title match $searchTerm + "*" ||
76+ name match $searchTerm + "*" ||
77+ excerpt match $searchTerm + "*" ||
78+ summary match $searchTerm + "*" ||
79+ description match $searchTerm + "*" ||
80+ fullText match $searchTerm + "*" ||
81+ transcript->summary match $searchTerm + "*" ||
82+ transcript->fullText match $searchTerm + "*"
83+ )
84+ ]
4785 | score(
4886 boost(title == $searchTerm, 100),
4987 boost(name == $searchTerm, 100),
5088 boost(title match $searchTerm + "*", 50),
5189 boost(name match $searchTerm + "*", 50),
5290 boost(title match $searchTerm, 30),
5391 boost(name match $searchTerm, 30),
54- boost(excerpt match $searchTerm + "*", 8)
92+ boost(excerpt match $searchTerm + "*", 8),
93+ boost(summary match $searchTerm + "*", 8),
94+ boost(description match $searchTerm + "*", 6)
5595 )
56- | order(_score desc)[0...24 ] {
96+ | order(_score desc)[0...28 ] {
5797 _id,
5898 _type,
5999 "title": coalesce(title, name, "Untitled"),
60- "slug": slug.current,
61- "excerpt": coalesce(excerpt, transcript->summary),
62- "transcriptSummary": transcript->summary,
63- "youtube": coalesce(youtube, listenLinks.youtube, transcript->youtubeUrl),
100+ "slug": coalesce(slug.current, contentRef->slug.current, youtubeId),
101+ "courseSlug": select(
102+ _type == "lesson" => *[_type == "course" && references(^._id)][0].slug.current,
103+ contentRef->_type == "lesson" => *[_type == "course" && references(^.contentRef._ref)][0].slug.current,
104+ null
105+ ),
106+ "parentType": contentRef->_type,
107+ "parentSlug": contentRef->slug.current,
108+ "excerpt": coalesce(excerpt, summary, description, transcript->summary),
109+ "transcriptSummary": coalesce(summary, transcript->summary),
110+ "youtube": coalesce(youtubeUrl, youtube, listenLinks.youtube, transcript->youtubeUrl, contentRef->youtube),
111+ "youtubeId": coalesce(youtubeId, transcript->youtubeId),
112+ "duration": coalesce(duration, transcript->duration),
113+ "durationSeconds": coalesce(durationSeconds, transcript->durationSeconds),
114+ "viewCount": coalesce(statistics.viewCount, statistics.youtube.viewCount, transcript->statistics.viewCount),
64115 listenLinks,
65116 "spotifyLink": spotify.link,
66117 coverImage,
67- date,
118+ " date": coalesce(date, publishedAt, _createdAt) ,
68119 _score
69120 }
70121` ) ;
0 commit comments