Skip to content

Commit 845e037

Browse files
committed
sql-page.com search: dynamic component retrieval and improve link data handling
1 parent d526ccb commit 845e037

File tree

1 file changed

+57
-30
lines changed

1 file changed

+57
-30
lines changed

examples/official-site/search.sql

+57-30
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ END
66
SELECT 'redirect' as component, $redirect as link WHERE $redirect IS NOT NULL;
77

88

9-
select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1;
9+
select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object(
10+
'title', coalesce($search || ' | ', '') || 'SQLPage documentation search'
11+
)) as properties
12+
FROM example WHERE component = 'shell' LIMIT 1;
1013

1114
SELECT 'form' as component,
1215
'GET' as method,
@@ -37,45 +40,69 @@ WHERE $search IS NOT NULL;
3740

3841
WITH search_results AS (
3942
SELECT
43+
COALESCE(
44+
component_name || ' component: parameter ' || parameter_name
45+
, component_name || ' component' || IF(component_example_description IS NULL, '', ' example')
46+
, 'blog: ' || blog_title
47+
, 'sqlpage.' || function_name || '(...' || function_parameter_name || '...)'
48+
, 'sqlpage.' || function_name || '(...)'
49+
) as title,
50+
COALESCE(
51+
component_description,
52+
parameter_description,
53+
blog_description,
54+
function_parameter_description,
55+
function_description,
56+
component_example_description
57+
) as description,
4058
CASE
41-
WHEN parameter_name IS NOT NULL THEN component_name || ' component: parameter ' || parameter_name
42-
WHEN component_name IS NOT NULL THEN component_name || ' component'
43-
WHEN blog_title IS NOT NULL THEN 'blog: ' || blog_title
44-
WHEN function_parameter_name IS NOT NULL THEN function_name || '(...' || function_parameter_name || '...)'
45-
WHEN function_name IS NOT NULL THEN function_name || '(...)'
46-
END as title,
47-
CASE
48-
WHEN component_description IS NOT NULL THEN component_description
49-
WHEN parameter_description IS NOT NULL THEN parameter_description
50-
WHEN blog_description IS NOT NULL THEN blog_description
51-
WHEN function_description IS NOT NULL THEN function_description
52-
WHEN function_parameter_description IS NOT NULL THEN function_parameter_description
53-
END as description,
54-
CASE
55-
WHEN component_name IS NOT NULL THEN json_object('page', '/component.sql', 'parameters', json_object('component', component_name))
56-
WHEN parameter_name IS NOT NULL THEN json_object('page', '/component.sql', 'parameters', json_object('component', (
57-
SELECT component FROM parameter
58-
WHERE name = parameter_name
59-
LIMIT 1
60-
)))
61-
WHEN blog_title IS NOT NULL THEN json_object('page', '/blog.sql', 'parameters', json_object('post', blog_title))
62-
WHEN function_name IS NOT NULL THEN json_object('page', '/functions.sql', 'parameters', json_object('function', function_name))
63-
WHEN function_parameter_name IS NOT NULL THEN json_object('page', '/functions.sql', 'parameters', json_object('function', (
64-
SELECT function FROM sqlpage_function_parameters
65-
WHERE name = function_parameter_name
66-
LIMIT 1
67-
)))
59+
WHEN component_name IS NOT NULL THEN
60+
json_object(
61+
'page', '/component.sql',
62+
'parameters', json_object('component', component_name)
63+
)
64+
WHEN parameter_name IS NOT NULL THEN
65+
json_object(
66+
'page', '/component.sql',
67+
'parameters', json_object('component', (
68+
SELECT component
69+
FROM parameter
70+
WHERE name = parameter_name
71+
LIMIT 1
72+
))
73+
)
74+
WHEN blog_title IS NOT NULL THEN
75+
json_object(
76+
'page', '/blog.sql',
77+
'parameters', json_object('post', blog_title)
78+
)
79+
WHEN function_name IS NOT NULL THEN
80+
json_object(
81+
'page', '/functions.sql',
82+
'parameters', json_object('function', function_name)
83+
)
84+
WHEN function_parameter_name IS NOT NULL THEN
85+
json_object(
86+
'page', '/functions.sql',
87+
'parameters', json_object('function', (
88+
SELECT function
89+
FROM sqlpage_function_parameters
90+
WHERE name = function_parameter_name
91+
LIMIT 1
92+
))
93+
)
6894
END as link_data,
6995
rank
7096
FROM documentation_fts
7197
WHERE $search IS NOT NULL
7298
AND documentation_fts = $search
7399
)
74100
SELECT
75-
title,
76-
description,
101+
max(title) as title,
102+
max(description) as description,
77103
sqlpage.link(link_data->>'page', link_data->'parameters') as link
78104
FROM search_results
105+
GROUP BY link_data
79106
ORDER BY
80107
rank,
81108
CASE

0 commit comments

Comments
 (0)