views:

41

answers:

3

I have a table called artists. Within it, there is a field for the artist name (artist_name). Then there is a field for SEO friendly artist name, we'll call it search_name.

I have over 40,000 artists in this table. So, I'd like to convert all artists names to search friendly. What is the best way to accomplish this? Not looking for code here, just ideas.

This is what I have thus far. I'm just not sure if I should call all 40,000 artists, loop through them and update?

// Does this artist name have any symbols, apostrophes, etc. If so, strip them out

// Does this artist have a space (the beatles)? If so, replace with + (the+beatles).

// insert into search field

A: 

You could go through and create a secondary table two columns wide (id, safe) and insert it from there.

Query Table 1

Convert artist names to safe names

Insert into Table 2

Use id of both tables to match them. This would only allow one to one matches though if id is the index, you may want to create a third column if you want multiple safe names for a single artist (id | artistID | artistName)

Duniyadnd
A: 

Please consider using some full-text search engine. For example, the free sphinx search - it's quite flexible, extremely fast and it does support word stemming.

scaryzet
A: 

As 40,000 records aren't that much, I'd grab all of them and loop through them in memory. By doing it in memory, unique checks should be pretty fast.

In the end, I'd just chain the commands together like: $query .= "UPDATE artists SET search_name = $generated_name[$i] WHERE id = $id[$i];".

By the way: I'd replace spaces with a minus.

Maxem
This is the way I was leaning towards; just wasn't sure if my db server would take much of a hit or not.
pixel
As I said, 40k records ain't that much. If you'd do it row wise, you'd stress the server way more - as long as it has enough memory.
Maxem