/// <summary> /// Rank the filtered items based on the matched occurences /// </summary> /// <returns> /// Queryable ranked items. Each item will contain /// the amount of hits found across the defined properties. /// </returns> /// <remarks>Only works in conjunction with string searches</remarks> public IQueryable <IRanked <T> > ToRanked(RankedType type = RankedType.Default) { Expression combinedHitExpression = null; foreach (var propertyToSearch in Properties) { var nullSafeExpression = BuildNullSafeExpression(propertyToSearch); for (int j = 0; j < _searchTerms.Count; j++) { var searchTerm = _searchTerms[j]; var hitCountExpression = type == RankedType.Default ? EnumerableExpressionHelper.CalculateHitCount(nullSafeExpression, searchTerm) : EnumerableExpressionHelper.CalculateHitCount_LeftWeighted(nullSafeExpression, searchTerm); combinedHitExpression = ExpressionHelper.AddExpressions(combinedHitExpression, hitCountExpression); } } var rankedInitExpression = EnumerableExpressionHelper.ConstructRankedResult <T>(combinedHitExpression, FirstParameter); var selectExpression = Expression.Lambda <Func <T, Ranked <T> > >(rankedInitExpression, FirstParameter); return(this.Select(selectExpression)); }
public static string GetRankedTypeString(RankedType rankedType) => rankedType switch {