|
1 | 1 | """ |
2 | | -Command to build or re-build the search index for courses (in Studio, i.e. Draft |
3 | | -mode), in Meilisearch. |
| 2 | +Command to queue incremental population of the Studio Meilisearch search index. |
| 3 | +
|
| 4 | +Index creation, configuration, and schema reconciliation are handled |
| 5 | +automatically via the post_migrate signal. This command is solely |
| 6 | +responsible for enqueuing the population task in Celery. |
4 | 7 |
|
5 | 8 | See also cms/djangoapps/contentstore/management/commands/reindex_course.py which |
6 | 9 | indexes LMS (published) courses in ElasticSearch. |
7 | 10 | """ |
| 11 | + |
| 12 | +import logging |
| 13 | + |
| 14 | +from django.conf import settings |
8 | 15 | from django.core.management import BaseCommand, CommandError |
9 | 16 |
|
10 | 17 | from ... import api |
| 18 | +from ...tasks import rebuild_index_incremental |
| 19 | + |
| 20 | +log = logging.getLogger(__name__) |
11 | 21 |
|
12 | 22 |
|
13 | 23 | class Command(BaseCommand): |
14 | 24 | """ |
15 | | - Build or re-build the Meilisearch search index for courses and libraries in Studio. |
| 25 | + Add all course and library content to the Studio search index. |
| 26 | +
|
| 27 | + This enqueues a Celery task that incrementally indexes all courses and |
| 28 | + libraries. Progress is tracked via IncrementalIndexCompleted, so the task |
| 29 | + can safely resume if interrupted. |
| 30 | +
|
| 31 | + Index creation and configuration are handled by post_migrate reconciliation |
| 32 | + (runs automatically on ./manage.py cms migrate). |
16 | 33 |
|
17 | | - This is separate from LMS search features like courseware search or forum search. |
| 34 | + If it's ever necessary to reset the incremental indexing state (force |
| 35 | + the full re-index process to start from the beginning), use: |
| 36 | +
|
| 37 | + ./manage.py cms shell -c 'IncrementalIndexCompleted.objects.all().delete()' |
| 38 | +
|
| 39 | + This will delete all the IncrementalIndexCompleted records and will help in restarting the index population. |
18 | 40 | """ |
19 | 41 |
|
20 | | - # TODO: improve this - see https://github.com/openedx/edx-platform/issues/36868 |
| 42 | + help = "Add all course and library content to the Studio search index." |
21 | 43 |
|
22 | 44 | def add_arguments(self, parser): |
23 | | - parser.add_argument("--experimental", action="store_true") # kept for compatibility but ignored. |
24 | | - parser.add_argument("--reset", action="store_true") |
25 | | - parser.add_argument("--init", action="store_true") |
26 | | - parser.add_argument("--incremental", action="store_true") |
27 | | - parser.set_defaults(experimental=False, reset=False, init=False, incremental=False) |
| 45 | + # Removed flags — provide clear error messages for operators with old automation. |
| 46 | + parser.add_argument( |
| 47 | + "--reset", |
| 48 | + action="store_true", |
| 49 | + default=False, |
| 50 | + help="(Removed) Index reset is now handled by post_migrate reconciliation.", |
| 51 | + ) |
| 52 | + parser.add_argument( |
| 53 | + "--init", |
| 54 | + action="store_true", |
| 55 | + default=False, |
| 56 | + help="(Removed) Index initialization is now handled by post_migrate reconciliation.", |
| 57 | + ) |
| 58 | + parser.add_argument( |
| 59 | + "--incremental", |
| 60 | + action="store_true", |
| 61 | + default=False, |
| 62 | + help="(Removed) Incremental is now the default and only population mode.", |
| 63 | + ) |
28 | 64 |
|
29 | 65 | def handle(self, *args, **options): |
30 | | - """ |
31 | | - Build a new search index for Studio, containing content from courses and libraries |
32 | | - """ |
33 | 66 | if not api.is_meilisearch_enabled(): |
34 | 67 | raise CommandError("Meilisearch is not enabled. Please set MEILISEARCH_ENABLED to True in your settings.") |
35 | 68 |
|
36 | 69 | if options["reset"]: |
37 | | - api.reset_index(self.stdout.write) |
38 | | - elif options["init"]: |
39 | | - api.init_index(self.stdout.write, self.stderr.write) |
40 | | - elif options["incremental"]: |
41 | | - api.rebuild_index(self.stdout.write, incremental=True) |
| 70 | + raise CommandError( |
| 71 | + "The --reset flag has been removed. " |
| 72 | + "Index reset is now handled automatically by post_migrate reconciliation. " |
| 73 | + "Run: ./manage.py cms migrate" |
| 74 | + ) |
| 75 | + |
| 76 | + if options["init"]: |
| 77 | + raise CommandError( |
| 78 | + "The --init flag has been removed. " |
| 79 | + "Index initialization is now handled automatically by post_migrate reconciliation. " |
| 80 | + "Run: ./manage.py cms migrate" |
| 81 | + ) |
| 82 | + |
| 83 | + if options["incremental"]: |
| 84 | + log.warning( |
| 85 | + "The --incremental flag has been removed. " |
| 86 | + "Incremental population is now the default behavior of this command." |
| 87 | + ) |
| 88 | + |
| 89 | + result = rebuild_index_incremental.delay() |
| 90 | + |
| 91 | + if settings.CELERY_ALWAYS_EAGER: |
| 92 | + self.stdout.write("Indexing complete!") |
42 | 93 | else: |
43 | | - api.rebuild_index(self.stdout.write) |
| 94 | + self.stdout.write( |
| 95 | + f"Studio search index population has been queued (task_id={result.id}). " |
| 96 | + "Population will run incrementally in a Celery worker. " |
| 97 | + "Monitor progress in Celery worker logs. " |
| 98 | + "In order to reset the incremental indexing state, please run: " |
| 99 | + "./manage.py cms shell -c 'IncrementalIndexCompleted.objects.all().delete()'" |
| 100 | + ) |
0 commit comments