Skip to content

Commit c466d80

Browse files
committed
📦 NEW: Add indexBuilder.delete( indexName ) support
IMHO, it feels funny to call `indexBuilder.new()` just to delete an index. Even the `new()` method is documented with a "Create a new index" hint - it's not just a weirdly-named init message. TLDR: Adds support for an indexName argument so we can delete indices from the indexBuilder.
1 parent 371d132 commit c466d80

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

‎modules/cbelasticsearch/models/IndexBuilder.cfc

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ component accessors="true" {
6969

7070
/**
7171
* Deletes the index named in the configured builder
72+
*
73+
* @indexName Specify an index name to delete, if not already populated from the indexBuilder.new() method.
7274
**/
73-
function delete(){
75+
function delete( string indexName ){
76+
if ( !isNull( arguments.indexName ) ){
77+
setIndexName( arguments.indexName );
78+
}
7479
return getClient().deleteIndex( this.getIndexName() );
7580
}
7681

‎tests/specs/unit/IndexBuilderTest.cfc

+9
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ component extends="coldbox.system.testing.BaseTestCase" {
201201

202202
expect( variables.model.getClient().indexExists( variables.testIndexName ) ).toBeFalse();
203203
} );
204+
it( "Tests the delete() method with an index name argument", function(){
205+
var shortLivedIndex = getWirebox().getInstance( "IndexBuilder@cbElasticSearch" ).new( variables.testIndexName );
206+
shortLivedIndex.save();
207+
expect( shortLivedIndex.getClient().indexExists( shortLivedIndex.getIndexName() ) ).toBeTrue();
208+
209+
getWirebox().getInstance( "IndexBuilder@cbElasticSearch" ).delete( shortLivedIndex.getIndexName() );
210+
211+
expect( shortLivedIndex.getClient().indexExists( shortLivedIndex.getIndexName() ) ).toBeFalse();
212+
} );
204213
} );
205214
}
206215

0 commit comments

Comments
 (0)