public static IQueryable<Package> Search(this IQueryable<Package> source, string searchTerm) { // Split the search terms by spaces var terms = (searchTerm ?? String.Empty).Split(); // Build a list of expressions for each term var expressions = new List<LambdaExpression>(); foreach (var criteria in searchCriteria) { foreach (var term in terms) { expressions.Add(criteria(term)); } } // Build a giant or statement using the bodies of the lambdas var body = expressions.Select(p => p.Body) .Aggregate(Expression.OrElse); // Now build the final predicate var parameterExpr = Expression.Parameter(typeof(Package)); // Fix up the body to use our parameter expression body = new ParameterExpressionReplacer(parameterExpr).Visit(body); // Build the final predicate var predicate = Expression.Lambda<Func<Package, bool>>(body, parameterExpr); // Apply it to the query return source.Where(predicate); }
public static IQueryable<Package> Search(this IQueryable<Package> source, string searchTerm) { if (String.IsNullOrWhiteSpace(searchTerm)) { return source; } // Split the search terms by spaces var terms = (searchTerm ?? String.Empty).Split(); // Build a list of expressions for each term var expressions = new List<LambdaExpression>(); foreach (var term in terms) { var localSearchTerm = term.to_lower(); if (localSearchTerm.StartsWith("id:")) { expressions.Add(idCriteria(localSearchTerm.Replace("id:", string.Empty))); } if (localSearchTerm.StartsWith("author:")) { expressions.Add(authorCriteria(localSearchTerm.Replace("author:", string.Empty))); } else if (localSearchTerm.StartsWith("tag:")) { expressions.Add(tagCriteria(localSearchTerm.Replace("tag:", string.Empty))); } else { foreach (var criteria in searchCriteria) { expressions.Add(criteria(localSearchTerm)); } } } //todo this becomes an AND // Build a giant or statement using the bodies of the lambdas var body = expressions.Select(p => p.Body) .Aggregate(Expression.OrElse); // Now build the final predicate var parameterExpr = Expression.Parameter(typeof(Package)); // Fix up the body to use our parameter expression body = new ParameterExpressionReplacer(parameterExpr).Visit(body); // Build the final predicate var predicate = Expression.Lambda<Func<Package, bool>>(body, parameterExpr); // Apply it to the query return source.Where(predicate); }
public override IEnumerable<object[]> GetData(MethodInfo testMethod) { var folderNames = new List<object[]> { new object[] { Constants.PackagesFolderName, true }, new object[] { Constants.UploadsFolderName, false } }; if (!IncludePermissions) { folderNames = folderNames.Select(fn => new[] { fn.ElementAt(0) }).ToList(); } return folderNames; }
private static void AddPackages(List<PackageIndexEntity> packages, bool creatingIndex) { if (!creatingIndex) { // If this is not the first time we're creating the index, clear any package registrations for packages we are going to updating. var packagesToDelete = from packageRegistrationKey in packages.Select(p => p.PackageRegistrationKey).Distinct() select new Term("PackageRegistrationKey", packageRegistrationKey.ToString(CultureInfo.InvariantCulture)); indexWriter.DeleteDocuments(packagesToDelete.ToArray()); } // As per http://stackoverflow.com/a/3894582. The IndexWriter is CPU bound, so we can try and write multiple packages in parallel. // The IndexWriter is thread safe and is primarily CPU-bound. Parallel.ForEach(packages, AddPackage); indexWriter.Commit(); }
public override IEnumerable<object[]> GetData( MethodInfo methodUnderTest, Type[] parameterTypes) { var folderNames = new List<object[]> { new object[] { Const.PackagesFolderName, true }, new object[] { Const.UploadsFolderName, false } }; if (!IncludePermissions) folderNames = folderNames.Select(fn => new object[] { fn.ElementAt(0) }).ToList(); return folderNames; }