Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check against all joins when generating a score using MYSQL
    primarykey
    data
    text
    <p>I'm using MYSQL to generate a score for each result returned by a query. The results are then ordered by the score. </p> <p>The part that doesn't seem to be working properly is when I'm trying to add a score for each tag that has been searched and the result is assigned to. So lets say I do a search for the tags "example", "test and "tag" and one of my results is assigned to the tags "example", "test", "someothertag" it should come up with a score of 10 since there are 2 matches.</p> <p>What is actually happening is I'm getting a score of 5 if there is a match, regardless of how many tags are matched. and 0 if no tags are matched.</p> <p>Here is an example of one of the queries that is generated from a search.</p> <pre><code> SELECT DISTINCT results.*, ( 5*(MATCH(tags.name) AGAINST('"self employed"' IN BOOLEAN MODE)) + 5*(MATCH(tags.name) AGAINST('"rental income"' IN BOOLEAN MODE)) + 5*(MATCH(tags.name) AGAINST('"commission income"' IN BOOLEAN MODE)) + 5*(MATCH(tags.name) AGAINST('"bankruptcy"' IN BOOLEAN MODE)) + 5*(MATCH(tags.name) AGAINST('"condo approval"' IN BOOLEAN MODE)) + 1*usefulness + 10*shares ) AS score FROM results INNER JOIN categories c on results.ID = c.RESULT_ID INNER JOIN tags ON results.id = tags.result_id WHERE c.name in ('purchase', 'condo', 'va') AND ( tags.name = 'self employed' OR tags.name = 'rental income' OR tags.name = 'commission income' OR tags.name = 'bankruptcy' OR tags.name = 'condo approval' ) AND ( results.scope = 'all' OR results.scope = 'hi' ) AND published = 1 GROUP BY results.ID having count(distinct c.c_id) = 3 ORDER BY score DESC LIMIT 8 OFFSET 0 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload