Make google custom search location-aware - api

When I search for "football images" on google.co.uk, it knows that I mean the sport that elsewhere might be called "soccer". If I do the same search on google.com, I get American Football.
I'm using the custom search API - how can I tell it that I'm in the UK and would like results relevant to here?

You can limit your engine to operate on sites from a particular country via "cr" param, e.g. in Custom Element it looks like this:
<gcse:search cr="gb"></gcse:search>
Google knows some synonyms on the web, but if your particular use case is not correctly recognized you can add it in Control Panel in Search Features > Synonyms
More on synonyms:

Sorry, I ended up answering this myself. I couldn't get any of the instructions under the custom search API itself to work (although the answer offered above was also mentioned there, but this just made my CSE Context XML apparently invalid), but you can make requests to a custom search engine by using the instructions here https://developers.google.com/custom-search/json-api/v1/using_rest and an API key.

This is how I did it;
<gcse:search cr="countryUK"></gcse:search>
You can even return results in a specific language, code shown below returns results only in french;
<gcse:search lr = "lang_fr"></gcse:search>
This is the reference for Google Custom Search Element Control API: https://developers.google.com/custom-search/docs/element?hl=en

Try to set the 'gl' parameter to the country you want.
For details, look into CSE:list

Related

Google Custom Search API curl trouble

I'm a newbie at stackoverflow so please be patient with me :)
I'm trying to get access with the Google Custom Search API.
But I get return that I can't understand.
My query is like this:
https://www.googleapis.com/customsearch/v1?&key=********&q=red%2Bsox&cx=**********&start=0&num=10&cr=countryCA&lr=lang_fr&client=google-csbe&output=xml_no_dtd
And the result I get is this?
string '{"error": {"errors": [{"domain": "global","reason": "invalid","message": "Invalid Value"}],"code": 400,"message": "Invalid Value"}}' (length=172)
What am I doing wrong?
I want the result from Google to appear.
Thanks in advance :)
You don't have a cx.
Take a look at this answer
What happens is because this api is used mostly for adding a search option
for your site you have to specify you custom search engine (e.g. search only your site).
When you want this to search the web by code you need to do the above. Add a fake
site (where you would add your search textbox), configure it (search the web, or your site, or whatever else) and then delete the fake site
Update
Oh god, i just saw that. Sorry. Well the problem is that you start with 0. Valid is 1. Change start=0 with start=1 and i think you would be good to go. Take a look at this for valid values for the start parameter official page

Google Custom Search Query Parameters and Category Parameters

So I'm trying to set the query parameters and category parameters for google custom search. Here is an example search results page url:
http://www.whiterootmedia.com/search_results/index.html?q=my%20search%20phrase
So it looks like the default query parameter is q so I put q in the box when setting up the analytics portion for my google custom search engine. Is this ok? I read it wasn't ok to use q but to instead use query? And why does it matter?
Also should I set a category parameter that looks to be optional.
Thanks,
Dusty
The Google Search API just uses q. AFAIK the API doesn't have a query parameter. Check out the custom search API documentation.
Not sure what you mean by the 'category' parameter. Haven't come across that one before.
HTML:
<gcse:search gname='google1'></gcse:search>
Javascript:
window.google.search.cse.element.getElement("google1").execute("hello world");
But you need to wait for the Google script to load before launching the javascript.
If you use searchresults-only instead of search, you also need to enable the correct layout in the CSE Control Pannel: https://www.google.com/cse/
You can hit the following: https://cse.google.com/cse?as_q=your_query_string%20must_be_urlencoded&client=google-csbe&cx=full_cse_id_goes_here:including_the_bit_after_the_colon
So a direct answer to your question - the query parameter key is 'as_q'.

is it possible to specify a region/locale for google custom search engine?

I want to use the Google Custom Search API (or custom search engine directly) in the following manner--
(1) I want to get the set of results for a search term for Google UK(This should return results that are returned by a regular search on Google.co.uk- Google UK)
(2) I want to get the results for a search on Google.co.in(Google India)
Is it possible to do the above, either directly while creating a custom search engine, or through the API?
Yes. It is possible. Specifiy the parameter googlehost in your query. Example: &googlehost=google.de or whatever country you want.
It is in the settings, can change from the Control Panel.

how to correct spelling mistakes in Google custom API

I am using Google's custom search API, I make an HTTP request to a URL that looks like this:
https://www.googleapis.com/customsearch/v1?key=<my-key>&cref=&num=10&q=how+can+i+do+htis
if you search for "how can i do htis" on Google you are told "Showing results for how can i do this", and give you some results (call them result set A)
but if you use the API to search for the misspelled string, you get different results than those of A... Searching with a correctly spelled string gives you result A, which matches the ordinary search service on Google
Is there a way to search directly using the suggested string? I want to use the API I can't afford implementing a spell checker myself that can also correct people names and everything
I think what you want to do is possible using the spelling suggestions of Google. This is part of the xml-results returned by your query.
See API here.

Normal Google Custom Search

I'm writing an application that analyses search engine results.
With the Google Search API now being depreciated and limited to 1000 queries/day they are forcing developers to move to the AJAX APIs and to use the Custom Search API to do a Google search.
The thing is I don't need a Custom Search, I need a general search not one that is filtered by site; OK maybe filtered by USA/UK (Google.com/Google.co.uk).
Does anyone know how to just do a regular Google search using the AJAX APIs? Is the Custom Search the right thing to be using?
I don't want to hit the 1000/day limit using the old service but this is exactly what I need.
I did find: How do I create a CSE that searches the entire web?
http://www.google.com/support/customsearch/bin/answer.py?hl=en&answer=1210656
But by the sounds of it this will distort the search results.
Thank you.
OK. Here's how I think it is done.
Create a Custom Search Engine.
Add a site such as *.com When this is created go to the Advanced tab
and download the context xml.
Remove the Background Label associated with the site.
Upload the XML to replace the previous context.
This seems to work just fine and is returning the same values as far as I can see.
Yes, you are right *in theory, and this should let you get 100 results a day on the fly. Just this Saturday though, Google confirmed how here -
(* so far though, we can't get it working...)