diff --git a/annim/src/graphql/mod.rs b/annim/src/graphql/mod.rs index 325a4d7..28f5e74 100644 --- a/annim/src/graphql/mod.rs +++ b/annim/src/graphql/mod.rs @@ -157,14 +157,24 @@ impl MetadataQuery { &self, ctx: &Context<'ctx>, keyword: String, - count: usize, + #[graphql(default = 20)] count: usize, + #[graphql(default = 0)] offset: usize, ) -> anyhow::Result> { let search_manager = ctx.data::().unwrap(); let query = search_manager.query_parser().parse_query(&keyword)?; - let searcher = search_manager.searcher(); + let query_not = TermQuery::new( + Term::from_field_i64(search_manager.fields.track_db_id, i64::MAX), + Default::default(), + ); + let query = BooleanQuery::new(vec![ + (Occur::Must, query), + // AND -track_db_id:9223372036854775807 + (Occur::MustNot, Box::new(query_not)), + ]); - let top_docs = searcher.search(&*query, &TopDocs::with_limit(count))?; + let searcher = search_manager.searcher(); + let top_docs = searcher.search(&query, &TopDocs::with_limit(count).and_offset(offset))?; let result: Vec<_> = top_docs .into_iter() @@ -218,7 +228,7 @@ impl MetadataMutation { &self, ctx: &Context<'ctx>, input: input::AddAlbumInput, - commit: Option, + #[graphql(default = true)] commit: bool, ) -> anyhow::Result { require_auth(ctx)?; let db = ctx.data::().unwrap(); @@ -251,7 +261,7 @@ impl MetadataMutation { } txn.commit().await?; - if commit.unwrap_or(true) { + if commit { index_writer.commit().await?; }