Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Full Text Search and Joins
    primarykey
    data
    text
    <p>I have built a celebrity photo website. After reaching 100,000 photos, my amateur skills have started to show up and need honing, quickly. Some simple queries are taking 5-10 seconds to return!</p> <p>I have a one text-box search feature, which will search the "photos" table (for caption and headline), the "people" table, the "keywords" table and the "photoContributor" table. There are two relational/association tables for "people" and "keywords" called "photoPeople" and "photoKeyword".</p> <p>One possible user search maybe: "Brad Pitt Angelina Jolie Sunglasses @MG" - This should return all photos that contain Brad and Angelina together, where Sunglasses can be seen and taken by the contributor @MG.</p> <p>I soon realised that I could not use an INDEX on my "caption" and "headline" fields in the "photos" table because I am using the "LIKE" clause with a "%" prefix, and that those particular fields are set to a "LONGTEXT" data type. Because I have no indexes on those fields, it's causing huge return times. Therefore, I believe I need to use "FULLTEXT" search, I can then set the "caption" and "headline" fields to VARCHAR(2000), as the largest caption to-date is 1991 characters, and still use the "INDEX" feature, which will hopefully speed things up. I also like the boolean function to remove words from the search too.</p> <p>The reason I am writing this question, is that I am totally useless at "JOINS". I can probably write a "FULLTEXT" query on one table and I can probably join two tables together using a left or right join... but because I have the association/relational tables in between, I get really, really confused.</p> <p>I would appreciate if somebody could please show me an example query, using joins and full-text and using relational tables, or just explain to me which joins to use, if any, and any tips you have for full-text on the database structure I have.</p> <p>Below is my basic database schema:</p> <pre> photos (tbl) photoID INT(11) Primary Auto-Increment headline Long-Text caption Long-Text dateCreated DateTime people (tbl) peopleID INT(11) Primary Auto-Increment people VarChar(255) photoPeople (tbl) photoID INT(11) peopleID INT(11) keywords (tbl) keywordID INT(11) Primary Auto-Increment keyword VarChar(255) photoKeyword (tbl) photoID INT(11) keywordID INT(11) photoContributor (tbl) photoID INT(11) contributorRef VarChar(100) </pre> <p>When a search is made, the tables/fields that are queried are: photos.headline, photos.caption, keywords.keyword, people.people, photoContributor.contributorRef.</p> <p>I hope somebody can help me on my way to build this <em>urgent</em> query.</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.
 

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