Note that there are some explanatory texts on larger screens.

plurals
  1. POAggregate most relevant results with MySQL's fulltext search across many tables
    primarykey
    data
    text
    <p>I am running fulltext queries on multiple tables on MySQL 5.5.22. The application uses innodb tables, so I have created a few MyISAM tables specifically for fulltext searches.</p> <p>For example, some of my tables look like</p> <pre><code>account_search =========== id account_id name description hobbies interests product_search =========== id product_id name type description reviews </code></pre> <p>As these tables are solely for fulltext search, they are denormalized. Data can come from multiple tables and are agregated into the search table. Besides the ID columns, the rest of the columns are assigned to 1 fulltext index.</p> <p>To work around the "50%" rule with fulltext searches, I am using <code>IN BOOLEAN MODE</code>.</p> <p>So for the above, I would run:</p> <pre><code>SELECT *, MATCH(name, type, description, reviews) AGAINST('john') as relevance FROM product_search WHERE MATCH(name, type, description, reviews) AGAINST('john*' IN BOOLEAN MODE) LIMIT 10 SELECT *, MATCH(name, description, hobbies, interests) AGAINST('john') as relevance FROM account_search WHERE MATCH(name, description, hobbies, interests) AGAINST('john*' IN BOOLEAN MODE) LIMIT 10 </code></pre> <p>Let's just assume that we have products called "john" as well :P</p> <p>The problem I am facing are:</p> <ul> <li><p>To get meaningful relevance, I need to use a search without <code>IN BOOLEAN MODE</code>. This means that the search is subjected to the 50% rule and word length rules. So, quite often, if I most of the products in the <code>product_search</code> table is called <code>john</code>, their relevance would be returned as 0.</p></li> <li><p>Relevances between multiple queries are not comparable. (I think a relevance of 14 from one query does not equal a relevance of 14 from another different query).</p></li> <li><p>Searches will not be just limited to these 2 tables, there are other "object types", for example: "orders", "transactions", etc.</p></li> </ul> <p>I would like to be able to return the top 7 most relevant results of ALL object types given a set of keywords (1 search box returns results for ALL objects).</p> <p>Given the above, what are some algorithms or perhaps even better ideas for get the top 7?</p> <p>I know I can use things like solr and elasticsearch, I have already tried them and am in the proces of integrating them into the application, but I would like to be able to provide search for those who only have access to MySQL.</p>
    singulars
    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.
    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