I have been playing with search querys its one of the more out dated pieces of code in TT, the biggest pain is the relevance of the results which took some attempts lol so here is a example im working on at the minute which you maybe be able to improve or use
Ill update when im fully happy and when its live here but the results should work for testing your forum tables will be pretty much the same
what it returns
matched word in title (eg snatch) then
word in title (eg snatched) then
word in post (eg this is snatch posted by ???) then
word inside post somewhere (eg this is snatched posted by ???)
i have no condition for no key on this so be sure to add to url eg url/????/search=test or = url/????/search=test+snatch
Ill update when im fully happy and when its live here but the results should work for testing your forum tables will be pretty much the same
what it returns
matched word in title (eg snatch) then
word in title (eg snatched) then
word in post (eg this is snatch posted by ???) then
word inside post somewhere (eg this is snatched posted by ???)
i have no condition for no key on this so be sure to add to url eg url/????/search=test or = url/????/search=test+snatch
$keywords = $_GET['keywords'];
if (!$keywords == '') {
$keys = explode(" ", $keywords);
foreach ($keys as $k) {
$searcha[] = " forum_topics.subject LIKE '%$k%' ";
$searchb[] = " forum_posts.body LIKE '%$k%' ";
$searchc[] = " forum_topics.subject LIKE '%$k%' ";
$searchd[] = " forum_posts.body LIKE '%$k%' ";
}
$whereasearch = '(' . implode(' OR ', $searcha) . ')';
$wherebsearch = '(' . implode(' OR ', $searchb) . ')';
$wherecsearch = implode(' OR ', $searchc);
$wheredsearch = implode(' OR ', $searchd);
$wherea = $whereasearch;
$whereb = $wherebsearch;
$wherec = $wherecsearch;
$whered = $wheredsearch;
}
$test = DB::run("SELECT *, ( $wherea + $whereb ) as count_words
FROM forum_posts
JOIN forum_topics
ON forum_posts.topicid=forum_topics.id
WHERE ($wherec OR $whered)
ORDER BY count_words DESC")->fetchAll();
/*
var_dump($wherea); echo '<br>';
var_dump($whereb); echo '<br>';
var_dump($wherec); echo '<br>';
var_dump($whered); echo '<br>';
*/
foreach ($test as $row) {
var_dump($row); echo '<br>';
}
die();
