我真的不喜欢全文,只是因为我没有让它为我工作,所以我决定使用长匹配。我想知道是否有办法提高这段代码的速度。我知道它笨重,而且 99% 都是垃圾。但我真正想要的只是可以查看我的整个表格并按相关性对其进行排序。:
if (isset($_GET['post_title'])) {
$colname_getPosts = $_GET['post_title'];
}
mysql_select_db($database_Main);
function test($string){
$output = '';
$array = explode(' ', $string);
foreach ($array as $arraytags) {$output .= ' OR MATCH(post_title, post_entry, post_author, tags)
AGAINST("%'.$arraytags.'"IN BOOLEAN MODE)'; }
$array = explode(' ', $string);
foreach ($array as $arraytags) {$output .= ' OR MATCH(post_title, post_entry, post_author, tags)
AGAINST("%'.$arraytags.'%"IN BOOLEAN MODE)'; }
$array = explode(' ', $string);
foreach ($array as $arraytags) {$output .= ' OR MATCH(post_title, post_entry, post_author, tags)
AGAINST("'.$arraytags.'%"IN BOOLEAN MODE)'; }
$array = explode(' ', $string);
foreach ($array as $arraytags) {$output .= ' OR MATCH(post_title, post_entry, post_author, tags)
AGAINST("'.$arraytags.'"IN BOOLEAN MODE)'; }
return $output;
}
$query_getPosts = "
SELECT post_id, post_date, post_title, post_author, post_entry, tags, sum(relevance)
FROM (
SELECT post_id, post_date, post_title, post_author, post_entry, tags, 10 AS relevance FROM blog_posts WHERE MATCH(post_title) AGAINST('%$colname_getPosts%' IN BOOLEAN MODE)
UNION
SELECT post_id, post_date, post_title, post_author, post_entry, tags, 2 AS relevance FROM blog_posts WHERE MATCH(post_author) AGAINST('%$colname_getPosts%' IN BOOLEAN MODE)".test($colname_getPosts)."
UNION
SELECT post_id, post_date, post_title, post_author, post_entry, tags, 5 AS relevance FROM blog_posts WHERE MATCH(post_entry) AGAINST('%$colname_getPosts%' IN BOOLEAN MODE)
UNION
SELECT post_id, post_date, post_title, post_author, post_entry, tags, 7 AS relevance FROM blog_posts WHERE MATCH(tags) AGAINST('%$colname_getPosts%' IN BOOLEAN MODE))results
GROUP BY post_id, post_date, post_title, post_author, post_entry, tags ORDER BY relevance DESC";
我该如何改进它,他们的代码更简单吗?