0
how the query below could be ordered by relevance and then by date?
$query = $mysqli->prepare(
"SELECT `id`, `titulo`, `foto`, `descricao`, `slug`, `data`, '' as `local` FROM `noticias` WHERE MATCH (`titulo`, `descricao`) AGAINST (?)
UNION
SELECT `id`, `titulo`, `foto`, '' as `descricao`, `slug`, `data`, `local` FROM `galeria` WHERE MATCH (`titulo`, `local`) AGAINST (?) ORDER BY `data` DESC"
);
Currently ordering by date, but wanted by relevance according to the search.
Example:
Currently if I search "Maria’s Feast" is appearing like this:
- Feast of Mary 12/09/2018
- Any party 10/09/2018
- Feast of John 10/08/2018
- Feast of Mary 10/07/2017
I wanted it to stay that way:
- Feast of Mary 12/09/2018
- Feast of Mary 10/07/2017
- Any party 10/09/2018
- Feast of John 10/08/2018
then wouldn’t be
order by titulo, data DESC
?– Ricardo Pontual
I tried, but it didn’t work.
– Frederico Moreira
ORDER BY relevance DESC
can help you... however it will order the first result_set separate from the second– fernandosavio
@fernandosavio could not make it work, because in the other example was only 1 table and not two as I am doing.
– Frederico Moreira
Yeah, he’d just sort a select... to sort the two together I guess I’d have to turn your Unions into a subquery and sort in select more from outside.
– fernandosavio
@fernandosavio this link here has the answer (I think), but I could not adapt to my query. Could you help me? https://stackoverflow.com/questions/9018577/mysql-fulltext-search-relevance-across-multiple-tables
– Frederico Moreira
Actually what I said is exactly what @Matheusribeiro posted in response. He turned your query into a subquery and ordered "out" of the subquery
– fernandosavio
The only difference is that in the answer you linked there is a field
relevance
which is added to select and is used to sort.– fernandosavio
Yes, but as I told him, I need to order by relevancy of the result and not necessarily in alphabetical order. For example, I need "Rosario party" if I sort by alphabetical order this result may come after "cool party" because the 2 has the term party and by alphabetical order the result "cool party" would come first
– Frederico Moreira