/// <summary> /// Performs the search on an IFunctionInfo object and combines the results using logical AND. /// </summary> /// <param name="functionInfo">Object to perform the search on.</param> /// <param name="terms">Array of terms to search for.</param> /// <param name="target">Property of the object to search.</param> /// <returns>True if there is a match, false otherwise.</returns> public bool IsAndMatch(IFunctionInfo functionInfo, string[] terms, CalculatorFilterTarget target) { var overallMatch = true; var isMatch = false; for (var i = 0; i < terms.Length && overallMatch; i++) { if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Name)) { isMatch = this.Compare(functionInfo.Name, terms[i]); } if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Tags)) { for (var j = 0; j < functionInfo.Tags.Length && !isMatch; j++) { isMatch = this.Compare(functionInfo.Tags[j], terms[i]); } } if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Description)) { isMatch = this.Compare(functionInfo.Description, terms[i]); } overallMatch = isMatch; isMatch = false; } return(overallMatch); }
public ICalculator[] Filter(string[] terms, CalculatorFilterTarget target, bool matchCase, bool matchWholeString, MultipleFilterMatch multipleFilterMatch) { var search = new FunctionInfoSearch(matchCase, matchWholeString, multipleFilterMatch); var allCalculators = this.repository.GetAll(); var nonEmptyTerms = terms == null ? new string[0] : terms.Where(i => !string.IsNullOrWhiteSpace(i)).ToArray(); var selectedCalculators = nonEmptyTerms.Length == 0 ? allCalculators : allCalculators.Where(i => search.IsMatch(i.Module.Function.FunctionInfo, nonEmptyTerms, CalculatorFilterTarget.All)); return(selectedCalculators .OrderBy(i => i.Module.Function.FunctionInfo.Name) .ToArray()); }
/// <summary> /// Performs the search on an IFunctionInfo object and combines the results using logical OR. /// </summary> /// <param name="functionInfo">Object to perform the search on.</param> /// <param name="terms">Array of terms to search for.</param> /// <param name="target">Property of the object to search.</param> /// <returns>True if there is a match, false otherwise.</returns> public bool IsOrMatch(IFunctionInfo functionInfo, string[] terms, CalculatorFilterTarget target) { var isMatch = false; if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Name)) { isMatch = terms.Any(i => this.Compare(functionInfo.Name, i)); } if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Tags)) { for (var i = 0; i < functionInfo.Tags.Length && !isMatch; i++) { isMatch = terms.Any(j => this.Compare(functionInfo.Tags[i], j)); } } if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Description)) { isMatch = terms.Any(i => this.Compare(functionInfo.Description, i)); } return(isMatch); }
/// <summary> /// Performs the search on an IFunctionInfo object. /// </summary> /// <param name="functionInfo">Object to perform the search on.</param> /// <param name="terms">Array of terms to search for.</param> /// <param name="target">Property of the object to search.</param> /// <returns>True if there is a match, false otherwise.</returns> public bool IsMatch(IFunctionInfo functionInfo, string[] terms, CalculatorFilterTarget target) { return(this.MultipleFilterMatch == MultipleFilterMatch.And ? this.IsAndMatch(functionInfo, terms, target) : this.IsOrMatch(functionInfo, terms, target)); }