Question

I have the following query which is doing a search against the keywords in Natural Language mode,

However I found that although I am using "Distinct" keyword to select Unique url, its not working, I get results with the same url a number of times, which is confusing me,

Also I have tried the "Group By" url, however issue is then "ORDER" of the mysql results changes (as you know MYSQL orders results in MOST RELEVANCE first in Natural Language Search)

Any other ways to achieve this

  1. Results must be in the "Most Relevance first"
  2. URLS must be unique

Query is

SELECT DISTINCT `url` , `search_id` , `total` , `keyword`, `title`, `description`
     FROM search 
     WHERE MATCH (`keyword`,`title`,`description`,`url`) AGAINST
    ('".$natural_keywords."'
    IN NATURAL LANGUAGE MODE)
    -- GROUP BY url
    -- ORDER BY score DESC
LIMIT ".$page.",10 
Was it helpful?

Solution

i solved this problem using relevance as below

SELECT `url` , `search_id` , `total` , `keyword`, `title`, `description`,
    ( 
        (   
            0.9 * (MATCH(`title`) AGAINST ('".$keywords."' IN BOOLEAN MODE))
        ) 
        + 
        (
            0.6 * (MATCH(`description`) AGAINST ('".$keywords."' IN BOOLEAN MODE))
        )
        + 
        (
            0.3 * (MATCH(`keyword`) AGAINST ('".$keywords."' IN BOOLEAN MODE))
        )

    ) AS relevance 

     FROM search
     WHERE MATCH (`keyword`,`title`,`description`,`url`) AGAINST
    ('".$natural_keywords."'
    IN NATURAL LANGUAGE MODE)
    -- GROUP BY url
    ORDER BY relevance DESC
    LIMIT ".$page.",10
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top