@@ -0,0 +1,2783 @@
+###########################################################################%0A#          (C) Vrije Universiteit, Amsterdam (the Netherlands)            #%0A#                                                                         #%0A# This file is part of AmCAT - The Amsterdam Content Analysis Toolkit     #%0A#                                                                         #%0A# AmCAT is free software: you can redistribute it and/or modify it under  #%0A# the terms of the GNU Affero General Public License as published by the  #%0A# Free Software Foundation, either version 3 of the License, or (at your  #%0A# option) any later version.                                              #%0A#                                                                         #%0A# AmCAT is distributed in the hope that it will be useful, but WITHOUT    #%0A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   #%0A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public     #%0A# License for more details.                                               #%0A#                                                                         #%0A# You should have received a copy of the GNU Affero General Public        #%0A# License along with AmCAT.  If not, see %3Chttp://www.gnu.org/licenses/%3E.  #%0A###########################################################################%0A%0Afrom django.core.management import BaseCommand%0Afrom amcat.models import ArticleSet, ProjectArticleSet%0Aimport logging%0A%0Adef reindex_sets(sets, full_refresh=True):%0A    logging.info(f%22Reindexing %7Blen(sets)%7D articlesets: %7Bsets%7D%22)%0A    for i, setid in enumerate(sets):%0A        logging.info(f%22%5B%7Bi:4%7D/%7Blen(sets):4%7D%5D Reindexing set %7Bsetid%7D%22)%0A        ArticleSet.objects.get(pk=setid).refresh_index(full_refresh=full_refresh)%0A%0A    %0Aclass Command(BaseCommand):%0A    help = 'Reindex one or more projects or sets'%0A    %0A    def add_arguments(self, parser):%0A        parser.add_argument(%22projectid%22, nargs=%22+%22, help=%22Project ID(s) or 'all'%22)%0A        parser.add_argument(%22--full%22, action='store_true', help=%22Full refresh (article content as well as set membership)%22)%0A        %0A    def handle(self, *args, **options):%0A        p = options%5B'projectid'%5D%0A        if p == %5B'all'%5D:%0A            logging.info(f%22Reindexing all projects (full_refresh=%7Boptions%5B'full'%5D%7D), retrieving set list%22)%0A            sets = sorted(ArticleSet.objects.all().values_list('pk', flat=True))%0A        else:%0A            projectids = %5Bint(x) for x in p%5D%0A            logging.info(%22Reindexing projects %7Bprojectids%7D (full_refresh=%7Boptions%5B'full'%5D%7D), retrieving set list%22)%0A            sets = sorted(ProjectArticleSet.objects.filter(project_id__in=projectids).values_list('articleset_id', flat=True))%0A        reindex_sets(sets, full_refresh=options%5B'full'%5D)%0A    %0A        %0A

Add management command for reindexing