Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated deletebyquery.py tool #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions tools/deletebyquery/deletebyquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
solr_connection = None
solr_collection = None
SOLR_UNIQUE_KEY = None
solr_delete_from_all_collections = None

cassandra_cluster = None
cassandra_session = None
Expand All @@ -45,11 +46,16 @@
def init(args):
global solr_connection
solr_connection = SolrConnection(args.solr)

global solr_collection
solr_collection = solr_connection[args.collection]

global SOLR_UNIQUE_KEY
SOLR_UNIQUE_KEY = args.solrIdField

global solr_delete_from_all_collections
solr_delete_from_all_collections = args.deleteFromAllCollections

dc_policy = RoundRobinPolicy()
token_policy = TokenAwarePolicy(dc_policy)

Expand Down Expand Up @@ -186,8 +192,15 @@ def delete_from_cassandra(doc_ids):


def delete_from_solr(query):
solr_collection.delete(query, commit=False)
solr_collection.commit()
global solr_collection
if not solr_delete_from_all_collections:
solr_collection.delete(query, commit=False)
solr_collection.commit()
else:
for collection in dir(solr_connection):
solr_collection = solr_connection[collection]
solr_collection.delete(query, commit=False)
solr_collection.commit()


def parse_args():
Expand All @@ -210,6 +223,13 @@ def parse_args():
required=False,
default='id',
metavar='id')

parser.add_argument('--deleteFromAllCollections',
help='Delete from all collections in SOLR, not limiting ' \
'to the collection specified in collection option',
required=False,
default=False,
action='store_true')

parser.add_argument('--cassandra',
help='The hostname(s) or IP(s) of the Cassandra server(s).',
Expand Down Expand Up @@ -243,8 +263,9 @@ def parse_args():

parser.add_argument('-p', '--cassandraPort',
help='The port used to connect to Cassandra.',
type=int,
required=False,
default='9042')
default=9042)

parser.add_argument('--cassandraUsername',
help='The username used to connect to Cassandra.',
Expand Down