forked from stakwork/sphinx-tribes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tribes.sql
145 lines (119 loc) · 3.32 KB
/
tribes.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
-- TRIBES
CREATE TABLE tribes (
uuid TEXT NOT NULL PRIMARY KEY,
owner_pub_key TEXT NOT NULL,
owner_alias TEXT,
group_key TEXT,
name TEXT,
description TEXT,
tags TEXT[] not null default '{}',
img TEXT,
price_to_join BIGINT,
price_per_message BIGINT,
escrow_amount BIGINT,
escrow_millis BIGINT,
created timestamptz,
updated timestamptz,
member_count BIGINT,
unlisted boolean,
private boolean,
deleted boolean,
app_url TEXT,
feed_url TEXT,
second_brain_url TEXT,
feed_type INT,
last_active BIGINT,
bots TEXT,
owner_route_hint TEXT,
unique_name TEXT,
pin TEXT,
preview TEXT,
profile_filters TEXT,
second_brain_url TEXT
);
-- for searching
ALTER TABLE tribes ADD COLUMN tsv tsvector;
UPDATE tribes SET tsv =
setweight(to_tsvector(name), 'A') ||
setweight(to_tsvector(description), 'B') ||
setweight(array_to_tsvector(tags), 'C');
CREATE INDEX tribes_tsv ON tribes USING GIN(tsv);
-- select
SELECT name, description, tags
FROM tribes, to_tsquery('foo') q
WHERE tsv @@ q;
-- rank
SELECT name, uuid, description, ts_rank(tsv, q) as rank
FROM tribes, to_tsquery('anothe') q
WHERE tsv @@ q
ORDER BY rank DESC
LIMIT 12;
-- plainto_tsquery is another way
-- BOTS
CREATE TABLE bots (
uuid TEXT NOT NULL PRIMARY KEY,
owner_pub_key TEXT NOT NULL,
owner_alias TEXT,
name TEXT,
unique_name TEXT,
description TEXT,
tags TEXT[] not null default '{}',
img TEXT,
price_per_use BIGINT,
created timestamptz,
updated timestamptz,
member_count BIGINT,
unlisted boolean,
deleted boolean
);
-- for searching
ALTER TABLE bots ADD COLUMN tsv tsvector;
UPDATE bots SET tsv =
setweight(to_tsvector(name), 'A') ||
setweight(to_tsvector(description), 'B') ||
setweight(array_to_tsvector(tags), 'C');
CREATE INDEX bots_tsv ON bots USING GIN(tsv);
SELECT uuid, unique_name, ts_rank(tsv, q) as rank
FROM bots, to_tsquery('btc') q
WHERE tsv @@ q
ORDER BY rank DESC LIMIT 2 OFFSET 0;
-- PEOPLE
CREATE TABLE people (
id SERIAL PRIMARY KEY,
uuid TEXT,
owner_pub_key TEXT NOT NULL,
owner_alias TEXT,
owner_route_hint TEXT,
owner_contact_key TEXT,
description TEXT,
tags TEXT[] not null default '{}',
img TEXT,
created timestamptz,
updated timestamptz,
unlisted boolean,
deleted boolean,
unique_name TEXT,
price_to_meet BIGINT,
extras JSONB,
twitter_confirmed BOOLEAN,
github_issues JSONB
);
ALTER TABLE people ADD COLUMN tsv tsvector;
UPDATE people SET tsv =
setweight(to_tsvector(owner_alias), 'A') ||
setweight(to_tsvector(description), 'B') ||
setweight(array_to_tsvector(tags), 'C');
CREATE INDEX people_tsv ON people USING GIN(tsv);
INSERT into people (owner_alias, owner_pub_key, description, tags, img, unique_name)
VALUES
('Evan', '02290714deafd0cb33d2be3b634fc977a98a9c9fa1dd6c53cf17d99b350c08c67b', 'Im cool', '{"tag1"}', 'https://evan.cool/img/trumpetplay.jpg', 'evan');
INSERT into people (owner_alias, owner_pub_key, description, tags, img, unique_name)
VALUES
('Jesse', '038c3c1f4d304c7b997fecfdaf8fdfc2215405942c025349b45de9dfe6fdb8a43e', 'Im cool', '{"tag1"}', 'https://cliparting.com/wp-content/uploads/2018/03/cool-pictures-2018-2.jpg', 'jesse');
ALTER TABLE IF EXISTS tribes ADD COLUMN IF NOT EXISTS preview VARCHAR NULL;
CREATE TABLE connectioncodes {
id SERIAL PRIMARY KEY,
connection_string TEXT,
is_used boolean,
date_created timestamptz
}