StupidRalph
01-29-2007, 09:38 AM
I have a comma delimited column for keywords in a DB. I was wondering the best way to compare these keywords with user submitted search terms.
I was thinking about putting the user entered text in an array and then comparing that array for each keyword array in the DB.
Other than me having a hard time with accomplishing this...I don't think this is the most efficient way of going about this.
This is what I have for parsing the user input search terms:
$input = basicClean($_GET['input']); //some basic string cleaning
$input = preg_replace('/[^a-z0-9&\s]/i', '', $input); //only allows alphanumeric characters, ampersand (&), and spaces.
$input = trim($input); // trims beginning and trailing space from text.
$input = strtolower($input); //makes the text lowercase
$input = explode(" ",$input); //creates an array delimited by spaces
$input = array_filter($input); //removes emptry strings, null values, and values that equate to false
$input = array_merge(array_flip(array_flip($input))); //removes duplicate entries
I just didn't know what to do beyond this to be able to compare to the keyword array for each row in the DB and rank each.
I'm open to any suggestions whether its a 3rd party class script or totally different approach.
I wanted to add that the keywords are not for actual pages but for business locations. The pages are created dynamically. So I would need to make a reference for each location ID.
I was thinking about putting the user entered text in an array and then comparing that array for each keyword array in the DB.
Other than me having a hard time with accomplishing this...I don't think this is the most efficient way of going about this.
This is what I have for parsing the user input search terms:
$input = basicClean($_GET['input']); //some basic string cleaning
$input = preg_replace('/[^a-z0-9&\s]/i', '', $input); //only allows alphanumeric characters, ampersand (&), and spaces.
$input = trim($input); // trims beginning and trailing space from text.
$input = strtolower($input); //makes the text lowercase
$input = explode(" ",$input); //creates an array delimited by spaces
$input = array_filter($input); //removes emptry strings, null values, and values that equate to false
$input = array_merge(array_flip(array_flip($input))); //removes duplicate entries
I just didn't know what to do beyond this to be able to compare to the keyword array for each row in the DB and rank each.
I'm open to any suggestions whether its a 3rd party class script or totally different approach.
I wanted to add that the keywords are not for actual pages but for business locations. The pages are created dynamically. So I would need to make a reference for each location ID.