Exemplo n.º 1
0
        private JobAdSearchResults GetSearchResults(BrowseResult result, int skip, int take)
        {
            // TotalMatches

            var searchResults = new JobAdSearchResults {
                TotalMatches = result.getNumHits()
            };

            // JobAdIds

            var hits = result.getHits();

            searchResults.JobAdIds = hits
                                     .Skip(skip)
                                     .Take(take)
                                     .Select(hit => new Guid(_browser.doc(hit.getDocid()).get(SearchFieldName.Id)))
                                     .ToArray();

            // Facets

            var facetMap = result.getFacetMap();

            if (facetMap != null)
            {
                searchResults.IndustryHits = GetFieldHits(facetMap, FieldName.Industries, v => new Guid(v));
                searchResults.JobTypeHits  = GetFieldHits(facetMap, FieldName.JobTypes, v => JobTypesFieldHandler.Decode(v));
            }

            return(searchResults);
        }
Exemplo n.º 2
0
        public static string GetItemsFoundHtml(this JobAdSearchResults results)
        {
            var sb      = new StringBuilder();
            var matches = results.TotalMatches;

            sb.Append("<b>");
            sb.Append(matches);
            sb.Append(matches == 1 ? " job</b> was found" : " jobs</b> were found");

            return(sb.ToString());
        }
Exemplo n.º 3
0
        public IList <JobSearchAlertEmailResult> CreateEmailResults(JobAdSearchResults searchResults, JobAdSearchCriteria criteria, int maximumResults)
        {
            var emailResults = new List <JobSearchAlertEmailResult>();

            if (searchResults.JobAdIds.Count > 0)
            {
                var highlighter = new JobSearchHighlighter(criteria, StartHighlightTag, EndHighlightTag);
                AppendResults(emailResults, searchResults, maximumResults, highlighter, criteria.KeywordsExpression != null);
            }
            return(emailResults);
        }
Exemplo n.º 4
0
        public static string GetCaptionDisplayHtml(this JobAdSearchResults results, JobAdSearchCriteria criteria, int startIndex, int numResults)
        {
            var matches = results.TotalMatches;
            var sb      = new StringBuilder();

            if (matches == 0)
            {
                return("No results found");
            }

            sb.AppendFormat("Results {0}-{1}<small> of {2}</small>", (startIndex + 1), Math.Min(startIndex + numResults, matches), matches);

            if (criteria != null)
            {
                sb.Append(" matching " + criteria.GetDisplayHtml());
            }

            return(sb.ToString());
        }
Exemplo n.º 5
0
        private static JobSearchResultSetEntity Map(this JobAdSearchResults results, int maxCount)
        {
            var entity = new JobSearchResultSetEntity
            {
                id    = results.Id,
                count = results.TotalMatches,
                JobSearchResultEntities = new EntitySet <JobSearchResultEntity>()
            };

            entity.JobSearchResultEntities.AddRange(
                from r in Enumerable.Range(1, Math.Min(results.JobAdIds.Count, maxCount))
                select new JobSearchResultEntity
            {
                rank    = (short)r,
                jobAdId = results.JobAdIds[r - 1]
            });

            return(entity);
        }
Exemplo n.º 6
0
        private JobAdSearchResults GetSortResults(BrowseResult result, int skip, int take)
        {
            // TotalMatches

            var sortResults = new JobAdSearchResults {
                TotalMatches = result.getNumHits()
            };

            // JobAdIds

            var hits = result.getHits();

            sortResults.JobAdIds = hits
                                   .Skip(skip)
                                   .Take(take)
                                   .Select(hit => new Guid(_browser.doc(hit.getDocid()).get(SearchFieldName.Id)))
                                   .ToArray();

            return(sortResults);
        }
Exemplo n.º 7
0
        private void SaveSearch(SearchContext context, IHasId <Guid> member, JobAdSearchResults results, JobAdSearchCriteria criteria, int page)
        {
            try
            {
                var userAgent = HttpContext.Request.UserAgent;

                //never log monitoring calls
                if (!string.IsNullOrEmpty(userAgent) && userAgent.Contains("LinkmeMonitoring"))
                {
                    return;
                }

                var app       = ActivityContext.Channel.App;
                var execution = new JobAdSearchExecution
                {
                    Context  = context.ToString(),
                    Criteria = criteria.Clone(),
                    Results  = new JobAdSearchResults
                    {
                        JobAdIds     = page == 1 ? results.JobAdIds : new List <Guid>(),
                        TotalMatches = results.TotalMatches
                    },
                    SearcherId = member == null ? (Guid?)null : member.Id,
                    SearchId   = null,
                    ChannelId  = app.ChannelId,
                    AppId      = app.Id,
                    StartTime  = DateTime.Now,
                };

                _jobAdSearchesCommand.CreateJobAdSearchExecution(execution);
            }
            catch (Exception)
            {
                // Never fail for this.
            }
        }
Exemplo n.º 8
0
 private static void AssertJobAds(JobAdSearchResults results, params JobAd[] jobAds)
 {
     Assert.AreEqual(jobAds.Length, results.JobAdIds.Count);
     Assert.IsTrue(results.JobAdIds.CollectionEqual(from j in jobAds select j.Id));
 }
Exemplo n.º 9
0
 private IList <MemberJobAdView> GetSuggestedJobs(IMember member, JobAdSearchResults results)
 {
     return(results.TotalMatches > 0
         ? _memberJobAdViewsQuery.GetMemberJobAdViews(member, results.JobAdIds)
         : new List <MemberJobAdView>());
 }
Exemplo n.º 10
0
        private void AppendResults(ICollection <JobSearchAlertEmailResult> emailResults, JobAdSearchResults searchResults, int maximumResults, JobSearchHighlighter highlighter, bool haveKeywords)
        {
            foreach (var jobAdId in searchResults.JobAdIds)
            {
                // Get the job ad for the result.

                var jobAd = _jobAdsQuery.GetJobAd <JobAd>(jobAdId);
                if (jobAd != null)
                {
                    AppendResult(emailResults, jobAd, highlighter, haveKeywords);
                    if (emailResults.Count == maximumResults)
                    {
                        return;
                    }
                }
            }
        }