simplify search
This commit is contained in:
parent
ba1f9119e8
commit
4e2e8e585f
1 changed files with 6 additions and 18 deletions
|
@ -4,7 +4,7 @@ use axum::{
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{query_as, SqlitePool};
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
misc_util::empty_string_as_none, AuthSession, OptionalOptionalUser, Star, User, Watch,
|
misc_util::empty_string_as_none, AuthSession, OptionalOptionalUser, Star, User, Watch,
|
||||||
|
@ -40,29 +40,17 @@ pub async fn get_search_watch(
|
||||||
State(pool): State<SqlitePool>,
|
State(pool): State<SqlitePool>,
|
||||||
search: Query<SearchQuery>,
|
search: Query<SearchQuery>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
const DEFAULT_WATCHES_QUERY: &str =
|
|
||||||
"select * from (select * from watches order by random() limit 50) order by release_date asc";
|
|
||||||
|
|
||||||
let user = auth.user;
|
let user = auth.user;
|
||||||
let search_query = search.0;
|
let search_query = search.0;
|
||||||
|
|
||||||
let query = if search_query == SearchQuery::default() {
|
let watches: Vec<Watch> = if let Some(title) = search_query.title {
|
||||||
query_as(DEFAULT_WATCHES_QUERY)
|
sqlx::query_as(
|
||||||
} else if let Some(title) = search_query.title {
|
"select * from watches where id in (select id from watch_search where title match ? order by rank)").bind(
|
||||||
query_as(
|
&title).fetch_all(&pool).await.unwrap_or_default()
|
||||||
"select * from watches where id in (select id from watch_search where title match ? order by rank)",
|
|
||||||
)
|
|
||||||
.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 {
|
} else {
|
||||||
query_as(DEFAULT_WATCHES_QUERY)
|
sqlx::query_as("select * from (select * from watches order by random() limit 50) order by release_date asc").fetch_all(&pool).await.unwrap_or_default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// until tantivy search
|
|
||||||
let watches: Vec<Watch> = query.fetch_all(&pool).await.unwrap();
|
|
||||||
|
|
||||||
SearchPage {
|
SearchPage {
|
||||||
results: watches,
|
results: watches,
|
||||||
user,
|
user,
|
||||||
|
|
Loading…
Reference in a new issue