I currently have this "bit" of code:
// Process the checkboxes
$options = array();
if ($_POST['chk_descriptions']):
array_push($options, 'description LIKE "%'.$keys.'%"');
endif;
if ($_POST['chk_issues']):
array_push($options, 'issue LIKE "%'.$keys.'%"');
endif;
if ($_POST['chk_solutions']):
array_push($options, 'solution LIKE "%'.$keys.'%"');
endif;
// Construct the query search conditions string
$options_string = "";
for ($index = 0; $index < count($options); $index++) {
$options_string .= $options[$index]." OR ";
}
// Strip out the ending OR condition
$options_string = substr($options_string, 0, strlen($options_string) - 4);
$query = mysql_query("SELECT id,description FROM solution WHERE ($options_string)", $mysql);
I want to convert this to a simple Full-text search (Non-Boolean since I'm on an earlier version MySQL). Sounded pretty easy to me at first. I am trying to figure out a way to allow dynamic choice of columns (which are set via the checkboxes) to be searched with Full-text search. My table is setup like-so:
CREATE TABLE `solution` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`description` VARCHAR( 100 ) NOT NULL ,
`issue` TEXT NOT NULL ,
`solution` TEXT NOT NULL ,
`owner` VARCHAR( 15 ) NOT NULL ,
`posted` TIMESTAMP,
PRIMARY KEY ( `id` ) ,
FULLTEXT (
`description` ,
`issue` ,
`solution`
)
);
I know how to setup the checkbox processing. But what I don't know how to approach is the dynamic query. If my table is setup with a FULLTEXT(description,issue,solution) and I try to Full-Text search only 1 chosen column it will give me an index error. Sorry I don't have the specific error right now as I have changed the code around. But I fixed it by dropping all my FULLTEXT's and making an individual FULLTEXT(description) FULLTEXT(issue) FULLTEXT(solution). The search worked on that particular column. But then if I search other columns besides 'description' (In other words, if I had more than one checkbox checked) I would get that index error again.
So, does this mean I have to add in FULLTEXT's for every possible column search combination? If so, that's whack. Is there an easier/simpler approach to allow dynamic column searches? I would prefer to use Full-text search and not the LIKE method because I want to make use of relevancy. But if you can give me a good enough reason to change my mind then go for it. 🙂
Thanks for any help!