pub async fn search_image(
        &self,
        query: &str,
        page: Option<u32>,
        is_premium: Option<bool>,
        is_published: Option<bool>,
        styles: &[StyleId],
        age_ranges: &[AgeRangeId],
        affiliations: &[AffiliationId],
        categories: &[CategoryId],
    ) -> anyhow::Result<Option<(Vec<Uuid>, u32, u64)>> {
        let compare_time = Utc::now().timestamp_nanos();

        let client = with_client!(self.inner; None);

        let mut filters = algolia::filter::AndFilter {
            filters: vec![Box::new(media_filter(MediaGroupKind::Image, false))],
        };

        if let Some(is_published) = is_published {
            filters.filters.push(Box::new(CommonFilter {
                filter: CmpFilter::new("publish_at".to_owned(), FilterOperator::Le, compare_time),
                invert: !is_published,
            }))
        }

        if let Some(is_premium) = is_premium {
            filters.filters.push(Box::new(CommonFilter {
                filter: BooleanFilter {
                    facet_name: "is_premium".to_owned(),
                    value: is_premium,
                },
                invert: false,
            }))
        }

        filters_for_ids(&mut filters.filters, "styles", styles);
        filters_for_ids(&mut filters.filters, "age_ranges", age_ranges);
        filters_for_ids(&mut filters.filters, "affiliations", affiliations);
        filters_for_ids(&mut filters.filters, "categories", categories);

        let results: SearchResponse = client
            .search(
                &self.index,
                SearchQuery {
                    query: Some(query),
                    page,
                    get_ranking_info: true,
                    filters: Some(filters),
                    hits_per_page: None,
                },
            )
            .await?;

        let pages = results.page_count.try_into()?;
        let total_hits = results.hit_count as u64;

        let results = results
            .hits
            .into_iter()
            .map(|hit| hit.object_id.parse())
            .collect::<Result<Vec<_>, _>>()?;

        Ok(Some((results, pages, total_hits)))
    }
// todo: return ImageId (can't because of repr issues in sqlx)
return ImageId (can't because of repr issues in sqlx)
return ImageId ( can ' t because of repr issues in sqlx )
pub async fn search_image(
        &self,
        query: &str,
        page: Option<u32>,
        is_premium: Option<bool>,
        is_published: Option<bool>,
        styles: &[StyleId],
        age_ranges: &[AgeRangeId],
        affiliations: &[AffiliationId],
        categories: &[CategoryId],
    ) -> anyhow::Result<Option<(Vec<Uuid>, u32, u64)>> {
        let compare_time = Utc::now().timestamp_nanos();
        let client = with_client!(self.inner; None);
        let mut filters = algolia::filter::AndFilter {
            filters: vec![Box::new(media_filter(MediaGroupKind::Image, false))],
        };
        if let Some(is_published) = is_published {
            filters.filters.push(Box::new(CommonFilter {
                filter: CmpFilter::new("publish_at".to_owned(), FilterOperator::Le, compare_time),
                invert: !is_published,
            }))
        }
        if let Some(is_premium) = is_premium {
            filters.filters.push(Box::new(CommonFilter {
                filter: BooleanFilter {
                    facet_name: "is_premium".to_owned(),
                    value: is_premium,
                },
                invert: false,
            }))
        }
        filters_for_ids(&mut filters.filters, "styles", styles);
        filters_for_ids(&mut filters.filters, "age_ranges", age_ranges);
        filters_for_ids(&mut filters.filters, "affiliations", affiliations);
        filters_for_ids(&mut filters.filters, "categories", categories);
        let results: SearchResponse = client
            .search(
                &self.index,
                SearchQuery {
                    query: Some(query),
                    page,
                    get_ranking_info: true,
                    filters: Some(filters),
                    hits_per_page: None,
                },
            )
            .await?;
        let pages = results.page_count.try_into()?;
        let total_hits = results.hit_count as u64;
        let results = results
            .hits
            .into_iter()
            .map(|hit| hit.object_id.parse())
            .collect::<Result<Vec<_>, _>>()?;
        Ok(Some((results, pages, total_hits)))
    }
pub async fn search_image ( & self , query : & str , page : Option < u32 > , is_premium : Option < bool > , is_published : Option < bool > , styles : & [ StyleId ] , age_ranges : & [ AgeRangeId ] , affiliations : & [ AffiliationId ] , categories : & [ CategoryId ] , ) -> anyhow :: Result < Option < ( Vec < Uuid > , u32 , u64 ) > > { let compare_time = Utc :: now ( ) . timestamp_nanos ( ) ; let client = with_client ! ( self inner None ) ; let mut filters = algolia :: filter :: AndFilter { filters : vec ! [ Box new ( media_filter ( MediaGroupKind Image false ) ) ] , } ; if let Some ( is_published ) = is_published { filters . filters . push ( Box :: new ( CommonFilter { filter : CmpFilter :: new ( " " . to_owned ( ) , FilterOperator :: Le , compare_time ) , invert : ! is_published , } ) ) } if let Some ( is_premium ) = is_premium { filters . filters . push ( Box :: new ( CommonFilter { filter : BooleanFilter { facet_name : " " . to_owned ( ) , value : is_premium , } , invert : false , } ) ) } filters_for_ids ( & mut filters . filters , " " , styles ) ; filters_for_ids ( & mut filters . filters , " " , age_ranges ) ; filters_for_ids ( & mut filters . filters , " " , affiliations ) ; filters_for_ids ( & mut filters . filters , " " , categories ) ; let results : SearchResponse = client . search ( & self . index , SearchQuery { query : Some ( query ) , page , get_ranking_info : true , filters : Some ( filters ) , hits_per_page : None , } , ) . await ? ; let pages = results . page_count . try_into ( ) ? ; let total_hits = results . hit_count as u64 ; let results = results . hits . into_iter ( ) . map ( | hit | hit . object_id . parse ( ) ) . collect :: < Result < Vec < _ > , _ > > ( ) ? ; Ok ( Some ( ( results , pages , total_hits ) ) ) }
todo: return ImageId (can't because of repr issues in sqlx)
todo : return ImageId ( can ' t because of repr issues in sqlx )
&self
query
&str
page
Option<u32>
is_premium
Option<bool>
is_published
Option<bool>
styles
&[StyleId]
age_ranges
&[AgeRangeId]
affiliations
&[AffiliationId]
categories
&[CategoryId]
&self
query
&str
page
Option<u32>
is_premium
Option<bool>
is_published
Option<bool>
styles
&[StyleId]
age_ranges
&[AgeRangeId]
affiliations
&[AffiliationId]
categories
&[CategoryId]