@@ -586,8 +586,8 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
586586 }
587587 const [ items , count ] = await DatabaseServer . getSchemasAndCount ( filter , otherOptions ) ;
588588 const pipeline = [
589- { $match : filter } ,
590- { $group : { _id : '$topicId' , count : { $sum : 1 } } }
589+ { $match : filter } ,
590+ { $group : { _id : '$topicId' , count : { $sum : 1 } } }
591591 ] as unknown [ ] ;
592592 const countByTopic = await new DataBaseHelper ( SchemaCollection ) . aggregate ( pipeline ) as unknown [ ] as { _id : string , count : number } [ ] ;
593593 items . forEach ( ( item ) => {
@@ -619,6 +619,7 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
619619 toolId ?: string ,
620620 topicId ?: string ,
621621 search ?: string
622+ searchOptions ?: string [ ]
622623 } ,
623624 owner : IOwner ,
624625 } ) => {
@@ -708,36 +709,72 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
708709 //search
709710 if ( options . search ) {
710711 let search = options . search . toLowerCase ( ) ;
711- let global = false ;
712- if ( search . startsWith ( '@' ) ) {
713- global = true ;
712+ if ( search . startsWith ( '@' ) || search . startsWith ( '#' ) ) {
714713 search = search . substring ( 1 ) ;
715714 }
715+ const searchOptions = options . searchOptions || [ 'uuid' , 'name' , 'description' , 'references' , 'fields' ] ;
716+ const fields = [ '_id' ] ;
717+ if ( searchOptions . includes ( 'uuid' ) ) {
718+ fields . push ( 'iri' ) ;
719+ }
720+ if ( searchOptions . includes ( 'name' ) ) {
721+ fields . push ( 'name' ) ;
722+ }
723+ if ( searchOptions . includes ( 'description' ) ) {
724+ fields . push ( 'description' ) ;
725+ }
726+ if ( searchOptions . includes ( 'references' ) || searchOptions . includes ( 'fields' ) ) {
727+ fields . push ( 'documentFileId' ) ;
728+ }
716729 let schemas = await DatabaseServer . getSchemas ( filter , {
717730 orderBy : { createDate : 'DESC' } ,
718731 limit : 10000 ,
719732 offset : 0 ,
720- fields : [ '_id' , 'documentFileId' ]
733+ fields
721734 } ) ;
722735 schemas = schemas . filter ( ( s ) => {
723- if ( s . document ) {
724- if ( ! global ) {
736+ if ( searchOptions . includes ( 'uuid' ) ) {
737+ if ( s . iri && s . iri . toLowerCase ( ) . includes ( search ) ) {
738+ return true ;
739+ }
740+ }
741+ if ( searchOptions . includes ( 'name' ) ) {
742+ if ( s . name && s . name . toLowerCase ( ) . includes ( search ) ) {
743+ return true ;
744+ }
745+ }
746+ if ( searchOptions . includes ( 'description' ) ) {
747+ if ( s . description && s . description . toLowerCase ( ) . includes ( search ) ) {
748+ return true ;
749+ }
750+ }
751+ if ( searchOptions . includes ( 'references' ) ) {
752+ if ( s . document ?. $defs ) {
753+ const text = JSON . stringify ( s . document . $defs ) . toLowerCase ( ) ;
754+ if ( text . includes ( search ) ) {
755+ return true ;
756+ }
757+ }
758+ }
759+ if ( searchOptions . includes ( 'fields' ) ) {
760+ if ( s . document ) {
725761 delete s . document . $defs ;
762+ const text = JSON . stringify ( s . document ) . toLowerCase ( ) ;
763+ if ( text . includes ( search ) ) {
764+ return true ;
765+ }
726766 }
727- const text = JSON . stringify ( s . document ) . toLowerCase ( ) ;
728- return text . indexOf ( search ) > - 1 ;
729- } else {
730- return false ;
731767 }
768+ return false ;
732769 } )
733770 const ids = schemas . map ( ( s ) => s . _id ) ;
734771 filter . _id = { $in : ids } ;
735772 }
736773
737774 const [ items , count ] = await DatabaseServer . getSchemasAndCount ( filter , otherOptions ) ;
738775 const pipeline = [
739- { $match : filter } ,
740- { $group : { _id : '$topicId' , count : { $sum : 1 } } }
776+ { $match : filter } ,
777+ { $group : { _id : '$topicId' , count : { $sum : 1 } } }
741778 ] as unknown [ ] ;
742779 const countByTopic = await new DataBaseHelper ( SchemaCollection ) . aggregate ( pipeline ) as unknown [ ] as { _id : string , count : number } [ ] ;
743780 items . forEach ( ( item ) => {
0 commit comments