fix fts table defs

This commit is contained in:
Joe Ardent 2024-02-03 15:04:05 -08:00
parent 24c67bc529
commit efec2e670f
2 changed files with 22 additions and 9 deletions

View File

@ -1,5 +1,16 @@
create virtual table if not exists star_search using fts5(name, id);
insert into star_search(name, id) select name, id from stars;
create virtual table if not exists star_search using fts5 (name, id UNINDEXED, tokenize = 'trigram', content = 'stars', content_rowid=rowid);
create trigger if not exists stars_update_search after insert on stars begin
insert into star_search (rowid, name, id) values (new.rowid, new.name, new.id);
end;
create trigger if not exists stars_delete_search after delete on stars begin
insert into star_search (star_search, rowid, name, id) values ('delete', old.rowid, old.name, old.id);
end;
create virtual table if not exists watch_search using fts5 (title, id UNINDEXED, tokenize = 'trigram', content = 'watches', content_rowid=rowid);
create trigger if not exists watches_update_search after insert on watches begin
insert into watch_search (rowid, title, id) values (new.rowid, new.title, new.id);
end;
create trigger if not exists watches_delete_search after delete on watches begin
insert into watch_search (watch_search, rowid, title, id) values ('delete', old.rowid, old.title, old.id);
end;
create virtual table if not exists watch_search using fts5(title, id);
insert into watch_search(title, id) select title, id from watches;

View File

@ -250,11 +250,13 @@ pub async fn get_search_watch(
let query = if search_query == SearchQuery::default() {
query_as(DEFAULT_WATCHES_QUERY)
} else if let Some(title) = search_query.title {
let q = format!("%{title}%");
query_as("select * from watches where title like ?").bind(q)
} else if let Some(search) = search_query.search {
let q = format!("%{search}");
query_as("select * from watches where title like ?").bind(q)
query_as(
"select * from watches where id in (select id from watch_search where title match ?)",
)
.bind(title)
} else if let Some(ref search) = search_query.search {
query_as("select * from watches where id in (select id from watch_search where title match ?) outer join (select * from stars where id in (select id from star_search where name match ?)) s")
.bind(search).bind(search)
} else {
query_as(DEFAULT_WATCHES_QUERY)
};