Exemple #1
0
        private void FindSimilarJobs(IJobsDataProvider jobsProvider, JobAdvertViewModel model)
        {
            // Get the job title from the URL and use it as keywords to search for jobs that might be similar
            var urlPath   = Request.Url.AbsolutePath.TrimEnd('/');
            var lastSlash = urlPath.LastIndexOf('/');

            if (lastSlash > -1)
            {
                urlPath = urlPath.Substring(lastSlash + 1);
            }

            var jobs = Task.Run(async() => await jobsProvider.ReadJobs(new JobSearchQuery()
            {
                KeywordsInTitle = urlPath.Replace("-", " ")
            })).Result;

            foreach (var job in jobs)
            {
                if (model.SimilarJobs.Count >= 10)
                {
                    break;
                }
                model.SimilarJobs.Add(job);
            }
        }
        private async Task LookupJobsForAlert(IJobsDataProvider jobsData, JobAlert alert, IList <int> jobsSentForThisAlert)
        {
            alert.Query.ClosingDateFrom = DateTime.Today;
            _log.Info($"Requesting {alert.Query.ToString()}");
            var jobs = await jobsData.ReadJobs(alert.Query);

            foreach (var job in jobs.Jobs)
            {
                if (!jobsSentForThisAlert.Contains(job.Id))
                {
                    alert.MatchingJobs.Add(job);
                }
            }
        }
        private static async Task <SimpleDataSet> CreateDataSetFromLookup(int fakeNodeId, string indexType, string group, JobSearchQuery query, JobsLookupValue lookupValue, IJobsDataProvider jobsDataProvider)
        {
            var simpleDataSet = new SimpleDataSet {
                NodeDefinition = new IndexedNode(), RowData = new Dictionary <string, string>()
            };

            simpleDataSet.NodeDefinition.NodeId = fakeNodeId;
            simpleDataSet.NodeDefinition.Type   = indexType;
            simpleDataSet.RowData.Add("id", lookupValue.Id);
            simpleDataSet.RowData.Add("group", group);
            simpleDataSet.RowData.Add("text", lookupValue.Text);

            if (jobsDataProvider != null)
            {
                var jobs = await jobsDataProvider.ReadJobs(query);

                simpleDataSet.RowData.Add("count", jobs.Count.ToString(CultureInfo.CurrentCulture));
            }
            return(simpleDataSet);
        }
        private static async Task <IEnumerable <SimpleDataSet> > CreateDataSetFromLookupValues(string indexType, string groupKey, int fakeNodeId, IList <JobsLookupValue> lookupValues, Action <JobsLookupValue, JobSearchQuery> addLookupToQuery, IJobsDataProvider jobsDataProvider)
        {
            var dataSets = new List <SimpleDataSet>();

            if (lookupValues != null)
            {
                foreach (var lookupValue in lookupValues)
                {
                    JobSearchQuery query = null;
                    if (addLookupToQuery != null)
                    {
                        query = new JobSearchQuery();
                        addLookupToQuery(lookupValue, query);
                        query.ClosingDateFrom = DateTime.Today;
                    }

                    var simpleDataSet = new SimpleDataSet {
                        NodeDefinition = new IndexedNode(), RowData = new Dictionary <string, string>()
                    };

                    simpleDataSet.NodeDefinition.NodeId = fakeNodeId;
                    simpleDataSet.NodeDefinition.Type   = indexType;
                    simpleDataSet.RowData.Add("id", lookupValue.LookupValueId);
                    simpleDataSet.RowData.Add("group", groupKey);
                    simpleDataSet.RowData.Add("text", lookupValue.Text);

                    if (jobsDataProvider != null)
                    {
                        var jobs = await jobsDataProvider.ReadJobs(query).ConfigureAwait(false);

                        simpleDataSet.RowData.Add("count", jobs.TotalJobs.ToString(CultureInfo.CurrentCulture));
                    }

                    dataSets.Add(simpleDataSet);

                    fakeNodeId++;
                }
            }
            return(dataSets);
        }
Exemple #5
0
        public IEnumerable <SimpleDataSet> GetAllData(string indexType)
        {
            //Ensure that an Umbraco context is available
            if (UmbracoContext.Current == null)
            {
                var dummyContext =
                    new HttpContextWrapper(
                        new HttpContext(new SimpleWorkerRequest("/", string.Empty, new StringWriter())));
                UmbracoContext.EnsureContext(
                    dummyContext,
                    ApplicationContext.Current,
                    new WebSecurity(dummyContext, ApplicationContext.Current),
                    false);
            }

            var dataSets = new List <SimpleDataSet>();

            try

            {
                var jobs = Task.Run(async() => await _jobsProvider.ReadJobs(new JobSearchQuery())).Result;

                //Looping all the raw models and adding them to the dataset
                var i = 1;
                foreach (var job in jobs)
                {
                    var jobAdvert = Task.Run(async() => await _jobsProvider.ReadJob(job.Id)).Result;
                    jobAdvert.Id = job.Id;
                    if (String.IsNullOrEmpty(jobAdvert.JobTitle))
                    {
                        jobAdvert.JobTitle = job.JobTitle;
                    }
                    if (String.IsNullOrEmpty(jobAdvert.Location))
                    {
                        jobAdvert.Location = job.Location;
                    }

                    jobAdvert.Salary.SearchRange = job.Salary.SearchRange;
                    if (String.IsNullOrEmpty(jobAdvert.Salary.SalaryRange))
                    {
                        jobAdvert.Salary.SalaryRange = job.Salary.SearchRange;
                    }
                    if (!jobAdvert.Salary.MinimumSalary.HasValue)
                    {
                        jobAdvert.Salary.MinimumSalary = job.Salary.MinimumSalary;
                    }
                    if (!jobAdvert.Salary.MaximumSalary.HasValue)
                    {
                        jobAdvert.Salary.MaximumSalary = job.Salary.MaximumSalary;
                    }

                    if (!jobAdvert.ClosingDate.HasValue)
                    {
                        jobAdvert.ClosingDate = job.ClosingDate;
                    }

                    var simpleDataSet = CreateIndexItemFromJob(i, jobAdvert, indexType);
                    dataSets.Add(simpleDataSet);
                    i++;
                }
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                LogHelper.Error <BaseJobsIndexer>("Error indexing:", ex);
            }

            LogHelper.Info <BaseJobsIndexer>($"{dataSets.Count} items built for indexing by {this.GetType().ToString()}");

            return(dataSets);
        }