mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-05-24 17:01:09 -04:00
Add keyword search
This commit is contained in:
@@ -83,7 +83,7 @@ export const getLovers: APIHandler<'get-lovers'> = async (props, _auth) => {
|
||||
where(`data->>'userDeleted' != 'true' or data->>'userDeleted' is null`),
|
||||
|
||||
name &&
|
||||
where(`lower(users.name) ilike '%' || lower($(name)) || '%'`, { name }),
|
||||
where(`lower(users.name) ilike '%' || lower($(name)) || '%' or lower(bio::text) ilike '%' || lower($(name)) || '%'`, { name }),
|
||||
|
||||
genders?.length && where(`gender = ANY($(gender))`, { gender: genders }),
|
||||
|
||||
|
||||
@@ -20,4 +20,7 @@ BEGIN;
|
||||
\i backend/supabase/user_notifications.sql
|
||||
\i backend/supabase/functions_others.sql
|
||||
\i backend/supabase/reports.sql
|
||||
\i backend/supabase/migrations/20250910_bio_to_jsonb.sql
|
||||
\i backend/supabase/migrations/20250910_add_bio_text.sql
|
||||
\i backend/supabase/migrations/20250910_pg_trgm.sql
|
||||
COMMIT;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
-- This file is copied from https://github.com/manifoldmarkets/manifold/blob/main/backend/supabase/reports.sql
|
||||
create table if not exists
|
||||
reports (
|
||||
content_id text not null,
|
||||
content_owner_id text not null,
|
||||
content_type text not null,
|
||||
created_time timestamp with time zone default now(),
|
||||
description text,
|
||||
id text default uuid_generate_v4 () not null,
|
||||
parent_id text,
|
||||
parent_type text,
|
||||
user_id text not null
|
||||
);
|
||||
|
||||
-- Foreign Keys
|
||||
alter table reports
|
||||
add constraint reports_content_owner_id_fkey foreign key (content_owner_id) references users (id);
|
||||
|
||||
alter table reports
|
||||
add constraint reports_user_id_fkey foreign key (user_id) references users (id);
|
||||
|
||||
-- Row Level Security
|
||||
alter table reports enable row level security;
|
||||
22
backend/supabase/migrations/20250910_add_bio_text.sql
Normal file
22
backend/supabase/migrations/20250910_add_bio_text.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
ALTER TABLE lovers ADD COLUMN bio_text tsvector;
|
||||
|
||||
CREATE OR REPLACE FUNCTION lovers_bio_tsvector_update()
|
||||
RETURNS trigger AS $$
|
||||
BEGIN
|
||||
new.bio_text := to_tsvector(
|
||||
'english',
|
||||
(
|
||||
SELECT string_agg(trim(both '"' from x::text), ' ')
|
||||
FROM jsonb_path_query(new.bio, '$.**.text'::jsonpath) AS x
|
||||
)
|
||||
);
|
||||
RETURN new;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER lovers_bio_tsvector_trigger
|
||||
BEFORE INSERT OR UPDATE OF bio ON lovers
|
||||
FOR EACH ROW EXECUTE FUNCTION lovers_bio_tsvector_update();
|
||||
|
||||
|
||||
create index on lovers using gin(bio_text);
|
||||
5
backend/supabase/migrations/20250910_bio_to_jsonb.sql
Normal file
5
backend/supabase/migrations/20250910_bio_to_jsonb.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- 1. Drop the old column
|
||||
alter table lovers drop column if exists bio;
|
||||
|
||||
-- 2. Add the new column as jsonb
|
||||
alter table lovers add column bio jsonb;
|
||||
4
backend/supabase/migrations/20250910_pg_trgm.sql
Normal file
4
backend/supabase/migrations/20250910_pg_trgm.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
create extension if not exists pg_trgm;
|
||||
|
||||
CREATE INDEX lovers_bio_trgm_idx
|
||||
ON lovers USING gin ((bio::text) gin_trgm_ops);
|
||||
@@ -61,7 +61,7 @@ export const Search = (props: {
|
||||
<Row className={'mb-2 justify-between gap-2'}>
|
||||
<Input
|
||||
value={filters.name ?? ''}
|
||||
placeholder={'Search name'}
|
||||
placeholder={'Search anything...'}
|
||||
className={'w-full max-w-xs'}
|
||||
onChange={(e) => {
|
||||
updateFilter({ name: e.target.value })
|
||||
|
||||
@@ -53,7 +53,11 @@ export function ProfilesHome() {
|
||||
if (!user) return;
|
||||
setIsReloading(true);
|
||||
const current = ++id.current;
|
||||
api('get-lovers', removeNullOrUndefinedProps({limit: 20, compatibleWithUserId: user?.id, ...filters}) as any)
|
||||
api('get-lovers', removeNullOrUndefinedProps({
|
||||
limit: 20,
|
||||
compatibleWithUserId: user?.id,
|
||||
...filters
|
||||
}) as any)
|
||||
.then(({lovers}) => {
|
||||
if (current === id.current) setLovers(lovers);
|
||||
})
|
||||
@@ -74,7 +78,8 @@ export function ProfilesHome() {
|
||||
const result = await api('get-lovers', removeNullOrUndefinedProps({
|
||||
limit: 20,
|
||||
compatibleWithUserId: user?.id,
|
||||
after: lastLover?.id.toString(), ...filters
|
||||
after: lastLover?.id.toString(),
|
||||
...filters
|
||||
}) as any);
|
||||
if (result.lovers.length === 0) return false;
|
||||
setLovers((prev) => (prev ? [...prev, ...result.lovers] : result.lovers));
|
||||
|
||||
Reference in New Issue
Block a user