|
11 | 11 | ATTR_STATUS,
|
12 | 12 | IndexStatus,
|
13 | 13 | ATTR_ENGINE_TYPE,
|
| 14 | + ATTR_METADATA, |
14 | 15 | )
|
15 | 16 | from primeqa.services.store import DIR_NAME_INDEX, StoreFactory
|
16 | 17 | from primeqa.services.grpc_server.utils import (
|
@@ -228,22 +229,40 @@ def GetIndexes(
|
228 | 229 | ) -> GetIndexesResponse:
|
229 | 230 | resp = GetIndexesResponse()
|
230 | 231 | for index_id in self._store.get_index_ids():
|
231 |
| - index_information = IndexInformation(index_id=index_id) |
| 232 | + index_information_return_obj = IndexInformation(index_id=index_id) |
232 | 233 | try:
|
233 |
| - status = self._store.get_index_information(index_id=index_id)[ |
234 |
| - ATTR_STATUS |
235 |
| - ] |
| 234 | + index_information = self._store.get_index_information(index_id=index_id) |
| 235 | + status = index_information[ATTR_STATUS] |
| 236 | + # Step 1: Check if particular engine type indices are requested |
| 237 | + if request.engine_type: |
| 238 | + # Step 1.a: If requested engine type doesn't match current index's engine type, skip processing |
| 239 | + if ( |
| 240 | + ATTR_ENGINE_TYPE not in index_information |
| 241 | + or request.engine_type != index_information[ATTR_ENGINE_TYPE] |
| 242 | + ): |
| 243 | + continue |
| 244 | + |
| 245 | + # Add status information |
236 | 246 | if status == IndexStatus.READY.value:
|
237 |
| - index_information.status = READY |
| 247 | + index_information_return_obj.status = READY |
238 | 248 | elif status == IndexStatus.INDEXING.value:
|
239 |
| - index_information.status = INDEXING |
| 249 | + index_information_return_obj.status = INDEXING |
240 | 250 | else:
|
241 |
| - index_information.status = CORRUPT |
| 251 | + index_information_return_obj.status = CORRUPT |
| 252 | + |
| 253 | + # Add metadata information |
| 254 | + if ( |
| 255 | + ATTR_METADATA in index_information |
| 256 | + and index_information[ATTR_METADATA] |
| 257 | + ): |
| 258 | + index_information_return_obj.metadata.update( |
| 259 | + index_information[ATTR_METADATA] |
| 260 | + ) |
242 | 261 | except KeyError:
|
243 |
| - index_information.status = CORRUPT |
| 262 | + index_information_return_obj.status = CORRUPT |
244 | 263 | except FileNotFoundError:
|
245 |
| - index_information.status = DOES_NOT_EXISTS |
| 264 | + index_information_return_obj.status = DOES_NOT_EXISTS |
246 | 265 |
|
247 |
| - resp.indexes.append(index_information) |
| 266 | + resp.indexes.append(index_information_return_obj) |
248 | 267 |
|
249 | 268 | return resp
|
0 commit comments