Skip to content

Instantly share code, notes, and snippets.

@yoku0825
Created March 6, 2015 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoku0825/f0708574294042cbf350 to your computer and use it in GitHub Desktop.
Save yoku0825/f0708574294042cbf350 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Text::MeCab;
my $parser= Text::MeCab->new();
my $conn = DBI->connect("dbi:mysql:d1;mysql_socket=/usr/mysql/5.6.23/data/mysql.sock",
"root", "", {mysql_enable_utf8 => 1});
my $rs = $conn->selectall_arrayref("SELECT tweet_id, text FROM tweets", {Slice =>{}});
foreach my $row (@$rs)
{
my @ret;
for (my $node= $parser->parse($row->{text}); $node; $node= $node->next)
{
push(@ret, $node->surface) if $node->surface;
}
$conn->do("UPDATE tweets SET fts = ? WHERE tweet_id = ?", undef, join(" ", @ret), $row->{tweet_id});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment