Page 1 of 1

Search engine methods...

Posted: Wed Jun 07, 2006 12:16 am
by JellyFish
Hi.

I have my own search engine for my website that's currently in progress. I'm using a method of keywords in the database separated by commas. My script doesn't really get the job done, if you know what I mean?

My script:

Code: Select all

$_GET['search'] = trim($_GET['search']);

	$search = explode(",", $keywords);
	$usrsearch = explode(" ", $_GET['search']);
	$l = 0;
	$usrloop = 0;
	$usrseachfull = "";
	while ($search[$l] != "") {
		$search[$l] = trim($search[$l]);

		while ($usrsearch[$usrloop] != "") {
			$usrseachfull .= $usrsearch[$usrloop]." ";
			if ($usrsearch[$usrloop+1] == "") {
				$usrseachfull = trim($usrseachfull);
			}
			if ((strtoupper($usrsearch[$usrloop]) == strtoupper($search[$l])) || (strtoupper($usrseachfull) == strtoupper($search[$l]))) {
				//create the two blocks to display the eyecons and one to display the popups in the eyecons ($display_block, $array_block)
				$display_block .= "whatever";
				$i++;
			}
			$usrloop++;
		}
		$l++;
	}
}
I don't really want to get into details about the code but if necessary. Basically I have the variable $_GET[search] that contains the string from the users input in the search field in a previous script. I have the $keywords which contains the string of keywords in the current selected field in the database table.

Basically all I'd need is to know some personal methods that you'd use or a link to a webpage that discuss such. I'm not at all familiar with search engines except the one I made.

Any help or post are appreciated.

Thanks. :D

Posted: Wed Jun 07, 2006 9:29 am
by TheMoose
http://us3.php.net/levenshtein
http://us3.php.net/soundex
http://us3.php.net/similar_text
http://us3.php.net/metaphone

All of these functions are amazing for building a search engine. What I do for a keyword style search engine is to create more of a "relevance" engine. Each time a keyword gets a hit for a specific object, you increment that object's hit counter by 1. The max number of hits an object can get is the number of keywords the user searches for.

If I search for "php,code,script,programming", and my object has the keywords "php,script,programming", it hits 3 out of 4 possible keywords, and for purposes of ease of use, I turn that into 75% relevant.

Posted: Fri Jun 09, 2006 3:41 pm
by JellyFish
Thanks moose, sorry I couldn't get back to this post sooner to say that. :(

Looks good I think I got a picture of how you'd do that. Except I don't know how this code might work, and what I mean is how do you increment an object, I'm not quite familiar with that explanation. :?
In other words what does increment mean in this context?

Posted: Fri Jun 09, 2006 3:47 pm
by TheMoose
It's just a counter of hits. Like the example I gave you, I search for the following:

php
code
script
programming

The object has the keywords:

php
script
programming

Each loop through of the words I searched for is one iteration, and each iteration if the word you searched for is a match, you increment (add 1) the hit counter. Basically like a count++ type thing.

Posted: Fri Jun 09, 2006 4:02 pm
by JellyFish
Oh Okay, I see.

Thanks. :D