public void MultipleResult() { var results = new NuGetQueryParser().Parse("\"hello you\" id:beautiful little:\"creatures\""); Assert.Equal(new NuGetSearchTerm { Field = null, TermOrPhrase = "hello you" }, results[0]); Assert.Equal(new NuGetSearchTerm { Field = "id", TermOrPhrase = "beautiful" }, results[1]); Assert.Equal(new NuGetSearchTerm { Field = "little", TermOrPhrase = "creatures" }, results[2]); }
public void ExtraColon() { var results = new NuGetQueryParser().Parse("ID::Foo"); Assert.Single(results); Assert.Equal(new NuGetSearchTerm { Field = "ID", TermOrPhrase = "Foo" }, results[0]); }
public void LeadingColon() { var results = new NuGetQueryParser().Parse(":Foo"); Assert.Single(results); Assert.Equal(new NuGetSearchTerm { TermOrPhrase = "Foo" }, results[0]); }
public void EmptyPhrase() { var results = new NuGetQueryParser().Parse("\"\""); Assert.Single(results); Assert.Equal(new NuGetSearchTerm { TermOrPhrase = "" }, results[0]); }
public void SingleResult(string input, string[] expectedResults) { var results = new NuGetQueryParser().Parse(input); Assert.Single(results); var expected = new NuGetSearchTerm { Field = expectedResults[0], TermOrPhrase = expectedResults[1] }; Assert.Equal(expected, results[0]); }
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 void TermlessField() { var results = new NuGetQueryParser().Parse("Id:"); Assert.Empty(results); }
public void EmptyString() { var results = new NuGetQueryParser().Parse(""); Assert.Empty(results); }