Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Category Search in Yelp is not Filtering properly in nodejs. I have given category as "Restaurants" but my o/p is : parks and Playgrounds

Tags:

node.js

yelp

I have been trying to implement the business search in yelp fusion. But I couldn't get the results, I have given the category in order to get filtered code:

            function yelpSearchReuslt(latitude,longitude,radius,listOfResult){
                const searchRequest = {
                    categories:"Restaurants",
                    latitude:latitude,
                    longitude:longitude,
                    radius:radius
                };
                const client = yelp.client(API_KEY);
                client.search(searchRequest).then(response => {
                    const firstResult = response.jsonBody.businesses;
                 })

In the o/p I am getting categories like Playground and parks o/p:

{
            "id": "U2lT4qo4R80vsYKUFaBoCA",
            "alias": "lost-hills-wonderful-park-lost-hills",
            "name": "Lost Hills Wonderful Park",
            "image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/t5y8zHqDfx5mN2v7wtvUxw/o.jpg",
            "is_closed": false,
            "url": "https://www.yelp.com/biz/lost-hills-wonderful-park-lost-hills?adjust_creative=KOlGv8v3EO9ZpCUlYru9eg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=KOlGv8v3EO9ZpCUlYru9eg",
            "review_count": 10,
            "categories": [
                {
                    "alias": "playgrounds",
                    "title": "Playgrounds"
                },
                {
                    "alias": "parks",
                    "title": "Parks"
                }
            ],
            "rating": 4.5,
            "coordinates": {
                "latitude": 35.6164124330499,
                "longitude": -119.689275188145
            },
            "transactions": [],
            "location": {
                "address1": "14688 Lost Hills Rd",
                "address2": "",
                "address3": "",
                "city": "Lost Hills",
                "zip_code": "93249",
                "country": "US",
                "state": "CA",
                "display_address": [
                    "14688 Lost Hills Rd",
                    "Lost Hills, CA 93249"
                ]
            },
            "phone": "+16614482149",
            "display_phone": "(661) 448-2149",
            "distance": 13784.418058437912
        }
like image 716
RAHUL SRV Avatar asked May 26 '18 10:05

RAHUL SRV


3 Answers

It looks like you've almost got it. You just need to use the identifier for 'categories' rather than the name based upon the documentation for the categories parameter which says:

"The value in parenthesis should be used when specifying a search category input."

In your case use restaurants rather than Restaurants. In your code above change the definition for searchRequest to:

const searchRequest = {
         categories:"restaurants",
         latitude:latitude,
         longitude:longitude,
         radius:radius
      };

Hope that helps!

-Darrin

like image 146
darrin Avatar answered Nov 19 '22 14:11

darrin


function yelpSearchReuslt(latitude,longitude,radius,ResultCount){   
                   var request = require("request");
                  var options =
                   {
                    method: 'GET',
                    url: YELP_URL+latitude+"&longitude="+longitude+"&term="+"Restaurants"+"&limit="+ResultCount+"",
                    headers:
                           {
                           authorization:API_KEY
                           },
                    body: '{}'
                   };
                   request(options, function (error, response, body){
                      if (error) {  
                           res.status(400).json({MESSAGE:MESSAGE})
                       }
}
like image 1
RAHUL SRV Avatar answered Nov 19 '22 14:11

RAHUL SRV


You need to change category to term and edit the answer

function yelpSearchReuslt(latitude,longitude,radius,listOfResult){
               const searchRequest = {
                   term:"Restaurants",
                   latitude:latitude,
                   longitude:longitude,
                   radius:radius
               };
               const client = yelp.client(API_KEY);
               client.search(searchRequest).then(response => {
                   const firstResult = response.jsonBody.businesses;
                })
like image 1
Allu Manikyam Avatar answered Nov 19 '22 15:11

Allu Manikyam