Created
July 28, 2009 13:46
-
-
Save Kimtaro/157305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ======================== | |
# = Specific to Japanese = | |
# ======================== | |
if ( $c->stash->{query}->{form}->{jap} ) { | |
$query->{'jap.jap'} = {'like' => $c->stash->{query}->{sql}->{jap_tokens}}; | |
my $q_jap = $c->model('DJDB')->storage->dbh->quote($jap); | |
$options = { | |
join => [qw/jap/], | |
order_by => qq{ | |
LOCATE($q_jap, kanji), | |
LOCATE($q_jap, kana_reading), | |
IF(kanji, CHAR_LENGTH(kanji), 0), | |
CHAR_LENGTH(kana_reading), | |
NOT(is_common) | |
}, | |
group_by => [qw/me.id/], | |
distinct => 1, | |
} | |
} | |
# ======================= | |
# = Specific to English = | |
# ======================= | |
if ( $c->stash->{query}->{form}->{eng} ) { | |
my(@eng_like, @eng_regexp); | |
foreach my $token (@{$c->stash->{query}->{sql}->{eng_tokens}}) { | |
push @eng_like, $token->{for_like}; | |
push @eng_regexp, $token->{for_regexp}; | |
} | |
$query->{'meanings'} = [ | |
'-and' => | |
[ '-and' => map {{'like' => $_}} @eng_like], | |
[ '-and' => map {{'regexp' => $_}} @eng_regexp], | |
]; | |
my $q_eng = $c->model('DJDB')->storage->dbh->quote($eng); | |
$options = { | |
order_by => qq{ | |
IF(kanji, CHAR_LENGTH(kanji), 0), | |
CHAR_LENGTH(kana_reading), | |
is_common, | |
LOCATE($q_eng, meanings) | |
}, | |
group_by => [qw/me.id/], | |
} | |
} | |
# ================================================ | |
# = When searching for both Japanese and English = | |
# ================================================ | |
if ( $c->stash->{query}->{form}->{jap} && $c->stash->{query}->{form}->{eng} ) { | |
my $q_jap = $c->model('DJDB')->storage->dbh->quote($jap); | |
my $q_eng = $c->model('DJDB')->storage->dbh->quote($eng); | |
$options = { | |
join => [qw/jap/], | |
order_by => qq{ | |
LOCATE($q_jap, kana_reading), | |
LOCATE($q_jap, kanji), | |
IF(kanji, CHAR_LENGTH(kanji), 0), | |
CHAR_LENGTH(kana_reading), | |
is_common, | |
LOCATE($q_eng, meanings) | |
}, | |
group_by => [qw/me.id/], | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment