diff --git a/watson/management/commands/buildwatson.py b/watson/management/commands/buildwatson.py index 59703d2..00ed2fa 100644 --- a/watson/management/commands/buildwatson.py +++ b/watson/management/commands/buildwatson.py @@ -28,7 +28,7 @@ def get_engine(engine_slug_): raise CommandError("Search Engine \"%s\" is not registered!" % force_text(engine_slug_)) -def rebuild_index_for_model(model_, engine_slug_, verbosity_): +def rebuild_index_for_model(model_, engine_slug_, verbosity_, slim_=False): """rebuilds index for a model""" search_engine_ = get_engine(engine_slug_) @@ -74,6 +74,14 @@ class Command(BaseCommand): action="store", help='Search engine models are registered with' ) + parser.add_argument( + '--slim', + action='store_true', + default=False, + help="Only include objects which satisfy the filter specified during \ + model registration. WARNING: buildwatson must be rerun if the filter \ + changes or the index will be incomplete." + ) @transaction.atomic() def handle(self, *args, **options): @@ -89,6 +97,9 @@ class Command(BaseCommand): engine_slug = "default" engine_selected = False + # Do we do a partial index? + slim = options.get("slim") + # work-around for legacy optparser hack in BaseCommand. In Django=1.10 the # args are collected in options['apps'], but in earlier versions they are # kept in args. @@ -123,7 +134,7 @@ class Command(BaseCommand): if verbosity >= 3: print("Using search engine \"%s\"" % engine_slug) for model in models: - refreshed_model_count += rebuild_index_for_model(model, engine_slug, verbosity) + refreshed_model_count += rebuild_index_for_model(model, engine_slug, verbosity, slim_=slim) else: # full rebuild (for one or all search engines) if engine_selected: @@ -139,7 +150,7 @@ class Command(BaseCommand): registered_models = search_engine.get_registered_models() # Rebuild the index for all registered models. for model in registered_models: - refreshed_model_count += rebuild_index_for_model(model, engine_slug, verbosity) + refreshed_model_count += rebuild_index_for_model(model, engine_slug, verbosity, slim_=slim) # Clean out any search entries that exist for stale content types. # Only do it during full rebuild