2
\$\begingroup\$

I'm using innodb full-text search to return a set of results where the newest posts are more relevant. Just wanted to check that this the best method:

SELECT *, (MATCH(note) AGAINST ('$search' IN BOOLEAN MODE))/SQRT(GREATEST(1, DATEDIFF(NOW(), date))) AS score FROM notes WHERE userid = '$userid' HAVING score > 0 ORDER BY score DESC
\$\endgroup\$
2
\$\begingroup\$

A few "small" comments.

  1. Don't use SELECT * for reasons outlined in this question's answers:

    What is the reason to not use select *?

  2. Linebreaks and indentation make your code much easier to read:

    SELECT *, (MATCH(note) AGAINST (
        '$search' IN BOOLEAN MODE))/SQRT(GREATEST(1, DATEDIFF(NOW(), date)
        )) AS score 
    FROM notes 
    WHERE userid = '$userid' 
    HAVING score > 0 
    ORDER BY score DESC
    

Things I like:

  • You're not writing it ALL IN SHOUT-CASE ;)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.