@@ -27,7 +27,7 @@ func (s *ScanServiceImpl) ScanFolder(ctx context.Context, req *entities.ScanRequ
2727 return nil , err
2828 }
2929
30- results , err := s .scanNode (ctx , req .Root , req .RankThreshold , req .RecursiveThreshold )
30+ results , err := s .scanNode (ctx , req .Root , req .RankThreshold , req .RecursiveThreshold , true )
3131 if err != nil {
3232 return nil , err
3333 }
@@ -63,7 +63,7 @@ func (s *ScanServiceImpl) processComponentGroups(componentGroups []entities.Comp
6363 return results
6464}
6565
66- func (s * ScanServiceImpl ) scanNode (ctx context.Context , node * entities.FolderNode , rankThreshold int , recursiveThreshold float32 ) ([]* entities.ScanResult , error ) {
66+ func (s * ScanServiceImpl ) scanNode (ctx context.Context , node * entities.FolderNode , rankThreshold int , recursiveThreshold float32 , isRoot bool ) ([]* entities.ScanResult , error ) {
6767 logger := ctxzap .Extract (ctx ).Sugar ()
6868
6969 if node .SimHashDirNames == "" && node .SimHashNames == "" && node .SimHashContent == "" {
@@ -80,8 +80,11 @@ func (s *ScanServiceImpl) scanNode(ctx context.Context, node *entities.FolderNod
8080
8181 logger .Debugf ("SearchByHashes returned %d component groups for node %s" , len (componentGroups ), node .PathID )
8282
83+ // Skip recursive threshold check for root node when depth is enabled (has children)
84+ shouldCheckThreshold := ! (isRoot && len (node .Children ) > 0 )
85+
8386 // Check if any component group has a version with score >= recursiveThreshold
84- if recursiveThreshold > 0 && s .hasHighScoreMatch (componentGroups , recursiveThreshold ) {
87+ if shouldCheckThreshold && recursiveThreshold > 0 && s .hasHighScoreMatch (componentGroups , recursiveThreshold ) {
8588 logger .Infof ("Found high score match (>= %f) for node %s, stopping search" , recursiveThreshold , node .PathID )
8689 results := s .processComponentGroups (componentGroups , node .PathID )
8790 return results , nil
@@ -91,7 +94,7 @@ func (s *ScanServiceImpl) scanNode(ctx context.Context, node *entities.FolderNod
9194
9295 if len (node .Children ) > 0 {
9396 for _ , child := range node .Children {
94- childResults , err := s .scanNode (ctx , child , rankThreshold , recursiveThreshold )
97+ childResults , err := s .scanNode (ctx , child , rankThreshold , recursiveThreshold , false )
9598 if err != nil {
9699 return nil , err
97100 }
0 commit comments