Categories > TinyButStrong general >

search

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Deependra
Date: 2006-03-06
Time: 11:04

search

i tried to use google search api, but did not work in the template - it works in my plane site. is there any search function that can be added?

DT
By: Deependra
Date: 2006-03-22
Time: 10:28

Re: search

I am in need of some search function on my site that i am shifting from static sites to TBS template based site.

Hints and ideas are welcome.

DT
By: RwD
Date: 2006-03-22
Time: 10:35

Re: search

So basically you need to search database data and then return results?

I built a system for my site myself, and I am afraid that is what you need to do as well (depending on the google search api) I take it the google search api searches all static pages on your server rather then the processed ones? Because if it works like google itself does then the api should just work...

In any case, you should look at the sql command "LIKE" that enables you to find partial matches, then just query the correct tables and fields and then filter the results and give them some ranking. It is not hard to build!!
By: RwD
Date: 2006-03-22
Time: 10:36

Re: search

But this has little to do with tbs actually...
By: Skrol29
Date: 2006-03-23
Time: 01:12

Re: search

Sorry, I don't know Google Search functions.
By: Deependra
Date: 2006-04-04
Time: 12:22

Re: search

hello,

can a script like the following be used in TBS?

DT

<?php

        error_reporting(E_ALL & ~E_NOTICE);
        // Free script to search your site
        // Copyright 2004, Digital Point Solutions
        // version 1.2 - August 2, 2004
        //
        // Feel free to format the results however you see fit, the only thing we ask is that you leave a link to us in case others would like to add it to their site.
        // Links will be checked, and removal of the link could result it your website being blocked from using the service.
        // Other than that, have fun!  :)   - Shawn

        // Set your parameters here
        $key = "20h/DudQFHLOV6QKqSgiCvaMvFvQDOSM";                        // This is your Google API key, if you don't have one, get one for free at:
                                                                        // https://www.google.com/accounts/NewAccount?continue=http://api.google.com/createkey&followup=http://api.google.com/createkey

        $site = "bees4livelihood.icimod.org/new";                // This is the site you wish to search within
                                                                        // If Google has you indexed without "www.", don't specify "www." within your site URL.
                                                                        // 'http://' is *not* required in the site variable.
                                                                        // Examples:
                                                                        // www.cnn.com                        search within www.cnn.com
                                                                        // www.cnn.com/tech/        search within www.cnn.com/tech/
                                                                        //
                                                                        // You can also leave it blank to search the entire web

        $spelling = 1;                                        // Change this to 0 if you do not want to check for spelling suggestions
                                                                        // Using this option makes searches twice as long, because it requires 2 queries instead of 1

        // Colors
        $color_border = "#ffffff";
        $color_title = "#ffffff";
        $color_odd_results = "#DDDDDD";
        $color_even_results = "#EEEEEE";


        $q = stripslashes ($HTTP_GET_VARS['q']);
        $start = 0 + $HTTP_GET_VARS['start'];

        include ("header.php"); // Edit this file to make it easy to fit into your site's look and feel

        ini_set ("allow_url_fopen", "1");
        if (!ini_get ("allow_url_fopen")) echo '<FONT COLOR=RED><B>Sorry, this PHP configuration does not allow for usage of <A HREF="http://www.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen" TARGET="_blank">fopen()</A>, which is required for this search engine script.</B></FONT><P>';

        // Let's get the results
        $handle = @fopen ("http://search.digitalpoint.com/?q=" . urlencode ($q) . "&key=" . urlencode ($key) . "&site=" . urlencode ($site) . "&start=" . min (990, $start) . "&spell=" . $spelling, "r");
        while (!feof ($handle) && $handle) {
                $line .= fgets ($handle, 1024);
        }
        fclose($handle);

        eval ('$urls = ' . $line . ';');

        echo '<TABLE BGCOLOR=' . $color_border . ' CELLSPACING=1 CELLPADDING=0><TR><TD><TABLE BGCOLOR=' . $color_odd_results . ' border=0 CELLSPACING=0 CELLPADDING=6><TR BGCOLOR=' . $color_title . '><TH COLSPAN=3>';
        echo '<TABLE border=0 WIDTH=100%><TR><TH ALIGN=left>';

        echo '&nbsp;&nbsp;';

        if ($urls['end'] - $urls['start'] < 9) $urls['results'] = $urls['end'];

        if ($urls['results'] > 10) {

                if ($start < 40) {
                        $x = 0;
                } else {
                        $x = round (max (0, min ($start - 40, $urls['results'] - 96) / 10));
                }
                for ($i = $x; $i < $x + 10; $i++) {
                        if ($i != round ($start / 10)) {
                                echo '<A HREF="search.php?q=' . urlencode($q) . '&start=' . ($i * 10) . '">' .  ($i + 1) . "</A>&nbsp;&nbsp;";
                        } else {
                                echo ($i + 1) . "&nbsp;&nbsp;";
                        }
                        if (max (10, ($i + 1) * 10) >= $urls['results']) break;
                }

                //echo '<BR>';
        }

        echo '<font size=-1>Estimated Total Results:  ' . number_format ($urls['results']) . '</font>';
        if ($urls['spelling']) echo '<br><font color="red">Did you mean: <a href="search.php?q=' . urlencode($urls['spelling']) . '">' . $urls['spelling'] . '</a></font>';

        echo '</TH><TH WIDTH=80>&nbsp;</TH></TR></TABLE>';

        $rownum = 1;

        $start = $urls['start'];
        if ($urls['error']) {
                echo "<TR COLSPAN=3><TD><BR><FONT SIZE=-1 COLOR=RED>" . $urls['error'] . "</FONT></TD></TR>";
        } else {

                foreach ($urls['urls'] as $key => $url) {
                        $rownum++;
                        echo "<TR";
                        if ($rownum % 2 == 1) echo ' BGCOLOR=' . $color_even_results;
                        echo "><TH ALIGN=RIGHT WIDTH=35>#" . ($key + $start) . ":&nbsp;</TH><TD><A HREF=\"$url\">" . $urls['titles'][$key] . "</A><BR>" . $urls['snippet'][$key] . "<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=$url>$url</a></FONT></TD><TD>&nbsp;&nbsp;&nbsp;</TD></TR>";
                }
        }
        echo '</TABLE></TD></TR></TABLE>';

?>