public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (pipelineResult.ScoredInterests == null) throw new ArgumentNullException("pipelineResult", "Scored results should be provided"); pipelineResult.ScoredInterests = _closeInterestLimiter.LimitCloseInterests(pipelineResult.ScoredInterests).Cast<ScoredRelatedInterestDto>().ToList(); }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (pipelineResult.ScoredInterests == null) throw new ArgumentNullException("pipelineResult", "Scored results should be provided"); pipelineResult.ScoredInterests = pipelineResult.ScoredInterests.Where(x => x.Score >= Constants.EXPLICIT_SEARCH_INTEREST_THRESHOLD).ToList(); }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (pipelineResult.ScoredInterests == null) throw new ArgumentNullException("pipelineResult", "Scored results should be provided"); _mainCategoryScoreCalculator.CalculateMainCategoryScores(pipelineResult.ScoredInterests); }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (request == null) throw new ArgumentNullException("request", "Location data is required"); if (request.LocationData == null) throw new ArgumentNullException("request", "Location data is required"); var geo = new GeoCoordinate(request.LocationData.Latitude, request.LocationData.Longitude); foreach (var user in pipelineResult.Users) { var distanceTo = (float) geo.GetDistanceTo(new GeoCoordinate(user.Latitude, user.Longitude)); float miles = distanceTo / _metersToMiles; var res = (int) Math.Round(miles, 0, MidpointRounding.AwayFromZero); float locationMultiplier = (Constants.LOCATION_MAX_MILES - res) * Constants.LOCATION_MILE_MULTIPLIER; if (Math.Abs(locationMultiplier) < float.Epsilon) //float precision - if not 0 { locationMultiplier = float.Epsilon; } user.Score *= locationMultiplier; } }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); _interestScoreCalculator.CalculateRelatedInterestScore(pipelineResult.RelatedInterests); pipelineResult.ScoredInterests = pipelineResult.RelatedInterests.Select(x => new ScoredRelatedInterestDto(x.Id, x.Score, x.Slug, x.IsMainCategory, x.ExplicitSearch, x.Weight.Count)).ToList(); }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (request == null) throw new ArgumentNullException("request"); if (request.User == null) throw new ArgumentNullException("request","User required"); var relatedInterestDtos = _interestRepository.GetRelatedInterests(request.User.Interests.Select(x => x.Interest.Slug).ToList()).ToList(); pipelineResult.RelatedInterests.AddRange(relatedInterestDtos); }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (pipelineResult.Users == null) throw new ArgumentNullException("pipelineResult", "Users must be provided"); pipelineResult.Users = pipelineResult .Users .OrderByDescending(x => x.Score) .ToList(); }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (request.User == null) throw new ArgumentNullException("request", "User cannot be null"); pipelineResult.UserQuery = pipelineResult .UserQuery .Where(x => x != request.User); }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (request == null) throw new ArgumentNullException("request"); if (request.InterestSearch == null) throw new ArgumentNullException("request", "Search keys required"); var relatedInterestDtos = _interestRepository.GetRelatedInterests(request.InterestSearch).ToList(); relatedInterestDtos.ForEach(x => x.ExplicitSearch = true); pipelineResult.RelatedInterests.AddRange(relatedInterestDtos); }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); foreach (var user in pipelineResult.Users) { user.Score += user.InterestDtos.Sum( x => { var foundInterest = pipelineResult.ScoredInterests.SingleOrDefault(y => y.Id == x.InterestId); return foundInterest != null ? foundInterest.Score : 0f; }); } }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (pipelineResult.ScoredInterests == null) throw new ArgumentNullException("pipelineResult", "Scored results should be provided"); var scoredRelatedInterestDtos = pipelineResult .ScoredInterests .Where(x => x.ExplicitSearch && x.Hops < Constants.EXPLICIT_SEARCH_INTEREST_MULTIPLIER.Length) .ToList(); foreach (var scoredRelatedInterestDto in scoredRelatedInterestDtos) { scoredRelatedInterestDto.Score *= Constants.EXPLICIT_SEARCH_INTEREST_MULTIPLIER[scoredRelatedInterestDto.Hops]; } }
public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request) { if (pipelineResult == null) throw new ArgumentNullException("pipelineResult"); if (pipelineResult.ScoredInterests == null) throw new ArgumentNullException("pipelineResult", "ScoredInterests is required"); var interestIds = pipelineResult .ScoredInterests .Select(x => x.Id) .ToList(); //this needs to be a list since it's used in a query expression pipelineResult.UserQuery = pipelineResult .UserQuery .Where(x => x.Interests.Any(y => interestIds.Contains(y.Interest.Id))); }
public UsersByInterestViewModel GetGetUsersByInterests(string slugs, int? page, string username) { var retVal = new UsersByInterestViewModel(); var user = _userTasks.GetUser(username); //NOTE: The slug string was lowered cased because if someone changed 'software' to 'Software' in the query string // no matches would be found. List<string> aliasCollection = slugs .ToLower() .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); var request = new UserSearchPipelineRequest { User = user, InterestSearch = aliasCollection, LocationData = user.Location.Data }; var userSearchPipelineResult = _userSearchPipeline.Execute(request); //assume interests is ordered highets to smallest List<string> interests = userSearchPipelineResult .ScoredInterests .Select(x => x.Slug) .Reverse() .ToList(); foreach (var foundUser in userSearchPipelineResult.Users) { var indvResultViewModel = new UsersByInterestViewModel.IndividualResultViewModel(foundUser, interests); if (indvResultViewModel.ImageUrl == null) { indvResultViewModel.ImageUrl = UrlHelper.GenerateContentUrl(Constants.DEFAULT_PROFILE_IMAGE, _httpProvider.Context); } retVal.Results.Add(indvResultViewModel); } retVal.PagedResults = retVal.Results.AsPagination(page ?? 1, 8); return retVal; }
public void Filter(UserSearchPipelineResult userSearchPipelineResult, UserSearchPipelineRequest request) { if (userSearchPipelineResult == null) throw new ArgumentNullException("userSearchPipelineResult"); userSearchPipelineResult.Users = userSearchPipelineResult.UserQuery.Select(x => new UserSearchResultDto(x)).ToList(); }
public FeedListApiModel GetFeedList(string userName, int? page, string search) { var retVal = new FeedListApiModel(); User user = _userTasks.GetUser(userName); var urlHelper = _mvcUrlHelperProvider.ProvideUrlHelper(); var request = new UserSearchPipelineRequest { User = user, LocationData = user.Location.Data }; int total = 0; var explicitSearch = !string.IsNullOrWhiteSpace(search); if (explicitSearch) { //NOTE: The slug string was lowered cased because if someone changed 'software' to 'Software' in the query string // no matches would be found. List<string> aliasCollection = search .ToLower() .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); request.InterestSearch = aliasCollection; } var result = _userSearchPipeline.Execute(request); var userFeedItemApiModels = result.Users.Select( x => new UserFeedItemApiModel { ProfileImageUrl = x.ImageUrl ?? Constants.DEFAULT_PROFILE_IMAGE, Username = x.Username, MajorLocationName = x.MajorLocationName, UserPageUrl = urlHelper.Action("Index", "User", new { username = x.Username }) }).TakeFeedPage(page).ToList(); foreach (var userFeedItem in userFeedItemApiModels) { var commonInterest = _userInterestTasks.GetInterestsInCommon(user, _userTasks.GetUser(userFeedItem.Username)); userFeedItem.CommonInterestCount = commonInterest.Count(x => x.IsExactMatch); userFeedItem.RelatedInterestCount = commonInterest.Count(x => !x.IsExactMatch); userFeedItem.InterestsInCommon = commonInterest .OrderByDescending(x => x.Score) .Take(5) .Select( x => new UserFeedItemApiModel.InterestInCommonApiModel { Name = x.Name, IsExactMatch = x.IsExactMatch }) .ToList(); } total += userFeedItemApiModels.Count; retVal.FeedItems.AddRange(userFeedItemApiModels); if (!explicitSearch) { IList<UserPostDto> postDtos = _postTasks.GetPostsByInterests(user.Interests.Select(x => x.Interest).ToList()); var dtos = postDtos .Select( x => new PostFeedItemApiModel(x) { UserPageUrl = urlHelper.Action("Index", "User", new { username = x.Username }), PostUrl = urlHelper.Action("Index", "Post", new { post = x.Post.PostId }), IsLikedByUser = x.Post.Likes.Any(y => y.UserId == user.Id) }).TakeFeedPage(page).ToList(); retVal.FeedItems.AddRange(dtos); total += dtos.Count; } retVal.Total = total; retVal.TotalReturned = retVal.FeedItems.Count; retVal.FeedItems = retVal.FeedItems.Randomize().ToList(); return retVal; }
public UserSearchPipelineResult Execute(UserSearchPipelineRequest request) { //set flags var explicitSearch = request.InterestSearch != null; //start with list of users var retVal = new UserSearchPipelineResult { UserQuery = _userRepository.FindAll() }; /************ Find Dependent Data ******************/ //run filter to query potential interests based on the user's list of interests _findTargetUsersRelatedInterestsFilter.Filter(retVal, request); //run filter to query potential interests based on what was explicitly searched for if (explicitSearch) { _findRelatedInterestsFromKeywordSearchFilter.Filter(retVal, request); } /************ Calculate Signal Data ******************/ //score interests based on user _calculateRelatedInterestScoreFilter.Filter(retVal, request); //score interests based on explicit search if (explicitSearch) { _calculateExplicitSearchInterestScoreFilter.Filter(retVal, request); } //main categories get less points - too vague _calculateMainCategoryInterestScoreFilter.Filter(retVal, request); //keep only the highest scored interests _calculateHighestScoredInterestFilter.Filter(retVal, request); /************ Limits/Constraints ******************/ //if explicit search, hide less relevant interests if (explicitSearch) { _limitByExplicitSearchScoreFilter.Filter(retVal, request); } else { //only keep 'close' interests _limitByCloseInterestFilter.Filter(retVal, request); } //filter users by interests and related _limitByInterestFilter.Filter(retVal, request); //dont show the target user in results _limitByTargetUserFilter.Filter(retVal, request); /************ Transform ******************/ //transform users to found dtos _transformUserToScoredUserFilter.Filter(retVal, request); /************ Assign User Score ******************/ //sort users by interests points _assignInterestCommonalityScoreFilter.Filter(retVal, request); _assignLocationScoreFilter.Filter(retVal, request); /************ Sort ******************/ //order by scores _sortUserScoreFilter.Filter(retVal, request); return retVal; }