public void Search_WhenSearchingByANonExistentField_ReturnsNoResults() { //Arrange var document = new IndexDocument() { Id = Guid.NewGuid(), Fields = { { "Color", "Red" }, { "Size", "Large" } } }; var document2 = new IndexDocument() { Id = Guid.NewGuid(), Fields = { { "Color", "Red" }, { "Size", "Medium" } } }; var document3 = new IndexDocument() { Id = Guid.NewGuid(), Fields = { { "Color", "Blue" }, { "Size", "Small" } } }; _sut.Index(document); _sut.Index(document2); _sut.Index(document3); var searchOptions = new IndexSearchOptions(); var fieldName = Guid.NewGuid().ToString(); searchOptions.SearchBy(fieldName, new List <string>() { "Small", "Medium" }); //Act var result = _sut.Search(searchOptions); //Assert var documentResults = result.DocumentResults; Assert.IsNotNull(documentResults); Assert.AreEqual(0, documentResults.Count()); }
public SearchResults Search(SearchOptions options) { // TODO: search logic goes here. if (options == null || options.Colors == null || options.Sizes == null) { throw new ArgumentNullException("Please ensure the SearchOptions is not null, and the the Colors and Size options are not null"); } // Convert SearchOptions to IndexSearchOptions var indexSearchOptions = ToIndexSearchOptions(options); //Perform search var results = _indexer.Search(indexSearchOptions); //Convert and results return(new SearchResults { Shirts = results.DocumentResults.Select(doc => _shirts[doc.Id]).ToList(), ColorCounts = ConvertFacetsToColorCount(results.FacetResults[MakePluralSingular(nameof(options.Colors))]), SizeCounts = ConvertFacetsToSizeCount(results.FacetResults[MakePluralSingular(nameof(options.Sizes))]) }); }
public RepositoryType(IIndexer indexer) { Field(x => x.name); Field(x => x.location); Field(x => x.author); Field(x => x.gitHubUrl, nullable: true); Field(x => x.payPalUrl, nullable: true); FieldAsync <ListGraphType <PackageType> >("packages", arguments: new QueryArguments( new QueryArgument <StringGraphType> { Name = "category" }, new QueryArgument <StringGraphType> { Name = "name" }, new QueryArgument <StringGraphType> { Name = "location" }, new QueryArgument <StringGraphType> { Name = "search" }, new QueryArgument <ListGraphType <StringGraphType> > { Name = "tags" }, new QueryArgument <IntGraphType> { Name = "size" }, new QueryArgument <IntGraphType> { Name = "offset" }), resolve: async context => { IEnumerable <Entities.Package> results = context.Source.packages; var category = context.GetArgument <string>("category"); var name = context.GetArgument <string>("name"); var location = context.GetArgument <string>("location"); var search = context.GetArgument <string>("search"); var tags = context.GetArgument <List <string> >("tags"); var offset = context.GetArgument <int?>("offset"); var size = context.GetArgument <int?>("size"); if (category != null) { results = results.Where(x => x.category?.Equals(category, StringComparison.InvariantCultureIgnoreCase) == true); } if (tags != null) { results = results.Where(r => r.tags?.Any(t => tags.Any(st => st.Equals(t, StringComparison.InvariantCultureIgnoreCase))) == true); } if (name != null) { results = results.Where(x => x.name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); } if (location != null) { results = results.Where(x => x.location == location); } if (search != null) { var matches = await indexer.Search(search, offset, size); if (matches.Any()) { return(results.Where(x => matches.Contains(x.location))); } else { return(null); } } return(GraphQLHelpers.PageResults(results, size, offset)); }); }