pub async fn search_image(
        &self,
        query: &str,
        page: Option<u32>,
        is_premium: Option<bool>,
        is_published: Option<bool>,
        styles: &[ImageStyleId],
        age_ranges: &[AgeRangeId],
        affiliations: &[AffiliationId],
        categories: &[CategoryId],
        tags: &[ImageTagIndex],
        tags_priority: &[ImageTagIndex],
    ) -> anyhow::Result<Option<(Vec<Uuid>, u32, u64)>> {
        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: TagFilter(PUBLISHED_TAG.to_owned()),
                invert: !is_published,
            }))
        }

        if let Some(is_premium) = is_premium {
            filters.filters.push(Box::new(CommonFilter {
                filter: TagFilter(PREMIUM_TAG.to_owned()),
                invert: !is_premium,
            }))
        }

        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);
        filters_for_ints(&mut filters.filters, "image_tags", tags);

        let optional_filters = scored_int_filtering(
            "image_tags",
            &tags_priority
                .iter()
                .map(|it| it.0 as i64)
                .collect::<Vec<i64>>(),
        );

        let results: SearchResponse = self
            .inner
            .search(
                &self.media_index,
                SearchQuery {
                    query: Some(query),
                    page,
                    get_ranking_info: true,
                    filters: Some(filters),
                    optional_filters: Some(optional_filters),
                    hits_per_page: None,
                    sum_or_filters_scores: true,
                },
            )
            .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: &[ImageStyleId],
        age_ranges: &[AgeRangeId],
        affiliations: &[AffiliationId],
        categories: &[CategoryId],
        tags: &[ImageTagIndex],
        tags_priority: &[ImageTagIndex],
    ) -> anyhow::Result<Option<(Vec<Uuid>, u32, u64)>> {
        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: TagFilter(PUBLISHED_TAG.to_owned()),
                invert: !is_published,
            }))
        }
        if let Some(is_premium) = is_premium {
            filters.filters.push(Box::new(CommonFilter {
                filter: TagFilter(PREMIUM_TAG.to_owned()),
                invert: !is_premium,
            }))
        }
        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);
        filters_for_ints(&mut filters.filters, "image_tags", tags);
        let optional_filters = scored_int_filtering(
            "image_tags",
            &tags_priority
                .iter()
                .map(|it| it.0 as i64)
                .collect::<Vec<i64>>(),
        );
        let results: SearchResponse = self
            .inner
            .search(
                &self.media_index,
                SearchQuery {
                    query: Some(query),
                    page,
                    get_ranking_info: true,
                    filters: Some(filters),
                    optional_filters: Some(optional_filters),
                    hits_per_page: None,
                    sum_or_filters_scores: true,
                },
            )
            .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 : & [ ImageStyleId ] , age_ranges : & [ AgeRangeId ] , affiliations : & [ AffiliationId ] , categories : & [ CategoryId ] , tags : & [ ImageTagIndex ] , tags_priority : & [ ImageTagIndex ] , ) -> anyhow :: Result < Option < ( Vec < Uuid > , u32 , u64 ) > > { 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 : TagFilter ( PUBLISHED_TAG . to_owned ( ) ) , invert : ! is_published , } ) ) } if let Some ( is_premium ) = is_premium { filters . filters . push ( Box :: new ( CommonFilter { filter : TagFilter ( PREMIUM_TAG . to_owned ( ) ) , invert : ! is_premium , } ) ) } 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 ) ; filters_for_ints ( & mut filters . filters , " " , tags ) ; let optional_filters = scored_int_filtering ( " " , & tags_priority . iter ( ) . map ( | it | it . 0 as i64 ) . collect :: < Vec < i64 > > ( ) , ) ; let results : SearchResponse = self . inner . search ( & self . media_index , SearchQuery { query : Some ( query ) , page , get_ranking_info : true , filters : Some ( filters ) , optional_filters : Some ( optional_filters ) , hits_per_page : None , sum_or_filters_scores : true , } , ) . 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
&[ImageStyleId]
age_ranges
&[AgeRangeId]
affiliations
&[AffiliationId]
categories
&[CategoryId]
tags
&[ImageTagIndex]
tags_priority
&[ImageTagIndex]
&self
query
&str
page
Option<u32>
is_premium
Option<bool>
is_published
Option<bool>
styles
&[ImageStyleId]
age_ranges
&[AgeRangeId]
affiliations
&[AffiliationId]
categories
&[CategoryId]
tags
&[ImageTagIndex]
tags_priority
&[ImageTagIndex]