Permalink
Browse files

clear_index: adopt new behaviour of update_index

* By default, all backends are cleared
* --using may be specified multiple times
  • Loading branch information...
1 parent a018d7b commit 1bfb09040aec9e21e73da8d6f098d64a52da2071 @acdha committed Nov 6, 2012
Showing with 20 additions and 14 deletions.
  1. +20 −14 haystack/management/commands/clear_index.py
@@ -1,7 +1,7 @@
from optparse import make_option
import sys
+
from django.core.management.base import BaseCommand
-from haystack.constants import DEFAULT_ALIAS
class Command(BaseCommand):
@@ -10,35 +10,41 @@ class Command(BaseCommand):
make_option('--noinput', action='store_false', dest='interactive', default=True,
help='If provided, no prompts will be issued to the user and the data will be wiped out.'
),
- make_option("-u", "--using", action="store", type="string", dest="using", default=DEFAULT_ALIAS,
- help='If provided, chooses a connection to work with.'
+ make_option("-u", "--using", action="append", dest="using",
+ default=[],
+ help='Update only the named backend (can be used multiple times). '
+ 'By default all backends will be updated.'
),
)
option_list = BaseCommand.option_list + base_options
-
+
def handle(self, **options):
"""Clears out the search index completely."""
from haystack import connections
self.verbosity = int(options.get('verbosity', 1))
- self.using = options.get('using')
-
+
+ using = options.get('using')
+ if not using:
+ using = connections.connections_info.keys()
+
if options.get('interactive', True):
print
- print "WARNING: This will irreparably remove EVERYTHING from your search index in connection '%s'." % self.using
+ print "WARNING: This will irreparably remove EVERYTHING from your search index in connection '%s'." % "', '".join(using)
print "Your choices after this are to restore from backups or rebuild via the `rebuild_index` command."
-
+
yes_or_no = raw_input("Are you sure you wish to continue? [y/N] ")
print
-
+
if not yes_or_no.lower().startswith('y'):
print "No action taken."
sys.exit()
-
+
if self.verbosity >= 1:
print "Removing all documents from your index because you said so."
-
- backend = connections[self.using].get_backend()
- backend.clear()
-
+
+ for backend_name in using:
+ backend = connections[backend_name].get_backend()
+ backend.clear()
+
if self.verbosity >= 1:
print "All documents removed."

0 comments on commit 1bfb090

Please sign in to comment.