2929from meilisearch_python_sdk .models .settings import (
3030 Embedders ,
3131 Faceting ,
32+ FilterableAttributeFeatures ,
33+ FilterableAttributes ,
3234 HuggingFaceEmbedder ,
3335 LocalizedAttributes ,
3436 MeilisearchSettings ,
@@ -990,6 +992,7 @@ async def facet_search(
990992 vector : list [float ] | None = None ,
991993 locales : list [str ] | None = None ,
992994 retrieve_vectors : bool | None = None ,
995+ exhaustive_facet_count : bool | None = None ,
993996 ) -> FacetSearchResults :
994997 """Search the index.
995998
@@ -1043,6 +1046,9 @@ async def facet_search(
10431046 locales: Specifies the languages for the search. This parameter can only be used with
10441047 Milisearch >= v1.10.0. Defaults to None letting the Meilisearch pick.
10451048 retrieve_vectors: Return document vector data with search result.
1049+ exhaustive_facet_count: forcing the facet search to compute the facet counts the same
1050+ way as the paginated search. This parameter can only be used with Milisearch >=
1051+ v1.14.0. Defaults to None.
10461052
10471053 Returns:
10481054 Results of the search
@@ -1091,6 +1097,7 @@ async def facet_search(
10911097 vector = vector ,
10921098 locales = locales ,
10931099 retrieve_vectors = retrieve_vectors ,
1100+ exhaustive_facet_count = exhaustive_facet_count ,
10941101 )
10951102 search_url = f"{ self ._base_url_with_uid } /facet-search"
10961103
@@ -1120,6 +1127,7 @@ async def facet_search(
11201127 show_ranking_score_details = show_ranking_score_details ,
11211128 ranking_score_threshold = ranking_score_threshold ,
11221129 vector = vector ,
1130+ exhaustive_facet_count = exhaustive_facet_count ,
11231131 )
11241132
11251133 if self ._concurrent_facet_search_plugins :
@@ -1152,6 +1160,7 @@ async def facet_search(
11521160 show_ranking_score_details = show_ranking_score_details ,
11531161 ranking_score_threshold = ranking_score_threshold ,
11541162 vector = vector ,
1163+ exhaustive_facet_count = exhaustive_facet_count ,
11551164 )
11561165 )
11571166
@@ -1195,6 +1204,7 @@ async def facet_search(
11951204 show_ranking_score_details = show_ranking_score_details ,
11961205 ranking_score_threshold = ranking_score_threshold ,
11971206 vector = vector ,
1207+ exhaustive_facet_count = exhaustive_facet_count ,
11981208 )
11991209 )
12001210
@@ -3568,11 +3578,11 @@ async def reset_synonyms(self) -> TaskInfo:
35683578
35693579 return TaskInfo (** response .json ())
35703580
3571- async def get_filterable_attributes (self ) -> list [str ] | None :
3581+ async def get_filterable_attributes (self ) -> list [str ] | list [ FilterableAttributes ] | None :
35723582 """Get filterable attributes of the index.
35733583
35743584 Returns:
3575- List containing the filterable attributes of the index.
3585+ Filterable attributes of the index.
35763586
35773587 Raises:
35783588 MeilisearchCommunicationError: If there was an error communicating with the server.
@@ -3589,10 +3599,24 @@ async def get_filterable_attributes(self) -> list[str] | None:
35893599 if not response .json ():
35903600 return None
35913601
3592- return response .json ()
3602+ response_json = response .json ()
3603+
3604+ if isinstance (response_json [0 ], str ):
3605+ return response_json
3606+
3607+ filterable_attributes = []
3608+ for r in response_json :
3609+ filterable_attributes .append (
3610+ FilterableAttributes (
3611+ attribute_patterns = r ["attributePatterns" ],
3612+ features = FilterableAttributeFeatures (** r ["features" ]),
3613+ )
3614+ )
3615+
3616+ return filterable_attributes
35933617
35943618 async def update_filterable_attributes (
3595- self , body : list [str ], * , compress : bool = False
3619+ self , body : list [str ] | list [ FilterableAttributes ] , * , compress : bool = False
35963620 ) -> TaskInfo :
35973621 """Update filterable attributes of the index.
35983622
@@ -3613,8 +3637,16 @@ async def update_filterable_attributes(
36133637 >>> index = client.index("movies")
36143638 >>> await index.update_filterable_attributes(["genre", "director"])
36153639 """
3640+ payload : list [str | JsonDict ] = []
3641+
3642+ for b in body :
3643+ if isinstance (b , FilterableAttributes ):
3644+ payload .append (b .model_dump (by_alias = True ))
3645+ else :
3646+ payload .append (b )
3647+
36163648 response = await self ._http_requests .put (
3617- f"{ self ._settings_url } /filterable-attributes" , body , compress = compress
3649+ f"{ self ._settings_url } /filterable-attributes" , payload , compress = compress
36183650 )
36193651
36203652 return TaskInfo (** response .json ())
@@ -5292,6 +5324,7 @@ def facet_search(
52925324 vector : list [float ] | None = None ,
52935325 locales : list [str ] | None = None ,
52945326 retrieve_vectors : bool | None = None ,
5327+ exhaustive_facet_count : bool | None = None ,
52955328 ) -> FacetSearchResults :
52965329 """Search the index.
52975330
@@ -5345,6 +5378,9 @@ def facet_search(
53455378 locales: Specifies the languages for the search. This parameter can only be used with
53465379 Milisearch >= v1.10.0. Defaults to None letting the Meilisearch pick.
53475380 retrieve_vectors: Return document vector data with search result.
5381+ exhaustive_facet_count: forcing the facet search to compute the facet counts the same
5382+ way as the paginated search. This parameter can only be used with Milisearch >=
5383+ v1.14.0. Defaults to None.
53485384
53495385 Returns:
53505386 Results of the search
@@ -5393,6 +5429,7 @@ def facet_search(
53935429 vector = vector ,
53945430 locales = locales ,
53955431 retrieve_vectors = retrieve_vectors ,
5432+ exhaustive_facet_count = exhaustive_facet_count ,
53965433 )
53975434
53985435 if self ._pre_facet_search_plugins :
@@ -5421,6 +5458,7 @@ def facet_search(
54215458 show_ranking_score_details = show_ranking_score_details ,
54225459 ranking_score_threshold = ranking_score_threshold ,
54235460 vector = vector ,
5461+ exhaustive_facet_count = exhaustive_facet_count ,
54245462 )
54255463
54265464 response = self ._http_requests .post (f"{ self ._base_url_with_uid } /facet-search" , body = body )
@@ -7156,7 +7194,7 @@ def reset_synonyms(self) -> TaskInfo:
71567194
71577195 return TaskInfo (** response .json ())
71587196
7159- def get_filterable_attributes (self ) -> list [str ] | None :
7197+ def get_filterable_attributes (self ) -> list [str ] | list [ FilterableAttributes ] | None :
71607198 """Get filterable attributes of the index.
71617199
71627200 Returns:
@@ -7177,9 +7215,25 @@ def get_filterable_attributes(self) -> list[str] | None:
71777215 if not response .json ():
71787216 return None
71797217
7180- return response .json ()
7218+ response_json = response .json ()
7219+
7220+ if isinstance (response_json [0 ], str ):
7221+ return response_json
7222+
7223+ filterable_attributes = []
7224+ for r in response_json :
7225+ filterable_attributes .append (
7226+ FilterableAttributes (
7227+ attribute_patterns = r ["attributePatterns" ],
7228+ features = FilterableAttributeFeatures (** r ["features" ]),
7229+ )
7230+ )
71817231
7182- def update_filterable_attributes (self , body : list [str ], * , compress : bool = False ) -> TaskInfo :
7232+ return filterable_attributes
7233+
7234+ def update_filterable_attributes (
7235+ self , body : list [str ] | list [FilterableAttributes ], * , compress : bool = False
7236+ ) -> TaskInfo :
71837237 """Update filterable attributes of the index.
71847238
71857239 Args:
@@ -7199,8 +7253,16 @@ def update_filterable_attributes(self, body: list[str], *, compress: bool = Fals
71997253 >>> index = client.index("movies")
72007254 >>> index.update_filterable_attributes(["genre", "director"])
72017255 """
7256+ payload : list [str | JsonDict ] = []
7257+
7258+ for b in body :
7259+ if isinstance (b , FilterableAttributes ):
7260+ payload .append (b .model_dump (by_alias = True ))
7261+ else :
7262+ payload .append (b )
7263+
72027264 response = self ._http_requests .put (
7203- f"{ self ._settings_url } /filterable-attributes" , body , compress = compress
7265+ f"{ self ._settings_url } /filterable-attributes" , payload , compress = compress
72047266 )
72057267
72067268 return TaskInfo (** response .json ())
@@ -8326,6 +8388,7 @@ def _process_search_parameters(
83268388 hybrid : Hybrid | None = None ,
83278389 locales : list [str ] | None = None ,
83288390 retrieve_vectors : bool | None = None ,
8391+ exhaustive_facet_count : bool | None = None ,
83298392) -> JsonDict :
83308393 if attributes_to_retrieve is None :
83318394 attributes_to_retrieve = ["*" ]
@@ -8377,6 +8440,9 @@ def _process_search_parameters(
83778440 if retrieve_vectors is not None :
83788441 body ["retrieveVectors" ] = retrieve_vectors
83798442
8443+ if exhaustive_facet_count is not None :
8444+ body ["exhaustivefacetCount" ] = exhaustive_facet_count
8445+
83808446 return body
83818447
83828448
0 commit comments