SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    google or yahoo custom search using php

    hii,
    i want to integrate google or yahoo custom search in my website,
    anyone please give me an idea..
    many regards,

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Why not use the Google Adsense search? Make money and provide searches.

    I don't think there is any way that you can directly tap into their data or anything though. You could possibly run a page with the search then get the page it returns and process it into your own format, but that's a lot of work.

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use Google Site Search, which is a paid (but cheap) service from Google. I believe Yahoo has something similar.

  4. #4
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hii,
    i found code for google custom search which is free.
    heres the code:
    Code:
    <p align="center">search site</p>
    <form action="" id="cse-search-box">
      <div>
        <input type="hidden" name="cx" value="013069836288472481273:yf_kbl-8lly" />
        <input type="hidden" name="cof" value="FORID:10" />
        <input type="hidden" name="ie" value="UTF-8" />
    	<table width="240" cellpadding="3" cellspacing="5" align="center">
       <tr align="center">
        <td>
            <input type="text" name="q" size="31" />
       <br /></td>
    
        <td>
            <select name="as_sitesearch"><option value="pick1" selected="selected"><b>-Select website-</option></b>
                <option value="lycos.com">lycos</option>
    			<option value="google.com">google</option>
    			<option value="yahoo.com">yahoo</option>
                
            </select>
       <br /></td>
    
        <td><input type="submit" name="sa" value="Search" /></td>
    	 <td><input type="reset" name="sa" value="reset" /></td>
      </div>
    </form>
    </tr>
    </table>
    <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>
    
    <div id="cse-search-results"></div>
    <script type="text/javascript">
      var googleSearchIframeName = "cse-search-results";
      var googleSearchFormName = "cse-search-box";
      var googleSearchFrameWidth = 600;
      var googleSearchDomain = "www.google.com";
      var googleSearchPath = "/cse";
    </script>
    <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
    i dont think it is a paid service..
    many regards.

  5. #5
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I could be wrong here but as best I remember the Google CSE offers both a paid service and a free service. I think the paid service is $100 a year. The biggest difference between the paid and the free service is that with the paid you will have the option to parse the XML results yourself. This means that you have far more control over the look and feel of your search results.

    On November 13th Google also announced that paid accounts will have the option of uploading at new sitemap and requesting that Google reindex the website based on the new sitemap within 24 hours. A pretty cool feature if you ask me.
    http://googlewebmastercentral.blogsp...om-search.html
    TAKE A WALK OUTSIDE YOUR MIND.

  6. #6
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hyperbolik
    many thanks for your information.
    till now i knew nothing about these custom searches,
    many thanks again, this mite b a good tutorial for the beginners.

    regards,

  7. #7
    Non-Member adstiger's Avatar
    Join Date
    Nov 2008
    Location
    Canada
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so which one you implemented?

  8. #8
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so which one you implemented?
    i've to discuss about the paid implementation with my client
    so now, i gotta go wid google custom search(free service)

  9. #9
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pavanpuligandla View Post
    i've to discuss about the paid implementation with my client
    so now, i gotta go wid google custom search(free service)
    Good choice.

    Has anyone tried the Yahoo site search?
    TAKE A WALK OUTSIDE YOUR MIND.

  10. #10
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Has anyone tried the Yahoo site search?
    yeah, i've been trying for yahoo custom search also.
    i'll surely let you knoe if my trials succeed..
    regards,
    pavan.
    "Microsoft has no beef with OpenSource"

  11. #11
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @ hyperbolik,

    hiiya,
    got yahoo custom search..
    u can 've a glance at it..
    http://developer.yahoo.com/search/boss/boss_guide/
    PHP Professional turned ASP.NET Professional

  12. #12
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pavanpuligandla View Post
    @ hyperbolik,

    hiiya,
    got yahoo custom search..
    u can 've a glance at it..
    http://developer.yahoo.com/search/boss/boss_guide/
    Maybe I'm just missing something but that looks like the Yahoo developer guide. Do you have a website that uses the Yahoo custom search?
    TAKE A WALK OUTSIDE YOUR MIND.

  13. #13
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think this info will be helpful..
    and this blog is powered by YAHOO! search..
    http://www.ysearchblog.com/archives/000339.html
    PHP Professional turned ASP.NET Professional

  14. #14
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heres the source code for yahoo custom search powered by BOSS.
    i think Yahoo search yeild better results than Google.
    Code:
    <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <-- 
    Created by Marco Vitanza
    http://marcovitanza.com
    
    This code is hereby released into the public domain.
    Feel free to copy, modify, and reuse it in any way.
    -->
    <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
    <title>Custom Search with Yahoo BOSS</title>
    <style type="text/css">
    /* SIMPLE STYLING FOR SEARCH RESULTS */
    body { font-family:arial; font-size:12px; }
    div.result { margin-bottom:15px; background-color:#efefef; padding:10px; }
    div.result a { font-size:18px; font-weight:bold; }
    div.result div { float:left; font-size:30px; font-weight:bold; margin-right:10px; color:#c0c0c0; }
    </style>
    </head>
    <body>
    <h1>Custom Search with Yahoo BOSS</h1>
    <?php
    // Echo the search form
    echo '<form action="" method="get">';
    echo 'Search for <input type="text" name="q" value="';
    
    // Needed if MAGIC_QUOTES is on
    // $_GET['q'] = stripslashes($_GET['q']);
    	
    // Echo the query in the search text field 
    $query = htmlentities($_GET['q'], ENT_QUOTES, 'UTF-8');
    echo $query . '" />   <input type="submit" value="Go" /></form>';
    
    // If there is a query
    if(!empty($_GET['q']))
    {
    	echo '<hr />';
    	
    	// IMPORTANT: FILL IN THESE FIELDS
    	//////////////////////////////////////////////////////////////////////////////////////
    	// Yahoo AppID - get one by registering at http://developer.yahoo.com/search/boss
    	$appid = 'YOUR_YAHOO_APP_ID_HERE';
    	// Comma-separated list of domains to search in
    	$domains = 'yourdomain.com';
    	//////////////////////////////////////////////////////////////////////////////////////
    	
    	// Main part of BOSS query URL - note the "web/" for web pages only
    	$pre = 'http://boss.yahooapis.com/ysearch/web/v1/';
    	// Set the current result page. Specific page may be requested from a Next or Prev link
    	$results_per_page = 10;
    	$page = intval($_GET['page']);
    	if($page < 1)
    		$page = 1;
    	// Partial query paramaters. Format can also be JSON
    	$params = '&format=xml&sites=' . $domains . '&count=' . $results_per_page . '&start=' . (($page - 1) * $results_per_page);
    
    	// Initialize our CURL session with the BOSS query URL
    	$ch = curl_init($pre . urlencode($_GET['q']) . '?appid=' . $appid . $params);
    	// We want the XML data to be returned (not echoed) so we can parse it
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	// Execute the CURL request to retrieve the search results in XML format
    	// By default, there will be a maximum of 10 results in one XML response
    	// You can change this value and the result offset (for page 2, 3...) by adding more query paramaters
    	// See BOSS documentation for more details
    	$xml = curl_exec($ch);
    	curl_close($ch);
    	
    	// variables for storing data from the XML
    	$curtag = $y_link = $y_abstract = $y_title = '';
    	// result counters
    	$i = ($page - 1) * $results_per_page + 1;
    	$totalhits = 0;
    	
    	// XML PARSING FUNCTIONS
    	/////////////////////////////////////////////////////////////////////////////////////////
    	// The parser found a start tag for an element
    	function start_tag($parser, $name, $attribs)
    	{ 
    		global $curtag, $totalhits; 
    		// Save the current tag name so we know where we are
    		$curtag = $name;
    		// Get the total hits from the <resultset_web> tag
    		if($curtag == 'RESULTSET_WEB')
    			$totalhits = intval($attribs['TOTALHITS']);
    	}
    	// The parser found some character data inside an element
    	function tag_data($parser, $data)
    	{
    		global $curtag, $y_link, $y_abstract, $y_title;
    		// If we are inside an <abstract> <title> or <url> tag, save the data for display later
    		// If you want the default keyword highlighting (bold) then don't strip_tags()
    		if($curtag == 'ABSTRACT')
    			$y_abstract = htmlentities(strip_tags($data), ENT_QUOTES, 'UTF-8');
    		elseif($curtag == 'TITLE')
    			$y_title = htmlentities(strip_tags($data), ENT_QUOTES, 'UTF-8');
    		elseif($curtag == 'URL')
    			$y_link = htmlentities(strip_tags($data), ENT_QUOTES, 'UTF-8');
    	}
    	// The parser found an end tag for an element
    	function end_tag($parser, $name)
    	{ 
    		global $curtag, $y_link, $y_abstract, $y_title, $i;
    		// If this is the end of a <result> element
    		if($name == 'RESULT')
    		{
    			// Echo the result listing with URL, title, and abstract
    			echo '<div class="result"><div>' . $i . '</div><a href="' . $y_link . '">' . 
    				$y_title . '</a><br />' . $y_abstract . '</div>';
    			// Reset the temporary data vars
    			$y_link = '';
    			$y_abstract = '';
    			$y_title = '';
    			// Increment result counter
    			$i++;
    		}
    		// Reset the current tag name
    		$curtag = ''; 
    	}
    	/////////////////////////////////////////////////////////////////////////////////////////
    
    	// Create an XML parser
    	$parser = xml_parser_create();
    	// Setup our handler functions so the parser calls them when it finds tags and data
    	xml_set_element_handler($parser, 'start_tag', 'end_tag');
    	xml_set_character_data_handler($parser, 'tag_data');
    	// Parse the search results XML. The results will be printed by the functions above
    	// Remember, $xml is the variable where the XML data was stored from the CURL response
    	xml_parse($parser, $xml);
    	
    	// Write the Prev and Next page links
    	echo '<hr /><div style="float:right; margin-top:15px;">';
    	if($page > 1)
    		echo '<a href="?q=' . $query . '&page=' . ($page - 1) . '">< Prev</a> | ';
    	echo 'Page ' . $page;
    	if($i - 1 < $totalhits)
    		echo ' | <a href="?q=' . $query . '&amp;page=' . ($page + 1) . '">Next ></a>';
    	echo '</div>';
    	
    	// Write the number of results. Note that this may be more than shown on the first page
    	echo '<div style="margin-top:15px;"><i>' . $totalhits . ' Total Result(s)';
    	// Shout out to the BOSS folks
    	echo ' | Powered by <a href="http://developer.yahoo.com/search/boss">Yahoo BOSS</a></i></div>';
    }
    ?>
    </body>
    </html>
    PHP Professional turned ASP.NET Professional


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •