|
| 1 | +-- Check for exact matches and redirect if found |
| 2 | +set redirect = CASE |
| 3 | + WHEN EXISTS (SELECT 1 FROM component WHERE name = $search) THEN sqlpage.link('/component.sql', json_object('component', $search)) |
| 4 | + WHEN EXISTS (SELECT 1 FROM sqlpage_functions WHERE name = $search) THEN sqlpage.link('/functions.sql', json_object('function', $search)) |
| 5 | +END |
| 6 | +SELECT 'redirect' as component, $redirect as link WHERE $redirect IS NOT NULL; |
| 7 | + |
| 8 | + |
| 9 | +select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; |
| 10 | + |
| 11 | +SELECT 'form' as component, |
| 12 | + 'GET' as method, |
| 13 | + true as auto_submit, |
| 14 | + 'Search documentation' as title; |
| 15 | + |
| 16 | +SELECT 'text' as type, |
| 17 | + 'search' as name, |
| 18 | + '' as label, |
| 19 | + true as autofocus, |
| 20 | + 'Search for components, parameters, functions...' as placeholder, |
| 21 | + $search as value; |
| 22 | + |
| 23 | +SELECT 'text' as component, |
| 24 | + CASE |
| 25 | + WHEN $search IS NULL THEN 'Enter a search term above to find documentation about components, parameters, functions, and blog posts.' |
| 26 | + WHEN NOT EXISTS ( |
| 27 | + SELECT 1 FROM documentation_fts |
| 28 | + WHERE documentation_fts = $search |
| 29 | + ) THEN 'No results found for "' || $search || '".' |
| 30 | + ELSE NULL |
| 31 | + END as contents; |
| 32 | + |
| 33 | +SELECT 'list' as component, |
| 34 | + 'Search Results' as title, |
| 35 | + 'No results found for "' || $search || '".' as empty_description |
| 36 | +WHERE $search IS NOT NULL; |
| 37 | + |
| 38 | +WITH search_results AS ( |
| 39 | + SELECT |
| 40 | + 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 | + ))) |
| 68 | + END as link_data, |
| 69 | + rank |
| 70 | + FROM documentation_fts |
| 71 | + WHERE $search IS NOT NULL |
| 72 | + AND documentation_fts = $search |
| 73 | +) |
| 74 | +SELECT |
| 75 | + title, |
| 76 | + description, |
| 77 | + sqlpage.link(link_data->>'page', link_data->'parameters') as link |
| 78 | +FROM search_results |
| 79 | +ORDER BY |
| 80 | + rank, |
| 81 | + CASE |
| 82 | + WHEN title LIKE 'component:%' THEN 1 |
| 83 | + WHEN title LIKE 'parameter:%' THEN 2 |
| 84 | + WHEN title LIKE 'blog:%' THEN 3 |
| 85 | + WHEN title LIKE 'function:%' THEN 4 |
| 86 | + END, |
| 87 | + description; |
0 commit comments