Reputation: 31
I am building out a site search using the google custom json/rest api, but I am not sure how to get the 'facet/ refinement labels' to filter down the results.
They are being returned in the json, but I haven't seen anything in the documentation that explains how to filter with it.
Upvotes: 3
Views: 436
Reputation: 907
After you have added refinement labels to your custom search, you have to add the facet name into your search query to "activate" the filter. Your facet name will be named the same as you named your refinement label. If you named your refinement label "race bicycles", you need to add more:race_bicycles
to your query. You can also find your facet name in the response meta data of your request in label_with_op
. Just copy and past your label_with_op
in your query.
For using the api in python, the request looks something like this:
params = {
"q" : "bicycles more:race_bicycles",
"cx": cx,
"key": key,
}
page = requests.request("GET", url = "https://www.googleapis.com/customsearch/v1" , params=params)
results = json.loads(page.text)
Upvotes: 2
Reputation: 305
To filter with facet, value of q parameter should be like this:
text_to_search more:facet_name
Upvotes: 3