| 176 | |
| 177 | |
| 178 | class UnifiedIndex: |
| 179 | # Used to collect all the indexes into a cohesive whole. |
| 180 | def __init__(self, excluded_indexes=None): |
| 181 | self._indexes = {} |
| 182 | self.fields = OrderedDict() |
| 183 | self._built = False |
| 184 | self.excluded_indexes = excluded_indexes or [] |
| 185 | self.excluded_indexes_ids = {} |
| 186 | self.document_field = constants.DOCUMENT_FIELD |
| 187 | self._fieldnames = {} |
| 188 | self._facet_fieldnames = {} |
| 189 | |
| 190 | @property |
| 191 | def indexes(self): |
| 192 | warnings.warn( |
| 193 | "'UnifiedIndex.indexes' was deprecated in Haystack v2.3.0. Please use UnifiedIndex.get_indexes()." |
| 194 | ) |
| 195 | return self._indexes |
| 196 | |
| 197 | def collect_indexes(self): |
| 198 | indexes = [] |
| 199 | |
| 200 | for app_mod in haystack_get_app_modules(): |
| 201 | try: |
| 202 | search_index_module = importlib.import_module( |
| 203 | "%s.search_indexes" % app_mod.__name__ |
| 204 | ) |
| 205 | except ImportError: |
| 206 | if module_has_submodule(app_mod, "search_indexes"): |
| 207 | raise |
| 208 | |
| 209 | continue |
| 210 | |
| 211 | for item_name, item in inspect.getmembers( |
| 212 | search_index_module, inspect.isclass |
| 213 | ): |
| 214 | if getattr(item, "haystack_use_for_indexing", False) and getattr( |
| 215 | item, "get_model", None |
| 216 | ): |
| 217 | # We've got an index. Check if we should be ignoring it. |
| 218 | class_path = "%s.search_indexes.%s" % (app_mod.__name__, item_name) |
| 219 | |
| 220 | if ( |
| 221 | class_path in self.excluded_indexes |
| 222 | or self.excluded_indexes_ids.get(item_name) == id(item) |
| 223 | ): |
| 224 | self.excluded_indexes_ids[str(item_name)] = id(item) |
| 225 | continue |
| 226 | |
| 227 | indexes.append(item()) |
| 228 | |
| 229 | return indexes |
| 230 | |
| 231 | def reset(self): |
| 232 | self._indexes = {} |
| 233 | self.fields = OrderedDict() |
| 234 | self._built = False |
| 235 | self._fieldnames = {} |
no outgoing calls