Skip to content

Commit

Permalink
Merge pull request #187 from tripal/deal-with-blastdb
Browse files Browse the repository at this point in the history
Add exception to remove blast database nodes
  • Loading branch information
almasaeed2010 committed Apr 20, 2018
2 parents c9b705b + f9ffd91 commit 48d9ce2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ services:
elasticsearch:
image: 'elasticsearch:5'
ports:
- "9200:9200"
- "9201:9200"
9 changes: 8 additions & 1 deletion includes/Elasticsearch/ESInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,25 @@ public function setIndexParams($index_name, $shards = 5, $replicas = 0,
* Perform the actual search.
* Use this function after setting the search params.
*
* @param bool $return_source whether to format the results or not.
*
* @see \ESInstance::setTableSearchParams()
* @see \ESInstance::setWebsiteSearchParams()
*
* @return array
* @throws \Exception
*/
public function search() {
public function search($return_source = false) {
if (empty($this->searchParams)) {
throw new Exception('Please build search parameters before attempting to search.');
}

$hits = $this->client->search($this->searchParams);

if($return_source) {
return $hits;
}

$results = [];
foreach ($hits['hits']['hits'] as $hit) {
if (isset($hit['highlight'])) {
Expand Down
3 changes: 2 additions & 1 deletion includes/Jobs/NodesIndexJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public function total() {
* @return int
*/
public function count() {
return db_query('SELECT COUNT(nid) FROM {node} WHERE status=1')->fetchField();
return db_query('SELECT COUNT(nid) FROM {node} N
WHERE status=1 AND type != :type', [':type' => 'blastdb'])->fetchField();
}
}
50 changes: 48 additions & 2 deletions tripal_elasticsearch.install
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ function tripal_elasticsearch_uninstall() {

// Auto drop anything in the schema
foreach ($schema as $table => $fields) {
if(db_table_exists($table)) {
if (db_table_exists($table)) {
db_drop_table($table);
}
}

// Drop tables that are created in the update functions
if(db_table_exists('tripal_elasticsearch_indices')) {
if (db_table_exists('tripal_elasticsearch_indices')) {
db_drop_table('tripal_elasticsearch_indices');
}
}
Expand Down Expand Up @@ -380,3 +380,49 @@ function tripal_elasticsearch_update_7209() {
throw $exception;
}
}

/**
* Remove blast database content type from website index.
*
* @throws \Exception
*/
function tripal_elasticsearch_update_7210() {
try {
$es = new ESInstance();
$count = $es->setWebsiteSearchParams('*', 'Blast Database', 'website')
->count();
$client = $es->client;

if ($count === 0) {
print "No blast database content was found\n";
return;
}

for ($i = 0; $i < $count; $i += 100) {
$results = $es->setWebsiteSearchParams('*', 'Blast Database', '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 blast database nodes from website index.\n";
} catch (Exception $exception) {
print "ERROR: failed to remove blast database nodes from website index due to the following exception\n";
print $exception->getMessage();

throw $exception;
}
}

0 comments on commit 48d9ce2

Please sign in to comment.