With LOWER() you can overcome the problem of the tc> function, which is case sensitive mysql.
Its messy, but at my end this query is pretty fast.
To speed things up, I get a result set in an element that I declared as a view in my "outer" query. Since mysql already has results at this point, the replace method is pretty fast.
I created a query like the one below to search for multiple terms in multiple tables and multiple columns. I get a relevancy number equivalent to the sum of counting all occurrences of all found search terms in all found columns
SELECT DISTINCT ( ((length(x.ent_title) - length(replace(LOWER(x.ent_title),LOWER('there'),''))) / length('there')) + ((length(x.ent_content) - length(replace(LOWER(x.ent_content),LOWER('there'),''))) / length('there')) + ((length(x.ent_title) - length(replace(LOWER(x.ent_title),LOWER('another'),''))) / length('another')) + ((length(x.ent_content) - length(replace(LOWER(x.ent_content),LOWER('another'),''))) / length('another')) ) as relevance, x.ent_type, x.ent_id, x.this_id as anchor, page.page_name FROM ( (SELECT 'Foo' as ent_type, sp.sp_id as ent_id, sp.page_id as this_id, sp.title as ent_title, sp.content as ent_content, sp.page_id as page_id FROM sp WHERE (sp.title LIKE '%there%' OR sp.content LIKE '%there%' OR sp.title LIKE '%another%' OR sp.content LIKE '%another%' ) AND (sp_content.title NOT LIKE '%goes%' AND sp_content.content NOT LIKE '%goes%') ) UNION ( [search a different table here.....] ) ) as x JOIN page ON page.page_id = x.page_id WHERE page.rstatus = 'ACTIVE' ORDER BY relevance DESC, ent_title;
Hope this helps someone
- Seacrest out
user423443
source share