protected virtual IQueryable <LucenePackage> ApplySearchCriteria(SearchCriteria criteria, IQueryable <LucenePackage> packages)
        {
            var advancedQuerySyntax = criteria.SearchTerm.Any(c => AdvancedQueryCharacters.Contains(c));

            if (advancedQuerySyntax)
            {
                var queryParser = new NuGetQueryParser(LuceneDataProvider.CreateQueryParser <LucenePackage>())
                {
                    AllowLeadingWildcard = true
                };

                try
                {
                    var query = queryParser.Parse(criteria.SearchTerm);
                    return(packages.Where(query));
                }
                catch (ParseException ex)
                {
                    throw new InvalidSearchCriteriaException("Failed to parse query", ex);
                }
            }

            return(from
                   pkg in packages
                   where
                   ((pkg.Id == criteria.SearchTerm).Boost(5) ||
                    (pkg.SearchId == criteria.SearchTerm).Boost(4) ||
                    (pkg.Title == criteria.SearchTerm).Boost(3) ||
                    (pkg.Tags == criteria.SearchTerm).Boost(2) ||
                    (pkg.Authors.Contains(criteria.SearchTerm) || pkg.Owners.Contains(criteria.SearchTerm)).Boost(2) ||
                    (pkg.Files.Contains(criteria.SearchTerm)) ||
                    (pkg.Summary == criteria.SearchTerm || pkg.Description == criteria.SearchTerm)).AllowSpecialCharacters()
                   select
                   pkg);
        }
        public SearchResult<ContactDocument> Search(string searchQuery)
        {
            using (var provider = new LuceneDataProvider(LuceneSearch.LuceneDirectory, Version.LUCENE_30))
            {
                provider.Settings.EnableMultipleEntities = false;

                var queryParser = provider.CreateQueryParser<ContactDocument>();
                queryParser.DefaultSearchProperty = "All";
                queryParser.DefaultOperator = Lucene.Net.QueryParsers.QueryParser.Operator.AND;

                var query = queryParser.Parse(searchQuery);

                var queryable = provider.AsQueryable<ContactDocument>();

                var results = queryable.Where(query);

                return new SearchResult<ContactDocument>
                {
                    SearchTerm = searchQuery,
                    Results = results.ToList()
                };
            }
        }