def get_property_of_particular_tag(request_data): if request_data: request_data = json.loads(request_data) if not request_data.get("tag"): raise MandatoryError("Mandatory Field Tag missing") try: exclude_list = ["agent_name", "agent_no", "contact_no", "contact_person", "created_by", "modified_by", "creation_date", "modified_date", "posted_datetime", "modified_datetime"] must_clause_list = [{ "match":{ "tag":request_data.get("tag") } }, { "match":{ "status":"Active" } } ] search_query = { "query":{ "bool":{ "must":must_clause_list } } } es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40),exclude_list) putil.show_amenities_with_yes_status(response_data) msg = "Property found for specfied criteria" if len(response_data) else "Property not found" response_dict = putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records) response_dict["tag"] = request_data.get("tag") return response_dict except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get Tagged Property Operation Failed")
def get_user_properties(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) search_query = { "query": { "match":{ "posted_by":request_data.get("user_id") } } } try: # fields_to_be_excluded from response and resultset generation include_list = ["property_photo", "city", "location", "carpet_area", "amenities", "no_of_floors", "price", "status", "floor_no", "price_per_sq_ft", "property_id", "property_title", "tag", "possession_status", "property_subtype_option"] es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40), [], include_list) response_data = check_for_shortlisted_property(response_data, request_data.get("user_id")) putil.show_amenities_with_yes_status(response_data) # response data & pagination logic msg = "User Property Found" if len(response_data) else "User Property not found" return putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records) except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get User Properties Operation Failed")
def search_unpublished_property(data): property_data = json.loads(data) try: # generate search query & result generation & list of fields which should be excluded. exclude_list = putil.get_exclude_list_for_search(property_data.get("request_source", "")) #must_clause_list.append([{"match":{ "published_status": "Unpublished" } }, { "match": { "status": "Deactivated" }}]) must_clause_list= [{"match":{ "published_status": "Unpublished" } }] search_query = { "query":{ "bool":{ "must":must_clause_list } }, "sort": [{ "posted_datetime": { "order": "desc" }}] } es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, property_data.get("page_number",1), property_data.get("records_per_page",40), exclude_list) if property_data.get("user_id") != "Guest": response_data = check_for_shortlisted_property(response_data,property_data.get("user_id")) response_data = putil.get_date_diff_and_count_from_posting(response_data) putil.convert_area_according_to_uom(response_data, property_data.get("unit_of_area", "Sq.Ft.")) putil.show_amenities_with_yes_status(response_data) # response data & pagination logic msg = "Property found for specfied criteria" if len(response_data) else "Property not found" response_dict = putil.init_pagination_and_response_generatrion(property_data, response_data, msg, total_records) return response_dict except elasticsearch.RequestError,e: raise ElasticInvalidInputFormatError(e.error)
def search_property(data): property_data = json.loads(data) property_data = putil.validate_property_posting_data(property_data, "property_json/property_search.json") putil.init_for_location_or_city_creation(property_data) putil.convert_area_to_sqft_for_search(property_data) try: # generate search query & result generation & list of fields which should be excluded. exclude_list = putil.get_exclude_list_for_search(property_data.get("request_source", "")) search_query = putil.generate_search_query(property_data) adv_search_query = search_query search_query = cstr(search_query) putil.generate_advance_search_query(adv_search_query, property_data) es = ElasticSearchController() response_data, total_records = es.search_document(["property"], adv_search_query, property_data.get("page_number",1), property_data.get("records_per_page",40), exclude_list) # post property-search operation if not property_data.get("request_id"): request_id = store_request_in_elastic_search(property_data, search_query, "Property Search", adv_search_query) if property_data.get("user_id") != "Guest": response_data = check_for_shortlisted_property(response_data,property_data.get("user_id")) response_data = putil.get_date_diff_and_count_from_posting(response_data) putil.convert_area_according_to_uom(response_data, property_data.get("unit_of_area", "Sq.Ft.")) putil.show_amenities_with_yes_status(response_data) # response data & pagination logic msg = "Property found for specfied criteria" if len(response_data) else "Property not found" response_dict = putil.init_pagination_and_response_generatrion(property_data, response_data, msg, total_records) response_dict["request_id"] = property_data.get("request_id") if property_data.get("request_id") else request_id return response_dict except elasticsearch.RequestError,e: raise ElasticInvalidInputFormatError(e.error)
def search_project(request_data): if request_data: project_data = json.loads(request_data) project_data = putil.validate_property_posting_data(project_data,"property_json/project_search.json") putil.init_for_location_or_city_creation(project_data) search_query = putil.generate_project_search_query(project_data) try: project_fields = get_project_include_fields(project_data.get("request_source", "")) exclude_list = putil.get_exclude_list_for_search(project_data.get("request_source", "")) es = ElasticSearchController() response_data, total_records = es.search_document(["project"], search_query, project_data.get("page_number",1), project_data.get("records_per_page",40), exclude_list, project_fields) if not project_data.get("request_id"): request_id = store_request_in_elastic_search(project_data, search_query, "Project Search") response_data = putil.get_date_diff_and_count_from_posting(response_data) putil.show_amenities_with_yes_status(response_data) # property_subtype_option = project_data.get("property_subtype_option","") # get_valid_property_subtype_option(response_data, property_subtype_option) if property_subtype_option else "" response_msg = "Project found for specfied criteria" if len(response_data) else "Project not found" from_record = (project_data.get("page_number",1) - 1) * cint(project_data.get("records_per_page",40)) + 1 no_of_pages = math.ceil(flt(total_records)/project_data.get("records_per_page",40)) to_record = from_record + len(response_data) - 1 if response_data else from_record + project_data.get("records_per_page",40) - 1 return { "operation":"Search", "message":response_msg , "total_records":total_records, "request_id":project_data.get("request_id") if project_data.get("request_id") else request_id, "records_per_page":project_data.get("records_per_page",40), "from_record":from_record , "to_record":to_record, "data":response_data, "user_id":project_data.get("user_id"), "no_of_pages":no_of_pages } except elasticsearch.RequestError,e: raise ElasticInvalidInputFormatError(e.error) except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)