Make search query mandatory (#5772)
* Make search query mandatory * update js client
This commit is contained in:
parent
b4c3cda061
commit
ea9b19bea8
@ -31,7 +31,7 @@
|
||||
"eslint-plugin-prettier": "^5.4.0",
|
||||
"jest": "^29.5.0",
|
||||
"joi": "^17.13.3",
|
||||
"lemmy-js-client": "1.0.0-rename-timestamp-to-at.4",
|
||||
"lemmy-js-client": "1.0.0-search-query-mandatory.1",
|
||||
"prettier": "^3.5.3",
|
||||
"ts-jest": "^29.3.2",
|
||||
"tsoa": "^6.6.0",
|
||||
|
10
api_tests/pnpm-lock.yaml
generated
10
api_tests/pnpm-lock.yaml
generated
@ -36,8 +36,8 @@ importers:
|
||||
specifier: ^17.13.3
|
||||
version: 17.13.3
|
||||
lemmy-js-client:
|
||||
specifier: 1.0.0-rename-timestamp-to-at.4
|
||||
version: 1.0.0-rename-timestamp-to-at.4
|
||||
specifier: 1.0.0-search-query-mandatory.1
|
||||
version: 1.0.0-search-query-mandatory.1
|
||||
prettier:
|
||||
specifier: ^3.5.3
|
||||
version: 3.5.3
|
||||
@ -1594,8 +1594,8 @@ packages:
|
||||
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
lemmy-js-client@1.0.0-rename-timestamp-to-at.4:
|
||||
resolution: {integrity: sha512-tEp92LODxqLIyru7qaMFVuXEmsusSDzG2V7QYctBYGfbJzsoUEogtuI9Gla5MlL6lT9l/hOLSv/ujqxdS0FLAg==}
|
||||
lemmy-js-client@1.0.0-search-query-mandatory.1:
|
||||
resolution: {integrity: sha512-Km4w/7BjL/aMnVVADQ6eqdGAYPzaXzOaCbeideWJ4XbNR3ESzXAuMyjK9ynw9Q65NWzXyAFs5VoaTALFVjU3aA==}
|
||||
|
||||
leven@3.1.0:
|
||||
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
|
||||
@ -4404,7 +4404,7 @@ snapshots:
|
||||
|
||||
kleur@3.0.3: {}
|
||||
|
||||
lemmy-js-client@1.0.0-rename-timestamp-to-at.4:
|
||||
lemmy-js-client@1.0.0-search-query-mandatory.1:
|
||||
dependencies:
|
||||
'@tsoa/runtime': 6.6.0
|
||||
transitivePeerDependencies:
|
||||
|
@ -566,7 +566,7 @@ test("Dont receive community activities after unsubscribe", async () => {
|
||||
// await longDelay();
|
||||
|
||||
let form: Search = {
|
||||
search_term: postRes.post_view.post.name,
|
||||
q: postRes.post_view.post.name,
|
||||
type_: "Posts",
|
||||
listing_type: "All",
|
||||
};
|
||||
|
@ -327,7 +327,7 @@ export async function searchPostLocal(
|
||||
post: Post,
|
||||
): Promise<PostView | undefined> {
|
||||
let form: Search = {
|
||||
search_term: post.name,
|
||||
q: post.name,
|
||||
type_: "Posts",
|
||||
listing_type: "All",
|
||||
};
|
||||
|
@ -47,7 +47,7 @@ pub async fn search(
|
||||
|
||||
let pool = &mut context.pool();
|
||||
let search_fut = SearchCombinedQuery {
|
||||
search_term: data.search_term.clone(),
|
||||
search_term: Some(data.q.clone()),
|
||||
community_id,
|
||||
creator_id: data.creator_id,
|
||||
type_: data.type_,
|
||||
@ -65,24 +65,19 @@ pub async fn search(
|
||||
}
|
||||
.list(pool, &local_user_view, &site_view.site);
|
||||
|
||||
let results = if let Some(q) = &data.search_term {
|
||||
let resolve_fut = resolve_object_internal(q, &local_user_view, &context);
|
||||
let (search, resolve) = join(search_fut, resolve_fut).await;
|
||||
let mut search = search?;
|
||||
// Ignore resolve errors as query may not be Activitypub object
|
||||
if let Ok(resolve) = resolve {
|
||||
search.push(resolve);
|
||||
}
|
||||
search
|
||||
} else {
|
||||
search_fut.await?
|
||||
};
|
||||
let resolve_fut = resolve_object_internal(&data.q, &local_user_view, &context);
|
||||
let (search, resolve) = join(search_fut, resolve_fut).await;
|
||||
let mut search = search?;
|
||||
// Ignore resolve errors as query may not be Activitypub object
|
||||
if let Ok(resolve) = resolve {
|
||||
search.push(resolve);
|
||||
}
|
||||
|
||||
let next_page = results.last().map(PaginationCursorBuilder::to_cursor);
|
||||
let prev_page = results.first().map(PaginationCursorBuilder::to_cursor);
|
||||
let next_page = search.last().map(PaginationCursorBuilder::to_cursor);
|
||||
let prev_page = search.first().map(PaginationCursorBuilder::to_cursor);
|
||||
|
||||
Ok(Json(SearchResponse {
|
||||
results,
|
||||
results: search,
|
||||
next_page,
|
||||
prev_page,
|
||||
}))
|
||||
|
@ -139,8 +139,7 @@ pub enum SearchCombinedView {
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// Searches the site, given a search term, and some optional filters.
|
||||
pub struct Search {
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub search_term: Option<String>,
|
||||
pub q: String,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub community_id: Option<CommunityId>,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
|
Loading…
x
Reference in New Issue
Block a user