public List <string> GetSuggesstionWord([FromQuery] string p) { var result = new List <string>(); if (skillService.GetSuggesstion_Skill(p).Count() != 0) { result = skillService.GetSuggesstion_Skill(p); } else { result = levenshteinService.calcDictDistance(p, 1); } return(result); // return levenshteinService.calcDictDistance(p, 1); }
public IActionResult SearchJobByKeyWord([FromQuery] string searchKey, int pageIndex = 0, int skipRelatedRecords = 0, int skipNormalizeRecords = 0) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int totalJobFound = 0; List <string> parseSearchKey = jobService.ParseSearchey(searchKey).Distinct().ToList(); List <JobSearchResult> jobWithoutDictionary = new List <JobSearchResult>(); List <JobGroupBySkill> jobWithoutDictionaryGroup = new List <JobGroupBySkill>(); foreach (string key in parseSearchKey) { string jobWithoutDictionaryCacheKey = $"{key}_jobWithoutDictionary"; List <JobSearchResult> cacheResponse = cacheService.GetJobResultCache(jobWithoutDictionaryCacheKey); if (cacheResponse.Count() > 0) { jobWithoutDictionary.AddRange(cacheResponse); } else { List <JobSearchResult> temp = jobService.KetQuaTimKiem(key); if (temp != null) { jobWithoutDictionary.AddRange(temp); cacheService.SetJobResultCache(jobWithoutDictionaryCacheKey, temp); } } } jobWithoutDictionaryGroup.AddRange(jobService.GroupJobBySkill(jobWithoutDictionary)); int skipRecords = pageIndex * JobService.PAGE_SIZE; jobWithoutDictionaryGroup = jobWithoutDictionaryGroup.Skip(skipRecords).Take(JobService.PAGE_SIZE).ToList(); if (jobWithoutDictionaryGroup.Count() >= JobService.PAGE_SIZE) { var results = new { success = true, data = new { Data = new { jobsSearchResult = jobWithoutDictionaryGroup, jobsInRelatedSkill = new List <JobSearchResult>(), jobsAfterNormalize = new List <JobSearchResult>(), }, PageIndex = pageIndex, skipRelatedRecords = skipRelatedRecords, skipNormalizeRecords = skipNormalizeRecords, TotalRecord = JobService.PAGE_SIZE } }; return(Ok(results)); } List <JobSearchResult> jobsOfRelatedSkill = new List <JobSearchResult>(); List <JobGroupBySkill> jobsOfRelatedSkillGroup = new List <JobGroupBySkill>(); foreach (string key in parseSearchKey) { if (jobService.CheckSkill(key)) { string jobsOfRelatedSkillCacheKey = $"{key}_jobsOfRelatedSkill"; List <JobSearchResult> cacheResponse = cacheService.GetJobResultCache(jobsOfRelatedSkillCacheKey); if (cacheResponse.Count() > 0) { jobsOfRelatedSkill.AddRange(cacheResponse); } else { List <JobSearchResult> temp = jobService.FindJobsOfRelatedSkill(key); if (temp != null) { jobsOfRelatedSkill.AddRange(temp); cacheService.SetJobResultCache(jobsOfRelatedSkillCacheKey, temp); } } } } jobsOfRelatedSkillGroup.AddRange(jobService.GroupJobBySkill(jobsOfRelatedSkill)); jobsOfRelatedSkillGroup = jobsOfRelatedSkillGroup.Skip(skipRelatedRecords).Take(JobService.PAGE_SIZE - jobWithoutDictionaryGroup.Count()).ToList(); if (jobsOfRelatedSkillGroup.Count() >= JobService.PAGE_SIZE) { var results = new { success = true, data = new { Data = new { jobsSearchResult = jobWithoutDictionaryGroup, jobsInRelatedSkill = jobsOfRelatedSkillGroup, jobsAfterNormalize = new List <JobSearchResult>(), }, PageIndex = pageIndex, skipRelatedRecords = skipRelatedRecords + jobsOfRelatedSkillGroup.Count(), skipNormalizeRecords = skipNormalizeRecords, TotalRecord = JobService.PAGE_SIZE } }; return(Ok(results)); } totalJobFound = jobWithoutDictionaryGroup.Count() + jobsOfRelatedSkillGroup.Count(); List <JobSearchResult> jobsAfterNormalize = new List <JobSearchResult>(); List <JobGroupBySkill> jobsAfterNormalizeGroup = new List <JobGroupBySkill>(); foreach (string key in parseSearchKey) { string mayCorrectSkill = levenshteinService.calcDictDistance(key, 1)[0]; if (StringUtils.RemoveVietnameseUnicode(mayCorrectSkill) == StringUtils.RemoveVietnameseUnicode(key)) { continue; } string jobsAfterNormalizeCacheKey = $"{key}_jobsAfterNormalize"; List <JobSearchResult> cacheResponse = cacheService.GetJobResultCache(jobsAfterNormalizeCacheKey); if (cacheResponse.Count() > 0) { jobsAfterNormalize.AddRange(cacheResponse); } else { List <JobSearchResult> temp = jobService.KetQuaTimKiem(mayCorrectSkill); if (temp != null) { jobsAfterNormalize.AddRange(temp); cacheService.SetJobResultCache(jobsAfterNormalizeCacheKey, temp); } } string jobsOfRelatedNormalizeSkillCacheKey = $"{key}_jobsOfRelatedNormalizeSkill"; cacheResponse = cacheService.GetJobResultCache(jobsOfRelatedNormalizeSkillCacheKey); if (cacheResponse.Count() > 0) { jobsAfterNormalize.AddRange(cacheResponse); } else { List <JobSearchResult> jobsOfRelatedNormalizeSkill = jobService.FindJobsOfRelatedSkill(mayCorrectSkill); if (jobsOfRelatedNormalizeSkill != null) { jobsAfterNormalize.AddRange(jobsOfRelatedNormalizeSkill); cacheService.SetJobResultCache(jobsOfRelatedNormalizeSkillCacheKey, jobsOfRelatedNormalizeSkill); } } } jobsAfterNormalizeGroup.AddRange(jobService.GroupJobBySkill(jobsAfterNormalize)); jobsAfterNormalizeGroup = jobsAfterNormalizeGroup.Skip(skipNormalizeRecords).Take(JobService.PAGE_SIZE - totalJobFound).ToList(); totalJobFound += jobsAfterNormalizeGroup.Count(); return(Ok(new { success = true, data = new { Data = new { jobsSearchResult = jobWithoutDictionaryGroup, jobsInRelatedSkill = jobsOfRelatedSkillGroup, jobsAfterNormalize = jobsAfterNormalizeGroup, }, PageIndex = pageIndex, skipRelatedRecords = skipRelatedRecords + jobsOfRelatedSkillGroup.Count(), skipNormalizeRecords = skipNormalizeRecords + jobsAfterNormalizeGroup.Count(), TotalRecord = totalJobFound } })); } catch (NullReferenceException e) { return(NotFound(new { success = false, error = e.Message })); } }