-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheme.sql
155 lines (149 loc) · 5.81 KB
/
scheme.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
CREATE SEQUENCE version_id_seq;
CREATE TABLE versions (
id integer PRIMARY KEY DEFAULT nextval('version_id_seq'),
key varchar(255) not NULL,
commit varchar(40) not NULL,
hidden BOOLEAN DEFAULT FALSE,
tree TEXT,
search TEXT,
show_samples BOOLEAN DEFAULT TRUE
);
CREATE SEQUENCE page_id_seq;
--- CREATE TYPE page_type AS ENUM ('namespace', 'class', 'typedef', 'enum'); -- not used now
CREATE TABLE pages (
id integer PRIMARY KEY DEFAULT nextval('page_id_seq'),
type varchar(100),
version_id integer references versions(id),
url varchar(255) not null,
full_name varchar(255),
content jsonb
);
create table sitemap (
page_url varchar(255),
version_id integer references versions(id),
last_modified bigint
);
-- not used now
CREATE MATERIALIZED VIEW search_table AS
select
version_id,
type,
json ->> 'name' as name,
full_name || '.' || (json ->> 'name') as full_name,
regexp_replace(json ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(json ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(json ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
full_name || '#' || (json ->> 'name') as link
FROM
(select json_array_elements ((content -> 'methods') :: json) as json, full_name, version_id, 'method'::TEXT as type
from pages
where type = 'class') AS data
UNION ALL
-- overrides from class methods
select
version_id,
type,
json ->> 'name' as name,
full_name || '.' || (json ->> 'name') as full_name,
regexp_replace(json ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(json ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(json ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
full_name || '#' || (json ->> 'name') as link
FROM
(select json_array_elements ((json -> 'overrides') :: json) as json, full_name, version_id, type FROM
(select json_array_elements ((content -> 'methods') :: json) as json, full_name, version_id, 'method'::TEXT as type
from pages
where type = 'class') AS data) as data2
UNION ALL
SELECT
version_id,
type,
json ->> 'name' as name,
json ->> 'full-name' as full_name,
regexp_replace(json ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(json ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(json ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
full_name || '#' || (json ->> 'name') as link
FROM
(select json_array_elements ((content -> 'functions') :: json) as json, full_name, version_id, 'function'::TEXT as type
from pages
where type = 'namespace') AS data
UNION ALL
SELECT
version_id,
type,
json ->> 'name' as name,
json ->> 'full-name' as full_name,
regexp_replace(json ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(json ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(json ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
full_name || '#' || (json ->> 'name') as link
FROM
(select json_array_elements ((content -> 'constants') :: json) as json, full_name, version_id, 'constant'::TEXT as type
from pages
where type = 'namespace') AS data
UNION ALL
---select fields from enum as enum to searching on them
SELECT
version_id,
type,
name,
fn,
regexp_replace(json ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(json ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(json ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
fn as link
FROM
(select json_array_elements ((content -> 'fields') :: json) as json, content ->> 'name' as name,
full_name as fn, version_id, 'enum'::TEXT as type
from pages
where type = 'enum') AS data
UNION ALL
SELECT
version_id,
type,
content ->> 'name' as name,
content ->> 'full-name' as full_name,
regexp_replace(content ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(content ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(content ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
url as link
FROM pages where type = 'class'
UNION ALL
SELECT
version_id,
type,
content ->> 'name' as name,
content ->> 'full-name' as full_name,
regexp_replace(content ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(content ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(content ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
url as link
FROM pages where type = 'enum'
UNION ALL
SELECT
version_id,
type,
content ->> 'name' as name,
content ->> 'full-name' as full_name,
regexp_replace(content ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(content ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(content ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
url as link
FROM pages where type = 'typedef'
UNION ALL
SELECT
version_id,
type,
content ->> 'name' as name,
content ->> 'full-name' as full_name,
regexp_replace(content ->> 'short-description', '(<[^>]*>|{[^}]*})', '', 'g') as short_description,
regexp_replace(content ->> 'description', '(<[^>]*>|{[^}]*})', '', 'g') as description,
regexp_replace(content ->> 'detailed', '(<[^>]*>|{[^}]*})', '', 'g') as detailed,
url as link
FROM pages where type = 'namespace';
-- To change pages type:
-- ALTER TABLE pages ALTER COLUMN content TYPE JSONB USING content::JSONB;
-- ALTER TABLE pages ALTER COLUMN content TYPE TEXT USING content;
-- To refresh view:
-- REFRESH MATERIALIZED VIEW search_table;