def search_for_microblogging(search_string): microblogging_query = get_search_query(search_string, ['text_cache', ]) found_posts = Post.objects.filter(microblogging_query).order_by("-id") return convert_to_response_list(found_posts)
def search_for_microblogging(search_string): microblogging_query = get_search_query(search_string, [ 'text_cache', ]) found_posts = Post.objects.filter(microblogging_query).order_by("-id") return convert_to_response_list(found_posts)
def search(request, search_fields, search_string): things_to_search_for = set(search_fields.split("_")) user_results = [] if "user" in things_to_search_for: exact_username_matches = User.objects.filter(username__iexact=search_string.strip()) for user in exact_username_matches: user_results.append( {"url": "user/" + user.username, "title": user.username, "snippet": "Profil von " + user.username} ) user_query = get_search_query(search_string, ["first_name", "last_name"]) found_users = User.objects.filter(user_query) for user in found_users: user_results.append( {"url": "user/" + user.username, "title": user.username, "snippet": "Profil von " + user.username} ) user_query = get_search_query(search_string, ["description"]) found_profiles = UserProfile.objects.filter(user_query) for profile in found_profiles: user_results.append( { "url": "user/" + profile.user.username, "title": profile.user.username, "snippet": profile.description[: min(len(profile.description), 140)], } ) content_results = [] if "content" in things_to_search_for: node_query = get_search_query(search_string, ["title"]) found_titles = backend.Node.objects.filter(node_query).exclude(node_type=backend.Node.SLOT).order_by("-id") for node in found_titles: content_results.append( { "url": node.get_a_path(), "title": node.title, "snippet": node.text.text[: min(len(node.text.text), 140)], } ) text_query = get_search_query(search_string, ["text"]) found_texts = backend.Text.objects.filter(text_query).order_by("-id") for text_node in found_texts: content_results.append( { "url": text_node.node.get_a_path(), "title": text_node.node.title, "snippet": text_node.text[: min(len(text_node.text), 140)], } ) microblogging_results = [] if "microblogging" in things_to_search_for: microblogging_results = search_for_microblogging(search_string) return json_response( { "searchResponse": { "userResults": user_results, "contentResults": content_results, "microbloggingResults": microblogging_results, } } )
def search(request, search_fields, search_string): things_to_search_for = set(search_fields.split('_')) user_results = [] if 'user' in things_to_search_for: exact_username_matches = User.objects.filter( username__iexact=search_string.strip()) for user in exact_username_matches: user_results.append({ "url": "user/" + user.username, "title": user.username, "snippet": "Profil von " + user.username }) user_query = get_search_query(search_string, ['first_name', 'last_name']) found_users = User.objects.filter(user_query) for user in found_users: user_results.append({ "url": "user/" + user.username, "title": user.username, "snippet": "Profil von " + user.username }) user_query = get_search_query(search_string, [ 'description', ]) found_profiles = UserProfile.objects.filter(user_query) for profile in found_profiles: user_results.append({ "url": "user/" + profile.user.username, "title": profile.user.username, "snippet": profile.description[:min(len(profile.description), 140)] }) content_results = [] if 'content' in things_to_search_for: node_query = get_search_query(search_string, [ 'title', ]) found_titles = backend.Node.objects.filter(node_query).exclude( node_type=backend.Node.SLOT).order_by("-id") for node in found_titles: content_results.append({ "url": node.get_a_path(), "title": node.title, "snippet": node.text.text[:min(len(node.text.text), 140)] }) text_query = get_search_query(search_string, [ 'text', ]) found_texts = backend.Text.objects.filter(text_query).order_by("-id") for text_node in found_texts: content_results.append({ "url": text_node.node.get_a_path(), "title": text_node.node.title, "snippet": text_node.text[:min(len(text_node.text), 140)] }) microblogging_results = [] if 'microblogging' in things_to_search_for: microblogging_results = search_for_microblogging(search_string) return json_response({ 'searchResponse': { 'userResults': user_results, 'contentResults': content_results, 'microbloggingResults': microblogging_results } })