public void Should_GetCorrectSearchWeight_ForBuilding(string searchString, int expectedSearchWeight, int expectedTransitiveWeight) { // Arrange var building = new Building { Id = Guid.NewGuid(), Name = "Head Office", ShortCut = "HOFF", Description = "Head Office, Feringastraße 4, 85774 Unterföhring", }; // Act var result = _searchEvaluator.Evaluate(building, searchString); // Assert result.Should().NotBeNull(); result.weight.Should().Be(expectedSearchWeight); result.transitiveWeight.Should().Be(expectedTransitiveWeight); }
public async Task <IEnumerable <SearchResultDTO> > ApplySearch(string query) { if (string.IsNullOrWhiteSpace(query)) { return(Enumerable.Empty <SearchResultDTO>()); } var searchableItems = await GetSearchableItems(); var searchEvaluations = searchableItems.ToDictionary(x => x, v => _searchEvaluator.Evaluate(v, query)); var searchResults = searchEvaluations .Select(x => new { Item = x.Key, TotalWeight = GetTotalSearchWeight(x.Key, searchEvaluations) }) .Where(x => x.TotalWeight > 0) .OrderByDescending(x => x.TotalWeight) .Select(x => x.Item) .ToList(); return(_mapper.Map <IEnumerable <SearchResultDTO> >(searchResults)); }