Commit 3d326a5 1 parent a892c93 commit 3d326a5 Copy full SHA for 3d326a5
File tree 2 files changed +33
-2
lines changed
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,18 @@ describe('Search Asset', () => {
108
108
109
109
it ( 'should be able to get assets by type' , async ( ) => {
110
110
const { results : ddos } = await neverminedOffline . search . byType ( 'dataset' )
111
+ assert . equal ( ddos . length , 5 )
111
112
112
- assert . equal ( ddos . length , 4 )
113
+ const { results : ddosWithTextFilter } = await neverminedOffline . search . byType (
114
+ 'dataset' ,
115
+ 'TestAsset' ,
116
+ )
117
+ assert . equal ( ddosWithTextFilter . length , 4 )
118
+
119
+ const { results : ddosServices } = await neverminedOffline . search . byType ( 'service' )
120
+ assert . equal ( ddosServices . length , 2 )
121
+
122
+ const { results : agent } = await neverminedOffline . search . byType ( 'agent' )
123
+ assert . equal ( agent . length , 0 )
113
124
} )
114
125
} )
Original file line number Diff line number Diff line change @@ -788,9 +788,19 @@ export class SearchApi extends Instantiable {
788
788
)
789
789
}
790
790
791
- public async byType ( assetType : MetaDataMain [ 'type' ] = 'agent' , offset = 100 , page = 1 ) {
791
+ public async byType (
792
+ assetType : MetaDataMain [ 'type' ] = 'agent' ,
793
+ text ?: string ,
794
+ offset = 100 ,
795
+ page = 1 ,
796
+ appId ?: string ,
797
+ ) {
792
798
const mustArray : unknown [ ] = [ ]
793
799
mustArray . push ( assetTypeFilter ( assetType ) )
800
+ if ( text ) {
801
+ mustArray . push ( textFilter ( text ) )
802
+ }
803
+
794
804
return this . query ( {
795
805
query : {
796
806
bool : {
@@ -802,6 +812,7 @@ export class SearchApi extends Instantiable {
802
812
} ,
803
813
page : page ,
804
814
offset : offset ,
815
+ appId,
805
816
} )
806
817
}
807
818
}
@@ -834,3 +845,12 @@ export const assetTypeFilter = (assetType: MetaDataMain['type']) => {
834
845
} ,
835
846
}
836
847
}
848
+
849
+ export const textFilter = ( searchInputText = '' ) => ( {
850
+ nested : {
851
+ path : [ 'service' ] ,
852
+ query : {
853
+ query_string : { query : `*${ searchInputText } *` , fields : [ 'service.attributes.main.name' ] } ,
854
+ } ,
855
+ } ,
856
+ } )
You can’t perform that action at this time.
0 commit comments