tags:

views:

24

answers:

2

Hi, I have been struggling to find a way to rank blog post articles by popularity of names that appear in them.

Here's what I'm trying to achieve: I have a blog where celebrity names commonly appear. I would like to count how many times these celebrity names appear in the blog titles, and rank the output by most popular celebrity (name appears the most).

My idea is to run a query that counts how many times names from a table(table of celebrity names) appear in the posts. This is where I'm having trouble. Can't figure out the best query to make this work.

Any help? Do I need to use an Array?

A: 

A possible solution is to index the data first and then search. I've done this via Lucene and works like a charm.

cherouvim
A: 

Maybe something like -- adjust for your dialect of SQL.

select c.name, count(*) as occurrences
from celebrities c
inner join articles a on a.title like '%' + c.name + '%'
group by c.name
tvanfosson
Thanks for this. Looks like it should work by I'm getting an empty result. Here's my query: SELECT c.names, count(*) as occurrences from wp_celebnames c inner join wp_posts p on p.post_title like '%c.names%' group by c.names wp_celebnames is a table with roughly 500 celebrity names. wp_posts.post_title has titles that may or may not have one of these names included.
Mike
You need to concatenate the pattern characters '%' + c.names + '%'
tvanfosson