def getMatches(query): username_match_ids = [] name_match_ids = [] # This is required since we are not pushing data to trinity until we have a resume # TODO: Push Name + Social Details as plain text, even if there is no resume. # This is also required for better RELEVANCE if not re.match("((^.*[\s]+(and|not)[\s]+.*$)|(^.*?[\(\)]+.*$))", query, re.IGNORECASE): keyword_list = re.compile("[,\s]+").split(query) username_matches = models.User.objects.filter( account__username=keyword_list[0], account__account_state="A" ).values("id") name_matches = models.User.objects.filter(name__icontains=keyword_list[0], account__account_state="A").values( "id" ) username_match_ids = [dict.values()[0] for dict in username_matches] name_match_ids = [dict.values()[0] for dict in name_matches] # limit name matches to 5 name_match_ids = name_match_ids[:5] # resume-search on TRINITY resume_match_ids = [] query = replaceSpecialKeyWords(query) data = trinity_client.getQueryResults( "resume_search", "filecontents:(" + query + ')<queryParams><sort field="last_access_time" order="DESC" /></queryParams>', ) if data: fts_reply = data.split(",") resume_match_ids = map(lambda s: string.atoi(s), fts_reply) return dataplus.getMergedList(username_match_ids, name_match_ids, resume_match_ids)[:200]
def getMatches(keywords): name_matches = models.Community.objects.filter(name__icontains=keywords).values('id') name_match_ids = [dict.values()[0] for dict in name_matches] desc_match_ids = [] keyword_list = re.compile("[,\s]+").split(keywords) for keyword in keyword_list: desc_matches = models.Community.objects.filter(desc__icontains=keyword).values('id') desc_match_ids += [dict.values()[0] for dict in desc_matches] return dataplus.getMergedList(name_match_ids, desc_match_ids)[:200]