protected TListModel Search <TListModel>(IMember member, JobAdSearchCriteria criteria, JobAdsPresentationModel presentation, JobAdListType listType)
            where TListModel : JobAdSearchListModel, new()
        {
            presentation = PreparePresentationModel(presentation);

            // Search.

            var execution = _executeJobAdSearchCommand.Search(member, criteria, presentation.Pagination.ToRange());

            var model = new TListModel
            {
                Criteria     = execution.Criteria,
                Presentation = presentation,
                ListType     = listType,
                Results      = new JobAdListResultsModel
                {
                    TotalJobAds  = execution.Results.TotalMatches,
                    IndustryHits = execution.Results.IndustryHits.ToDictionary(i => i.Key.ToString(), i => i.Value),
                    JobTypeHits  = GetEnumHitsDictionary(execution.Results.JobTypeHits, JobTypes.All, JobTypes.None),
                    JobAdIds     = execution.Results.JobAdIds,
                    JobAds       = GetMemberJobAdViews(member, execution.Results.JobAdIds),
                },
                Folders    = GetFoldersModel(),
                BlockLists = GetBlockListsModel(),
            };

            return(model);
        }
        private void TestSearch(JobAdSearchCriteria criteria, ICollection <string> expectedTitles)
        {
            var execution = _executeJobAdSearchCommand.Search(null, criteria, null);

            Assert.AreEqual(expectedTitles.Count, execution.Results.TotalMatches);
            Assert.AreEqual(expectedTitles.Count, execution.Results.JobAdIds.Count);

            foreach (var expectedTitle in expectedTitles)
            {
                var found = false;
                foreach (var jobAdId in execution.Results.JobAdIds)
                {
                    var jobAd = _jobAdsCommand.GetJobAd <JobAdEntry>(jobAdId);
                    if (jobAd.Title == expectedTitle)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    Assert.Fail("Could not find job with title '" + expectedTitle + "'.");
                }
            }
        }
Example #3
0
        IList <JobAdFeedElement> IJobAdFeedsManager.GetJobAdFeed(IEnumerable <JobAdSearchCriteria> criterias, IEnumerable <Guid> industryIds, DateTime?modifiedSince)
        {
            IList <Guid> jobAdIds = null;

            foreach (var criteria in criterias)
            {
                if (modifiedSince != null)
                {
                    criteria.Recency = DateTime.Now - modifiedSince;
                }

                if (industryIds != null)
                {
                    var industryIdList = industryIds.ToList();
                    if (industryIdList.Count > 0)
                    {
                        criteria.IndustryIds = criteria.IndustryIds == null
                            ? industryIdList
                            : criteria.IndustryIds.Concat(industryIdList).ToList();
                    }
                }

                var execution = _executeJobAdSearchCommand.Search(null, criteria, null);

                jobAdIds = jobAdIds == null
                    ? execution.Results.JobAdIds
                    : jobAdIds.Concat(execution.Results.JobAdIds).ToList();
            }

            return(GetJobAdFeeds(jobAdIds).ToList());
        }
Example #4
0
        private JobAdSearchExecution Search(JobAdSearch search, JobAdSearchAlert alert)
        {
            // Set the criteria recency to ensure only recently added jobs are included in the alert results.

            var criteria = search.Criteria.Clone();

            criteria.Recency = DateTime.Now - alert.LastRunTime;

            // Run the search as the owner.

            var member = new Member {
                Id = search.OwnerId
            };

            // Search.

            var execution = new JobAdSearchExecution
            {
                SearcherId = search.OwnerId,
                Criteria   = search.Criteria,
                Context    = "Alert",
                Results    = _executeJobAdSearchCommand.Search(member, criteria, new Range(0, MaximumResults)).Results,
            };

            // Update the last run time for next time.

            _jobAdSearchAlertsCommand.UpdateLastRunTime(search.Id, DateTime.Now);
            return(execution);
        }
Example #5
0
        protected IList <JobAd> Search(string keywords)
        {
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(keywords);

            var execution = _executeJobAdSearchCommand.Search(null, criteria, null);

            return(_jobAdsQuery.GetJobAds <JobAd>(execution.Results.JobAdIds));
        }
Example #6
0
        private void TestSearch(JobAdSearchCriteria criteria, params JobAd[] expectedResults)
        {
            var execution = _executeJobAdSearchCommand.Search(null, criteria, null);

            Assert.AreEqual(expectedResults.Length, execution.Results.TotalMatches);
            Assert.AreEqual(expectedResults.Length, execution.Results.JobAdIds.Count);
            for (var index = 0; index < expectedResults.Length; index++)
            {
                Assert.AreEqual(expectedResults[index].Id, execution.Results.JobAdIds[index], string.Format("Result {0} did not match", index));
            }
        }
Example #7
0
        private JobSearchModel GetSearchJobSearchModel(IMember member, JobAdSearchCriteria criteria)
        {
            var execution = _executeJobAdSearchCommand.Search(member, criteria, new Range(0, 1));

            if (execution.Results.TotalMatches < 2)
            {
                return(null);
            }

            return(new JobSearchModel {
                TotalMatches = execution.Results.TotalMatches, Description = criteria.GetDisplayText()
            });
        }
Example #8
0
        public override void ExecuteTask(string[] args)
        {
            var keywords = args[0];
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(keywords);
            var execution = _executeJobAdSearchCommand.Search(null, criteria, null);

            Console.WriteLine("Total results: " + execution.Results.TotalMatches);
            foreach (var jobAdId in execution.Results.JobAdIds)
            {
                Console.WriteLine(jobAdId);
            }
        }
 private SearchEnginesModel CreateModel()
 {
     return(new SearchEnginesModel
     {
         MemberSearch = new MemberSearchEngineModel
         {
             TotalMembers = _executeMemberSearchCommand.Search(null, new MemberSearchCriteria(), new Range(0, 1)).Results.TotalMatches,
         },
         JobAdSearch = new JobAdSearchEngineModel
         {
             TotalJobAds = _executeJobAdSearchCommand.Search(null, new JobAdSearchCriteria(), new Range(0, 1)).Results.TotalMatches,
         }
     });
 }
Example #10
0
        private JobAdSearch CreateTestSavedJobSearchAlert(Guid jobSearcherId, string jobTitle, DateTime whenSaved)
        {
            var criteria = new JobAdSearchCriteria
            {
                AdTitle = jobTitle,
            };

            var execution = new JobAdSearchExecution {
                SearcherId = jobSearcherId, Criteria = criteria, Context = "Search"
            };

            execution.Results = _executeJobAdSearchCommand.Search(null, execution.Criteria, null).Results;

            _jobAdSearchesCommand.CreateJobAdSearchExecution(execution);

            var search = new JobAdSearch {
                OwnerId = jobSearcherId, Name = "Test Search Alert", Criteria = execution.Criteria.Clone()
            };

            _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(jobSearcherId, search, whenSaved);

            return(search);
        }
Example #11
0
        private IList <MemberJobAdView> GetSuggestedJobs(IMember member, JobAdView jobAd)
        {
            const string method = "GetSuggestedJobs";

            try
            {
                // If the jobAd is closed and there is a query in the referrer then do a search.

                if (jobAd.Status == JobAdStatus.Closed)
                {
                    var q = HttpContext.Request.UrlReferrer == null
                        ? string.Empty
                        : HttpUtility.ParseQueryString(HttpContext.Request.UrlReferrer.Query)["q"];

                    if (!string.IsNullOrEmpty(q))
                    {
                        var criteria = new JobAdSearchCriteria();
                        criteria.SetKeywords(q);
                        return(GetSuggestedJobs(member, _executeJobAdSearchCommand.Search(member, criteria, new Range(0, MaxSuggestedJobsCount)).Results));
                    }
                }

                // If the member is logged in then get suggested jobs.

                if (member != null)
                {
                    return(GetSuggestedJobs(member, _executeJobAdSearchCommand.SearchSuggested(member, null, new Range(0, MaxSuggestedJobsCount)).Results));
                }

                // Otherwise get similar jobs to this one.

                return(GetSuggestedJobs(null, _executeJobAdSearchCommand.SearchSimilar(null, jobAd.Id, new Range(0, MaxSuggestedJobsCount)).Results));
            }
            catch (Exception ex)
            {
                // If there is a problem then log but don't stop the user doing what they need to do.

                EventSource.Raise(Event.Error, method, "Cannot get suggested jobs.", ex, new StandardErrorHandler(), Event.Arg("jobAdId", jobAd.Id));
                return(new List <MemberJobAdView>());
            }
        }
Example #12
0
        public ActionResult Search(JobAdSearchCriteria criteria, JobAdsPresentationModel presentation)
        {
            try
            {
                presentation = PreparePresentationModel(presentation);
                criteria.PrepareCriteria();

                var execution = _executeJobAdSearchCommand.Search(CurrentMember, criteria, presentation.Pagination.ToRange());

                SaveSearch(SearchContext.Filter, CurrentMember, execution.Results, criteria, presentation.Pagination.Page.Value);
                MemberContext.CurrentSearch = new JobAdSearchNavigation(criteria, presentation);

                // Be sure to maintain the order of the search.

                var views  = _memberJobAdViewsQuery.GetMemberJobAdViews(CurrentMember, execution.Results.JobAdIds).ToDictionary(v => v.Id, v => v);
                var jobAds = (from i in execution.Results.JobAdIds
                              select views[i]).ToList();

                var model = new JsonJobAdsResponseModel
                {
                    TotalJobAds      = execution.Results.TotalMatches,
                    IndustryHits     = execution.Results.IndustryHits.ToDictionary(i => i.Key.ToString(), i => i.Value),
                    JobTypeHits      = GetEnumHitsDictionary(execution.Results.JobTypeHits, JobTypes.All, JobTypes.None),
                    JobAds           = jobAds,
                    CriteriaHtml     = criteria.GetCriteriaHtml(),
                    Hash             = criteria.GetHash(),
                    QueryStringForGa = new AdSenseQueryGenerator(new JobAdSearchCriteriaAdSenseConverter()).GenerateAdSenseQuery(criteria)
                };

                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(Json(new JsonResponseModel()));
        }
Example #13
0
        private void CreateTestSavedJobSearchAlert(IHasId <Guid> jobSearcher, string jobTitle, LocationReference location, int?distance, DateTime whenSaved)
        {
            var criteria = new JobAdSearchCriteria
            {
                AdTitle  = jobTitle,
                Location = location,
                Distance = distance
            };

            var execution = new JobAdSearchExecution {
                SearcherId = jobSearcher.Id, Criteria = criteria, Context = "Test"
            };

            execution.Results = _executeJobAdSearchCommand.Search(null, execution.Criteria, null).Results;

            _jobAdSearchesCommand.CreateJobAdSearchExecution(execution);

            var search = new JobAdSearch {
                OwnerId = jobSearcher.Id, Name = "Test Search Alert", Criteria = execution.Criteria.Clone()
            };

            _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(jobSearcher.Id, search, whenSaved);
        }
Example #14
0
 private ICollection <Guid> Search(IMember member, JobAdSearchCriteria criteria)
 {
     return(_executeJobAdSearchCommand.Search(member, criteria, null).Results.JobAdIds);
 }