/// <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() { 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 = EnumerableExpressionHelper.CalculateHitCount(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)); }
/// <summary> /// Rank the filtered items based on the matched occurences /// </summary> /// <returns> /// Enumerable of ranked items. Each item will contain /// the amount of hits found across the defined properties /// </returns> public IEnumerable <IRanked <T> > ToRanked() { Expression combinedHitExpression = null; foreach (var propertyToSearch in this.Properties) { for (int j = 0; j < this._containingSearchTerms.Count; j++) { var searchTerm = this._containingSearchTerms[j]; var nullSafeExpresion = this.BuildNullSafeExpresion(propertyToSearch); var hitCountExpression = EnumerableExpressionHelper.CalculateHitCount(nullSafeExpresion, searchTerm, _searchOptions); combinedHitExpression = ExpressionHelper.AddExpressions(combinedHitExpression, hitCountExpression); } } var rankedInitExpression = EnumerableExpressionHelper.ConstructRankedResult <T>(combinedHitExpression, this.FirstParameter); var selectExpression = Expression.Lambda <Func <T, Ranked <T> > >(rankedInitExpression, this.FirstParameter).Compile(); return(this.Select(selectExpression.Invoke)); }
/// <summary> /// Rank the filtered items based on the matched occurences /// </summary> /// <returns> /// Enumerable of ranked items. Each item will contain /// the amount of hits found across the defined properties /// </returns> public IEnumerable <IRanked <T> > ToRanked(RankedType type = RankedType.Default) { Expression combinedHitExpression = null; foreach (var propertyToSearch in Properties) { for (int j = 0; j < _searchTerms.Count; j++) { var searchTerm = _searchTerms[j]; var nullSafeExpresion = BuildNullSafeExpresion(propertyToSearch); var hitCountExpression = type == RankedType.Default ? EnumerableExpressionHelper.CalculateHitCount(nullSafeExpresion, searchTerm, _searchOptions) : EnumerableExpressionHelper.CalculateHitCount_LeftWeighted(nullSafeExpresion, searchTerm, _searchOptions); combinedHitExpression = ExpressionHelper.AddExpressions(combinedHitExpression, hitCountExpression); } } var rankedInitExpression = EnumerableExpressionHelper.ConstructRankedResult <T>(combinedHitExpression, FirstParameter); var selectExpression = Expression.Lambda <Func <T, Ranked <T> > >(rankedInitExpression, FirstParameter).Compile(); return(this.Select(selectExpression.Invoke)); }