Example #1
0
        public int?GetVariantScore(VariantSet requestedVariants, VariantSet candidateVariants,
                                   VariantSet candidateImplicitVariants)
        {
            var score          = ZeroScore;
            var excessVariants = new HashSet <IVariant>(candidateVariants);

            foreach (var requestedVariant in requestedVariants)
            {
                // Matches exact variant?
                if (candidateVariants.Contains(requestedVariant))
                {
                    score += ExplicitVariantScore;
                    excessVariants.Remove(requestedVariant);
                }

                // Matches another variant in same group? (fail!)
                else if (candidateVariants.Any(x => x.Group == requestedVariant.Group))
                {
                    return(null);
                }

                // Matches implicit variant?
                else if (candidateImplicitVariants.Contains(requestedVariant))
                {
                    score += ImplicitVariantScore;
                }

                // Matches another implicit variant in same group?
                else if (candidateImplicitVariants.Any(x => x.Group == requestedVariant.Group))
                {
                    score -= IncorrectImplicitVariantPenality;
                }

                // No variant specified for that group (is a fallback)
                else
                {
                    score += FallbackVariantScore;
                }
            }

            score -= excessVariants.Count * ExcessVariantPenality;

            return(score);
        }
 public override bool Matches(string filter) =>
 base.Matches(filter) ||
 Target.Name.CaseInsensitiveContains(filter) ||
 _implicitVariants.Any(x => x.Name.CaseInsensitiveContains(filter));