http://qs321.pair.com?node_id=683137

hacker has asked for the wisdom of the Perl Monks concerning the following question:

I have a series of databases with articles in them. These are front-ended by a Wordpress blog interface.

I've been importing the articles into Wordpress with a little spider I wrote that pulls them from a remote article resource. This part all works.

The relevant insert code looks something like this (wrapped for PM):

my $users_sth = $dbh->prepare(qq{ INSERT IGNORE INTO `wp_users` (`user_login` , `user_pass` , `user_nicename` , `user_ +email` , `user_registered` , `user_status` , `display_name` ) VALUES (?, $random_password, ?, 'no-email\@localhost', ?, 0, ? +)}); $users_sth->execute($authors[$i], $authors[$i], $now, $authors[$i]); my $author_sth = $dbh->prepare(qq{SELECT id from wp_users WHERE user_ +login=?}); my $post_author = $authors[$i]; $author_sth->execute($authors[$i]); $author_sth->bind_col(1, \$post_author); my @output = fetch_body($urls[$i]); while ($author_sth->fetch) { my $post_sth = $dbh->prepare(qq{ INSERT IGNORE INTO `wp_posts` (`post_author` , `post_date` , `post_content` , `post_ +title`) VALUES (?, ?, ?, ?)}); $post_sth->execute($post_author, $now, @output, $title +s[$i]); } };

I had to alter some of the default tables in Wordpress to facilitate this by making post_title a VARCHAR(255) and setting it to unique as well as making user_login unique:

ALTER TABLE `wp_posts` ADD UNIQUE (`post_title`);

The inserts work, and so far no issues and no duplicate USERS in the database, but here's where it gets tricky...

When I'm inserting articles, sometimes there are articles which have "similar" titles and very similar content, written by two different people (plagiarism, no-doubt). Here are some examples:

| 597 | 102 | New Home Builders in Houston + + | 595 | 102 | New Home Builders In Houston Texas + + ... | 772 | 136 | Buy to Let Rental Properties + + | 754 | 136 | Buy to Let Rental Property

There are probably more examples, but those are the two that I picked out visually.

I asked the MySQL folks, and they pointed me to Soundex, but it didn't look that easy to implement, and I've heard bad things about the pattern matching.

So I started looking around and found Text::Levenshtein, Text::WagnerFischer, Text::PhraseDistance and String::Approx.

What I'm trying to figure out, is what is the best way to achieve this (preferably at article import time), so I can eliminate the potential for dupes?

An alternate solution is to import the "dupes", and mark them as "Unpublished", so I can manually review them later.

I don't want to add more tables to the db to facilitate this, I need to stay as close to "stock" as possible.

Ideas? Suggestions? Pseudocode?