Skip to main content

How to create a search engine

How to create a search engine

I am going to teach you how we can create a search engine using Google API.
You can add more styles to it ,because I'd be creating a simple looking search engine.
Google Custom Search API are wonderful tools to create some awesome search engine like tools. Also if you want to add a search option to your website and customize the look and feel of your search results, Google Custom Search API serve best to you. I have created a Real Time Search engine (I call it real time as it search as you type). I am really impressed by the speed/response of Google Search API.
In order to use Google Search API, you have to first generate a Key for you. Go to following page and signup your self for the Key. Sign up for Google API Key
https://code.google.com/apis/ajaxsearch/signup.html
Next step is to include the Google Search API javascript. Don’t forget to mention your key in the below code.
<script src="http://www.google.com/jsapi?key=YOURKEY" type="text/javascript"></script> <script type="text/javascript"> 

google.load('search', '1'); </script>
Now We will create a textbox and a button that will take input for search. And a DIV that will be populated by results
<input type="text" title="Real Time Search" name="searchbox"/>

<input type="button" id="searchbtn" value="Search" onclick="search(searchbox.value)"/> 
<div class="data" id="web-content">
</div> 

When user will write a query and push Search button, a request will be made to Google Search using Custom Search API and the results are fetched. These results are then copied into the DIV.
We will use following JavaScript to call the Google Search API and copy the results in our container DIV. The code in plain english is:
1. Create an object to connect Google Web search using class google.search.WebSearch.
2. Set a callback function that will get call once the results for the search are fetched.
3. Call the execute() method with search query as argument.
4. In callback function, iterate through the results and copy it to container DIV.
var webSearch;
webSearch = new 
google.search.WebSearch(); 
webSearch.setSearchCompleteCallback(this, webSearchComplete, [webSearch]); 
function webSearchComplete (searcher, searchNum)
{ 	
 var contentDiv = document.getElementById('web-content'); 
 contentDiv.innerHTML = ''; 
 var results = searcher.results;
 var newResultsDiv = document.createElement('div'); 
 newResultsDiv.id = 'web-content'; 
 for (var i = 0; i < results.length;
 i++)
 {
 var result = results[i]; 
 var resultHTML = '<div>';
 resultHTML += '<a href="' + result.unescapedUrl + '" target="_blank"><b>' + 
 result.titleNoFormatting + '</b></a>br<br/>' + 
 result.content + '<div/>'; 
 newResultsDiv.innerHTML += resultHTML; 
 } 
 
 contentDiv.appendChild(newResultsDiv); } 
 function search(query)
 { 
 
 webSearch.execute(query);
 }
You could see it was really simple,easy and short,however it works perfectly but you notice it has poor styling.You can add it up ,or download the sass styles. created from
Trednix.com/drexisrael

You can even collect cookies from the people using your search engine ,learn How to create session cookies and All you need to know about cookies.How about adding a cool ,nice and dynamic dark mode to it , see it here How to create the best dark mode that works for all the pages in your site and does not turn off when page reloaded

Comments

Popular posts from this blog

Ecommerce single item cart with php checkoit

email otp sms How to create an ecommerce single item cart with checkout integrations Guys today i am going to teach you guys how to build an ecommerce site with checkout integration but only with a single product, you can add more to it So we are building it using my favorite PHP ,Ajax and JQuery. I have already created a simple shopping cart code in PHP with the product gallery.let's get this over with What are we building? I am not meant to show you this but i would to make you exited about it.And look at the cool checkout page and it really works!!. Single product UI with buy now and Checkout controls This is the code of the landing page created for this example. It includes PHP snippets at the beginning. After that, it has the HTML for displaying only one product tile to users. This tile has the “ Buy now ” button. On clicking it will show an HTML form to collect the customer details, name and email address. By submitting the customer details, it calls the

Mobile SMS OTP

mobile otp sms How to build SMS otp for verification in php Today ,i am going to teach you something you cannot find easily on the web,which is sms otp . you can also learn email otp .You see that screenshot above? that's exactly what we are building,cool isn't it ? OTP is an effective way of validating users. This type of validation is widely followed by the banking applications, e-commerce software, and many more verticals. In this tutorial, we are going to see how to implement OTP SMS mobile number verification using PHP,isn't that fun?! There are various APIs available in the market for sending SMS via an application. In this code, I have used the Textlocal API for sending OTP SMS. Textlocal is one of the popular SMS services. It provides the SMS service for many programming languages. Download the API PHP class to integrate it into our application platform. For verifying a mobile number by sending OTP SMS with the use of Textlocal API, we need to create a Textlo

how to create Session cookies in php

What are Session cookies Session cookies , also known as ' temporary cookies ', help websites recognise users and the information provided when they navigate through a website. Session cookies only retain information about a user's activities for as long as they are on the website. Once the web browser is closed, the cookies are deleted. These are commonly used on shopping websites or e-commerce websites.We have already talked about cookies, Learn all about cookies . Cookies are the reason Trednix.com remembers your username between visits and the reason you don’t necessarily need to log in to your Hotmail account every time you open your browser. Cookie data typically contains a short set of information regarding when you last accessed a site, an ID number, and, potentially, information about your visit. Let’s now look at the basic syntax used to create a cookie. <?php setcookie(cookie_name, cookie_value, [expiry_time], [cookie_path], [domain], [secure], [httponl