In this article we’ll be reviewing Laravel Google Custom Search Engine package it allows you to easily add Google Custom Search within you laravel app . Well, there are not many possibilities if you want to have your own search engine on your site without too much programming. There were service called Swiftpe, where you had free plan – you just enter the URL of your site and you got HTML code to insert in you page – and you had your own fulltext search engine. Now there are only very expensive plans.
you can create Custom Search Engine for Laravel-project and use it in very simple way like
$fulltext = new LaravelGoogleCustomSearchEngine(); // initialize $results = $fulltext->getResults('some phrase'); // get first 10 results for query 'some phrase'
Configuration
Creating your custom search engine
- If you create your engine at https://cse.google.com/cse/ you will find the ID after you click at Settings
- Just check the URL you have like https://cse.google.com/cse/setup/basic?cx=search_engine_id and the string after cx= is your search engine ID
!! Attention !! If you change style of your Custom search engine, the ID can be changed
Get your API key
- go to https://console.developers.google.com, than
- click on the menu on the right side of the GoogleAPI logo and click on ‘Create project’
- enter the name of the new project – it is up to you, you can use ‘Google CSE’
- wait until project is created – the indicator is color circle on the top right corner around the bell icon
- API list is shown – search for ‘Google Custom Search API’ and click on it
- click on ‘Enable’ icone on the right side of Custom Search API headline
- click on the ‘Credentials’ on the left menu under the ‘Library’ section
- click on the ‘Create credentials’ and choose ‘API key’
- your API key is shown, so copy and paste it here
Save the configuration values
Save search engine ID and api ID in your config/laravelGoogleCustomSearchEngine