I've been struggling to find the correct way to format my mysql expression to match against a related keyword table.
The tables are set up as follows:
photos: id,path,various exif data
photos_to_tags: photos_id,photos_tags_id
photo_tags: id,name
The SQL is as follows:
SELECT DISTINCT (photos.path),photos.name,
MATCH (photo_tags.name) AGAINST('+bamboo* +flooring* ') AS relevance
FROM photo_tags
LEFT JOIN photos_to_tags ON photo_tags_id = photo_tags.id
LEFT JOIN photos ON photos.id = photos_id
WHERE (MATCH (photo_tags.name) AGAINST('+bamboo* +flooring* ' IN BOOLEAN MODE))
OR photo_tags.name = 'bamboo flooring'
GROUP BY path
ORDER BY relevance
LIMIT 0,24;
It is not returning results unless the exact phrase "bamboo flooring" is a tag. If 'bamboo' is a tag, and 'flooring' is a tag, then it won't return results.
Some more elaboration to further describe the problem: This is for a contractor's web site. He has hundreds of photos of work. He may have 30 roofing photos, some of the roofing photos may be steel roofs, others may be cedar shake, lifetime, etc.
The keyword tags are in a separate table, and they can be used to list all photos that are of roofing, or the search can be used to further isolate only the steel roofs, or perhaps steel roof with trim details, etc.
There may be another way to write this query-- I have not been able to find a good way to return relevant results. For example, if someone searches for lifetime roof, they don't want to see steel roof photos.
Thanks!