Jump to content

Fulltext search on multiple fields


DrQuincy
 Share

Recommended Posts

Firstly, when you do a MATCH AGAINST query in MySQL you can get the score. I have found this useful in the past where you want to place more on one field over another (e.g. you may wish to place more weight on a h1 fields than a body field) as you can add a multiplier to the relevancy score.

E.g.

SELECT
    `h1`,
    MATCH(`h1`) AGAINST ('birth') AS `score1`,
    MATCH(`body`) AGAINST ('birth') AS `score2`
FROM
    `pages`
ORDER BY
    (`score1` * 2) + `score2` DESC # h1 twice as important
LIMIT 10;

Without resorting to raw database queries can such a thing be done using the API? I.e. with $pages->find(). I searched the docs but couldn't find anything.

Secondly, according to https://processwire.com/docs/selectors/#sort

Quote

if you don't specify your own sort=property, the results are sorted according to MySQL's text searching relevance

If your query contains more than one fulltext search does PW combine the relevancy and order by that (if you don't explicitly sort by a property)? It seems to but from my tests I can't be 100% sure.

Thanks.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...