public IEnumerable <SearchResult> ByKeyword(string keyword)
        {
            _logger.LogInformation($"{keyword}");

            return(_policy.Execute(() =>
            {
                // get all Frameworks
                var allFrameworks = _frameworkDatastore.GetAll();

                // get all Solutions via frameworks
                var allSolns = allFrameworks
                               .SelectMany(fw => _solutionDatastore.ByFramework(fw.Id));

                // get all Capabilities via frameworks
                var allCapsFrameworks = allFrameworks
                                        .SelectMany(fw => _capabilityDatastore.ByFramework(fw.Id));

                // get all Capabilities with keyword
                var allCapsKeywordIds = allCapsFrameworks
                                        .Where(cap =>
                                               cap.Name.ToLowerInvariant().Contains(keyword.ToLowerInvariant()) ||
                                               cap.Description.ToLowerInvariant().Contains(keyword.ToLowerInvariant()))
                                        .Select(cap => cap.Id);

                // get all unique Solutions with at least one ClaimedCapability with keyword
                var allSolnsCapsKeyword = allSolns
                                          .Where(soln => _claimedCapabilityDatastore
                                                 .BySolution(soln.Id)
                                                 .Select(cc => cc.CapabilityId)
                                                 .Intersect(allCapsKeywordIds)
                                                 .Any())
                                          .Distinct();

                var searchResults = allSolnsCapsKeyword.Select(soln =>
                                                               new SearchResult
                {
                    SolutionEx = _solutionExDatastore.BySolution(soln.Id),
                    Distance = _claimedCapabilityDatastore.BySolution(soln.Id).Count() - allCapsKeywordIds.Count()
                });

                return searchResults;
            }));
        }
Exemplo n.º 2
0
 public IEnumerable <Capabilities> ByFramework(string frameworkId)
 {
     return(_filter.Filter(_datastore.ByFramework(frameworkId)));
 }