def handle(self, *args, **options): logging.basicConfig(level=logging.INFO) percent = options['percent'] if percent > 100 or percent < 1: raise CommandError('percent should be between 1 and 100') if args: search_models = get_search_models() possible_doctypes = dict((cls._meta.db_table, cls) for cls in search_models) for mem in args: if mem not in possible_doctypes: raise CommandError('"%s" is not a valid doctype (%s)' % (mem, possible_doctypes.keys())) # args are the list of doctypes to index. es_reindex(args, percent)
def setup_indexes(self): """(Re-)create ES indexes.""" from search.es_utils import es_reindex if getattr(settings, 'ES_HOSTS', None) is None: raise SkipTest # TODO: Don't bother scanning through model objects and indexing any # that exist. None of our ES tests use any fixtures, so incremental # indexing will suffice for them. es_reindex() # TODO: This is kind of bad. If setup_indexes gets called in # a setUp and that setUp at some point throws an exception, we # could end up in a situation where setUp throws an exception, # so tearDown doesn't get called and we never set # ES_LIVE_INDEXING to False and thus ES_LIVE_INDEXING is True # for a bunch of tests it shouldn't be true for. # # For settings like this, it's better to mock it in the class # because the mock will set it back regardless of whether the # test fails. settings.ES_LIVE_INDEXING = True
def handle(self, *args, **options): percent = options['percent'] if percent > 100 or percent < 1: raise CommandError('percent should be between 1 and 100') es_reindex(percent)
def handle(self, *args, **options): logging.basicConfig(level=logging.INFO) percent = options['percent'] if not 1 <= percent <= 100: raise CommandError('percent should be between 1 and 100') es_reindex(percent)