private LuceneQuery GetApplicationsMltQuery(MoreLikeThis mlt, IEnumerable <Guid> jobAdIds) { var jobAds = _jobAdsQuery.GetJobAds <JobAd>(jobAdIds); var applicationsString = new StringBuilder(); foreach (var jobAd in jobAds) { applicationsString.AppendLine(jobAd.Title) .AppendLine(jobAd.Description.BulletPoints == null ? string.Empty : jobAd.Description.BulletPoints.ToString()) .AppendLine(jobAd.Description.Content); } return(mlt.like(new StringReader(applicationsString.ToString()))); }
private static LuceneQuery GetCandidateMltQuery(MoreLikeThis mlt, ICandidate candidate, Resume resume, string method) { var candidateString = new StringBuilder(); if (resume.Jobs != null) { // construct a stream of relevant job data for passing to mlt foreach (var job in resume.Jobs.Take(5)) { candidateString.AppendLine(job.Description).AppendLine(job.Title); } } #region Log if (EventSource.IsEnabled(Event.Trace)) { EventSource.Raise(Event.Trace, method, "Building MLT Query #1", Event.Arg("Analysis Text", candidateString.ToString())); } #endregion // add additional relevant resume data candidateString.AppendLine(candidate.DesiredJobTitle); candidateString.AppendLine(resume.Summary).AppendLine(resume.Skills); if (candidateString.Length < 1000) { #region Log if (EventSource.IsEnabled(Event.Trace)) { EventSource.Raise(Event.Trace, method, "MLT Query aborted - insufficient text for analysis", Event.Arg("Analysis Text", candidateString.ToString())); } #endregion return(null); } #region Log if (EventSource.IsEnabled(Event.Trace)) { EventSource.Raise(Event.Trace, method, "Building MLT Query #2", Event.Arg("Analysis Text", candidateString.ToString())); } #endregion return(mlt.like(new StringReader(candidateString.ToString()))); }
JobAdSearchResults IJobAdSearchService.SearchSimilar(Guid?memberId, Guid jobAdId, JobAdSearchQuery searchQuery) { const string method = "GetSimilarJobs"; try { var reader = GetReader(); var searcher = new Searcher(reader); var docId = searcher.Fetch(jobAdId); // If the job ad cannot be found then return no results. if (docId == -1) { return(new JobAdSearchResults()); } var jobAd = _jobAdsQuery.GetJobAd <JobAd>(jobAdId); if (jobAd == null) { return(new JobAdSearchResults()); } // Look for more like this. var mlt = new MoreLikeThis(reader); mlt.setAnalyzer(_contentAnalyzer); mlt.setFieldNames(new [] { FieldName.Content, FieldName.Title }); var query = mlt.like(docId); //query = new SeniorityIndexHandler().GetQuery(query, new JobAdSearchQuery {SeniorityIndex = jobAd.SeniorityIndex}); // Ensure the initial job is not in the results. var searchFilter = new BooleanFilter(); searchFilter.add(new FilterClause(new SpecialsFilter(SearchFieldName.Id, false, new[] { jobAdId.ToFieldValue() }), BooleanClause.Occur.MUST_NOT)); // Add salary and location restriction. var filter = _indexer.GetFilter( new JobAdSearchQuery { Salary = FudgeSalary(jobAd.Description.Salary), ExcludeNoSalary = true, Location = jobAd.Description.Location, Distance = 50, }, null, null); searchFilter.add(new FilterClause(filter, BooleanClause.Occur.MUST)); return(searcher.Search(query, searchFilter, null, null, searchQuery.Skip, searchQuery.Take ?? reader.maxDoc(), false)); } catch (Exception e) { #region Log EventSource.Raise(Event.Error, method, "Unexpected exception.", e); #endregion throw; } }