Exemplo n.º 1
0
    def post(self):
        """
                """

        __eatery_id = self.get_argument("__eatery_id", None)
        eatery_name = self.get_argument("eatery_name", None)
        if __eatery_id:
            result = r_eateries.find_one({"__eatery_id": __eatery_id})
        else:
            result = r_eateries.find_one({"eatery_name": eatery_name})
            __eatery_id = result.get("__eatery_id")

        if not result:
            """
                        If the eatery name couldnt found in the mongodb for the popular matches
                        Then we are going to check for demarau levenshetin algorithm for string similarity
                        """

            self.write({
                "success":
                False,
                "error":
                True,
                "result":
                "Somehow eatery with this eatery is not present in the DB"
            })
            self.finish()
            return

        __result = process_result(result)
        __result.update({"images": result["pictures"][0:2]})
        self.write({"success": True, "error": False, "result": __result})
        self.finish()

        return
Exemplo n.º 2
0
    def fetch_nps_frm_eatery(self, category, sub_category=None):
        if category == "food":
            if not sub_category:
                raise StandardError(
                    "Food Category shall be provided to fecth nps")
            return r_eateries.find_one({
                "eatery_id": self.eatery_id
            }).get(category).get(sub_category)

        return r_eateries.find_one({"eatery_id": self.eatery_id}).get(category)
Exemplo n.º 3
0
 def processed_reviews(self):
     return r_eateries.find_one({
         "eatery_id": self.eatery_id
     }, {
         "_id": False,
         "processed_reviews": True
     }).get("processed_reviews")
Exemplo n.º 4
0
    def places_mentioned_for_eatery(self):
        result = r_eateries.find_one({
            "eatery_id": self.eatery_id
        }, {
            "places": True
        }).get("places")

        if result:
            return [place_name for place_name in result if place_name]

        return []
Exemplo n.º 5
0
 def processed_clusters(self):
     """
             This returns all the noun phrases that already have been processed for
             teh eatery id 
             """
     return r_eateries.find_one({
         "eatery_id": self.eatery_id
     }, {
         "_id": False,
         noun_phrases: True
     }).get("noun_phrases")
Exemplo n.º 6
0
 def old_considered_ids(self):
     """
             Returns review_ids whose noun_phrases has already been taken into account, 
             which means Clusteirng algorithms has already been done on the noun phrases 
             of these review ids and is stored under noun_phrases key of eatery
             nd these review ids has been stored under old_considered_ids
             """
     try:
         old_considered_ids = r_eateries.find_one(
             {
                 "eatery_id": self.eatery_id
             }, {
                 "_id": False,
                 "old_considered_ids": True
             }).get("old_considered_ids")
     except Exception as e:
         print e
         old_considered_ids = None
     return old_considered_ids
Exemplo n.º 7
0
    def post(self):
        """
                This api will be called when a user selects or enter a query in search box
                """
        text = self.get_argument("text")
        __type = self.get_argument("type")

        if __type == "dish":
            """
                        It might be a possibility that the user enetered the dish which wasnt in autocomplete
                        then we have to search exact dish name of seach on Laveneshtein algo
                        """
            ##search in ES for dish name

            result = list()
            __result = ElasticSearchScripts.get_dish_match(text)
            for dish in __result:
                eatery_id = dish.get("eatery_id")
                __eatery_details = r_clip_eatery.find_one(
                    {"eatery_id": eatery_id})
                for e in [
                        "eatery_highlights", "eatery_cuisine",
                        "eatery_trending", "eatery_known_for", "eatery_type",
                        "_id"
                ]:
                    try:
                        __eatery_details.pop(e)
                    except Exception as e:
                        print e
                        pass
                dish.update({"eatery_details": __eatery_details})
                result.append(dish)

        elif __type == "cuisine":
            ##gives out the restarant for cuisine name
            print "searching for cuisine"
            result = list()
            __result = ElasticSearchScripts.eatery_on_cuisines(text)
            print __result
            for eatery in __result:
                __result= short_eatery_result_collection.find_one({"__eatery_id": eatery.get("__eatery_id")}, {"_id": False, "food": True, "ambience": True, \
                        "cost":True, "service": True, "menu": True, "overall": True, "location": True, "eatery_address": True, "eatery_name": True, "__eatery_id": True})

                eatery.update({"eatery_details": __result})
                result.append(eatery)

        elif __type == "eatery":

            ##TODO : Some issue with the restaurant chains for example
            ##big chills at different locations, DOnt know why ES
            ##not returning multiple results
            ##TODO: dont know why dropped nps are still in result.
            result = r_eateries.find_one({"eatery_name": text}, {
                "_id": False,
                "eatery_known_for": False,
                "droppped_nps": False,
                "eatery_trending": False,
                "eatery_highlights": False
            })

            print result.get("eatery_id")
            __result = process_result(result)

            pictures = result.pop("pictures")
            result.update({"pictures": pictures[0:2]})

            result.update(__result)
            result = [result]

        elif not __type:
            print "No type defined"

        else:
            print __type
            self.write({
                "success": False,
                "error": True,
                "messege": "Maaf kijiyega, Yeh na ho paayega",
            })
            self.finish()
            return
        print result
        self.write({
            "success": True,
            "error": False,
            "result": result,
        })
        self.finish()
        return