What do I have to change in the query to get an exact match in the first place?
For example, anyone enters happy songs in the search form, now he will get this output..
Happy Child
Happy days
Happy people
Happy Song
Happy Station
...
This is my query..
SELECT `artist`, `song`, `genre`, `pass`, `id` FROM `songs` JOIN `artists` USING (`pass`) WHERE MATCH(`artist`) AGAINST("happy song") OR MATCH(`song`, `genre`) AGAINST("happy song") ORDER BY `song` ASC LIMIT 0,30 ') or die(mysql_error($_connect));``` Thank you! EDIT 03.07.22 Changed query to:<br> ```$query = mysqli_query($_connect, ' SELECT `artist`, `song`, `genre`, `pass`, `id` FROM `songs` JOIN `artists` USING (`pass`) WHERE MATCH(`artist`) AGAINST("happy song") OR MATCH(`song`, `genre`) AGAINST("happy song") ORDER BY `song` = "happy song" DESC ') or die(mysql_error($_connect));``` The output is the same, result with only "song" in the text are above in the result when searched for "happy song" **EDIT 14.7.22** **Table Artists:** CREATE TABLE `artists` ( `artist` varchar(40) NOT NULL, `pass` int(10) UNSIGNED NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 PACK_KEYS=1; ALTER TABLE `artists` ADD PRIMARY KEY (`pass`), ADD UNIQUE KEY `uni_que` (`artist`) USING BTREE; ALTER TABLE `artists` ADD FULLTEXT KEY `full_txt` (`artist`); COMMIT; **Table Songs:** CREATE TABLE `songs` ( `song` varchar(80) NOT NULL, `tags` varchar(40) NOT NULL, `style` varchar(20) NOT NULL, `pass` bigint(20) UNSIGNED NOT NULL, `id` bigint(20) UNSIGNED NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 PACK_KEYS=1; ALTER TABLE `songs` ADD PRIMARY KEY (`id`); ALTER TABLE `songs` ADD FULLTEXT KEY `song` (`song`,`tags`,`style`); COMMIT;
You are currently requesting
ORDER BY song ASC
Sort alphabeticallyChange to
ORDER BY MATCH(...) AGAINST(...) DESC
This might put "A Song About a Happy Child" at the top of the list. In other words, if you need to "sing" first, we need to work harder:
(Since you have
OR
and multiple columns involved, the query can get quite confusing.)If you don't want a song with only one word, see
operator, or
Note the intentional use of quotation marks.