@@ -640,11 +640,17 @@ void match_select_best(scan_data_t *scan)
640640
641641 LIST_FOREACH (item , & scan -> matches_list_array [i ]-> headp , entries )
642642 {
643- if (!item -> match -> component_list .headp .lh_first )
643+ match_data_t * match = item -> match ;
644+
645+ if (!match -> component_list .headp .lh_first )
644646 continue ;
647+ component_data_t * match_component = match -> component_list .headp .lh_first -> component ;
648+
649+ scanlog ("%s\n" ,match_component -> purls [0 ]);
650+
651+ match_data_t * best_match = scan -> matches_list_array [i ]-> best_match ;
652+ component_data_t * best_match_component = best_match -> component_list .headp .lh_first -> component ;
645653
646- component_data_t * best_match_component = scan -> matches_list_array [i ]-> best_match -> component_list .headp .lh_first -> component ;
647- component_data_t * match_component = item -> match -> component_list .headp .lh_first -> component ;
648654 if (path_is_third_party (match_component -> file ))
649655 continue ;
650656
@@ -653,34 +659,32 @@ void match_select_best(scan_data_t *scan)
653659 best_match_component -> release_date ,
654660 scan -> matches_list_array [i ]-> best_match -> hits ,
655661 match_component -> purls [0 ], match_component -> release_date , item -> match -> hits );
656-
657- if (!strcmp (best_match_component -> purls [0 ],match_component -> purls [0 ]))
658- {
659- if (abs (scan -> matches_list_array [i ]-> best_match -> hits - item -> match -> hits ) <= 2 &&
660- find_oldest_match (scan -> matches_list_array [i ]-> best_match , item -> match ))
661- {
662- scanlog ("Replacing best match for an older version with equal hits\n" );
663- scan -> matches_list_array [i ]-> best_match = item -> match ;
664- }
665- else if (scan -> matches_list_array [i ]-> best_match -> hits + 1 < item -> match -> hits )
666- {
667- scanlog ("Replacing best match for a newers version with more hits\n" );
668- scan -> matches_list_array [i ]-> best_match = item -> match ;
669- }
670-
671- }
672- else if (scan -> matches_list_array [i ]-> best_match -> hits > item -> match -> hits )
673- {
674- scanlog ("Hits are lower than the best match, no more comparations are needed. Exiting...\n" );
675- break ;
676- }
677662
663+ //If the best match is not good or is not identified be prefer the candidate.
678664 if ((!best_match_component -> identified && match_component -> identified ) ||
679- (strcmp (best_match_component -> vendor ,best_match_component -> component ) && !strcmp (match_component -> vendor , match_component -> component )) ||
680665 (path_is_third_party (best_match_component -> file )))
681666 {
682667 scanlog ("Replacing best match for a prefered component\n" );
683668 scan -> matches_list_array [i ]-> best_match = item -> match ;
669+ continue ;
670+ }
671+
672+ //If best match has 20% more of hits do nothing.
673+ if (best_match -> hits >= match -> hits * 1.2 )
674+ continue ;
675+
676+ //if cantidate has 10% more of hits do not consider dates and switch
677+ if (match -> hits > best_match -> hits * 1.1 )
678+ {
679+ scanlog ("Replacing best match due to big hits difference\n" );
680+ scan -> matches_list_array [i ]-> best_match = item -> match ;
681+ }
682+ // if the hit numbers are close, select the oldest.
683+ else if (abs (scan -> matches_list_array [i ]-> best_match -> hits - item -> match -> hits ) <= 2 &&
684+ find_oldest_match (scan -> matches_list_array [i ]-> best_match , item -> match ))
685+ {
686+ scanlog ("Replacing best match for an older version with equal hits\n" );
687+ scan -> matches_list_array [i ]-> best_match = item -> match ;
684688 }
685689 }
686690 }
0 commit comments