MySQL Search and Full Text Search

Any full-text, MySQL experts there?

I wrote yesterday a question about any suggestions on how to use full-text search with a lot of connections, a little lazy, I actually did not try.

Since then, I have had a good attempt to master it myself by creating several successful test queries regarding my full text fields. If I DO NOT use any connections and do not request each field separately, full-text functions work fine, and the / boolean value works fine with great performance ... but ... as soon as I add my connections to run the full query, it works forever and always.

Could someone find anything in my request that might cause this because, as an amateur, I really can't see it!

SELECT photos.photoID, photos.headline, photos.dateCreated, MATCH (people.people) AGAINST ('+sarah +harding' IN BOOLEAN MODE) AS Rel1 FROM photos LEFT JOIN ( photoPeople INNER JOIN people ON photoPeople.peopleID = people.PeopleID ) ON photos.photoID = photoPeople.photoID AND MATCH (people.people) AGAINST ('+sarah +harding' IN BOOLEAN MODE) WHERE photos.photoStatus = 'Live' GROUP BY photos.photoID ORDER BY Rel1 

This is one of my successful, individual requests:

 SELECT photoID, headline, dateCreated, MATCH (caption) AGAINST ('+sarah +harding' IN BOOLEAN MODE) AS Relevance FROM photos WHERE photoStatus = 'Live' AND MATCH (caption) AGAINST ('+sarah +harding' IN BOOLEAN MODE) ORDER BY Relevance 

This is the DB schema:

 photos (tbl) photoID INT(11) Primary Auto-Increment headline Long-Text caption Long-Text / FULLTEXT dateCreated DateTime people (tbl) peopleID INT(11) Primary Auto-Increment people VarChar(255) / FULLTEXT photoPeople (tbl) photoID INT(11) peopleID INT(11) keywords (tbl) keywordID INT(11) Primary Auto-Increment keyword VarChar(255) / FULLTEXT photoKeyword (tbl) photoID INT(11) keywordID INT(11) photoContributor (tbl) photoID INT(11) contributorRef VarChar(100) / FULLTEXT 

And this is my EXPLAIN listing:

  id select_type table type possible_keys key key_len ref rows
 1 SIMPLE photos ALL NULL NULL NULL NULL 89830
 1 SIMPLE photoContributor ALL NULL NULL NULL NULL 149635  
 1 SIMPLE photoPeople ALL NULL NULL NULL NULL 110606
 1 SIMPLE people eq_ref PRIMARY PRIMARY 4 1   
 1 SIMPLE photoKeyword ALL NULL NULL NULL NULL 699102  
 1 SIMPLE keywords eq_ref PRIMARY PRIMARY 4 1

My site visitor should be able to search: "Brad Pitt Angelina Jolie Dorchester Hotel Sunglasses @MG" - this should find "Brad Pitt" and "Angelina Jolie" from the "people.people" table and, possibly, the "photos.caption" table. He should also find "Dorchester Hotel" from the table "photos.caption" "Sunglasses" from the table "keywords.keyword" and, finally, he should find "@MG" in the table "photoContributor.contributorRef".

Any help on this subject would be greatly appreciated ...

+6
source share
2 answers

I suggest using separate small queries and using UNION to create a unified result set.

Here is another question with a similar task. Mysql Full text search across multiple tables

Update

 SELECT "Photos" AS TableName, photoID AS ID, MATCH (caption) AGAINST ('+sarah +harding' IN BOOLEAN MODE) AS Relevance FROM photos UNION ALL SELECT "People" AS TableName, peopleID AS ID, MATCH (people) AGAINST ('+sarah +harding' IN BOOLEAN MODE) FROM people UNION ALL SELECT "Keyword" AS TableName, keywordID AS ID, MATCH (keyword) AGAINST ('+sarah +harding' IN BOOLEAN MODE) FROM keyword 

I really don't know what data you have, but this will create something like:

Table name | ID | Relevance

Photo | 1 | 1

Photo | 2 | 0

People | 1 | 1

Keyword | 10 | 1

You can add additional offers that suit your needs, but this is the main idea.

+3
source

I suggest not using MySQL and instead use a real FTS solution like Lucene, which is often combined with MySQL by those who want FTS in MySQL. https://stackoverflow.com/questions/553055/best-full-text-search-for-mysql

0
source

Source: https://habr.com/ru/post/896901/


All Articles