From ef9e2522ef58ae190e669263db0d5a5cd74b1b6a Mon Sep 17 00:00:00 2001 From: Abdullah Almsaeed Date: Fri, 20 Apr 2018 10:13:54 -0400 Subject: [PATCH] Add another query to remove blastdb instead of only blast database --- includes/Elasticsearch/ESInstance.php | 1 + tripal_elasticsearch.install | 47 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/includes/Elasticsearch/ESInstance.php b/includes/Elasticsearch/ESInstance.php index 5112a11a..a36d97a9 100644 --- a/includes/Elasticsearch/ESInstance.php +++ b/includes/Elasticsearch/ESInstance.php @@ -138,6 +138,7 @@ public function setWebsiteSearchParams( $query = [ "bool" => [ "must" => $queries, + "filter" => [] ], ]; diff --git a/tripal_elasticsearch.install b/tripal_elasticsearch.install index 7ee0d998..31a23f2e 100644 --- a/tripal_elasticsearch.install +++ b/tripal_elasticsearch.install @@ -426,3 +426,50 @@ function tripal_elasticsearch_update_7210() { throw $exception; } } + + +/** + * Remove blastdb content type from website index. + * + * @throws \Exception + */ +function tripal_elasticsearch_update_7211() { + try { + $es = new ESInstance(); + $count = $es->setWebsiteSearchParams('*', 'blastdb', 'website') + ->count(); + $client = $es->client; + + if ($count === 0) { + print "No blastdb content was found\n"; + return; + } + + for ($i = 0; $i < $count; $i += 100) { + $results = $es->setWebsiteSearchParams('*', 'blastdb', 'website', 'website', [ + $i, + 100, + ])->search(FALSE); + foreach ($results as $result) { + $client->deleteByQuery([ + 'index' => 'website', + 'type' => 'website', + 'body' => [ + 'query' => [ + 'match' => [ + 'nid' => $result['nid'], + ], + ], + ], + ]); + } + } + + print "Successfully removed all blastdb nodes from website index.\n"; + } catch (Exception $exception) { + print "ERROR: failed to remove blastdb nodes from website index due to the following exception\n"; + print $exception->getMessage(); + + throw $exception; + } +}