Represents a search index to create.
| 808 | |
| 809 | |
| 810 | class SearchIndexModel: |
| 811 | """Represents a search index to create.""" |
| 812 | |
| 813 | __slots__ = ("__document",) |
| 814 | |
| 815 | def __init__( |
| 816 | self, |
| 817 | definition: Mapping[str, Any], |
| 818 | name: Optional[str] = None, |
| 819 | type: Optional[str] = None, |
| 820 | **kwargs: Any, |
| 821 | ) -> None: |
| 822 | """Create a Search Index instance. |
| 823 | |
| 824 | For use with :meth:`~pymongo.collection.AsyncCollection.create_search_index` and :meth:`~pymongo.collection.AsyncCollection.create_search_indexes`. |
| 825 | |
| 826 | :param definition: The definition for this index. |
| 827 | :param name: The name for this index, if present. |
| 828 | :param type: The type for this index which defaults to "search". Alternative values include "vectorSearch". |
| 829 | :param kwargs: Keyword arguments supplying any additional options. |
| 830 | |
| 831 | .. note:: Search indexes require a MongoDB server version 7.0+ Atlas cluster. |
| 832 | .. versionadded:: 4.5 |
| 833 | .. versionchanged:: 4.7 |
| 834 | Added the type and kwargs arguments. |
| 835 | """ |
| 836 | self.__document: dict[str, Any] = {} |
| 837 | if name is not None: |
| 838 | self.__document["name"] = name |
| 839 | self.__document["definition"] = definition |
| 840 | if type is not None: |
| 841 | self.__document["type"] = type |
| 842 | self.__document.update(kwargs) |
| 843 | |
| 844 | @property |
| 845 | def document(self) -> Mapping[str, Any]: |
| 846 | """The document for this index.""" |
| 847 | return self.__document |
| 848 | |
| 849 | def __repr__(self) -> str: |
| 850 | return "{}({})".format( |
| 851 | self.__class__.__name__, |
| 852 | ", ".join([f"{key}={value!r}" for key, value in self.document.items()]), |
| 853 | ) |
no outgoing calls