Merge lp:~felmas/mvhub/expand_synonyms into lp:mvhub

Proposed by Ferhat Elmas
Status: Merged
Merged at revision: 586
Proposed branch: lp:~felmas/mvhub/expand_synonyms
Merge into: lp:mvhub
Diff against target: 70 lines (+29/-8)
2 files modified
lib-mvhub/lib/MVHub/GuideSearch.pm (+6/-8)
lib-mvhub/t/GuideSearch/expand_synonyms.t (+23/-0)
To merge this branch: bzr merge lp:~felmas/mvhub/expand_synonyms
Reviewer Review Type Date Requested Status
MVHub devs with commit rights Pending
Review via email: mp+70656@code.launchpad.net

Description of the change

 Broken expand_synonyms method is fixed and one unit test is added for this method but since there is no data loaded for synonyms table (will be by the lp:~felmas/mvhub/structure_fix), I have used MV_CONFIG_FILE to tests pass.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib-mvhub/lib/MVHub/GuideSearch.pm'
2--- lib-mvhub/lib/MVHub/GuideSearch.pm 2010-09-17 16:54:29 +0000
3+++ lib-mvhub/lib/MVHub/GuideSearch.pm 2011-08-06 20:38:28 +0000
4@@ -1,15 +1,14 @@
5
6 package MVHub::GuideSearch;
7
8-our ($VERSION) = '$Revision: 1552 $' =~ /([.\d]+)/;
9-
10 use strict;
11 use warnings;
12
13 use DBI;
14+
15+use MVHub::Common;
16 use MVHub::Utils;
17 use MVHub::Utils::DB;
18-use MVHub::Common;
19
20 sub agency_search {
21 my $dbh = shift;
22@@ -250,15 +249,14 @@
23 my $dbh = shift;
24 my $phrase_words_aref = shift;
25
26- my $word_list = '';
27- foreach (@$phrase_words_aref) { $word_list .= $dbh->quote($_) . ',' }
28- chop $word_list;
29-
30 my $sql = MVHub::Utils::DB::get_sql_select_statement(
31 'SYNONYM_STEM_X_WORD_STEM');
32
33- my @synonyms = @{ $dbh->selectcol_arrayref( $sql, undef, $word_list ) };
34+ $sql =~ s/\?/%s/;
35+ $sql = sprintf( $sql, join ",", ('?') x @$phrase_words_aref );
36
37+ my @synonyms
38+ = @{ $dbh->selectcol_arrayref( $sql, undef, @$phrase_words_aref ) };
39 @$phrase_words_aref
40 = Set::Array->new( @synonyms, @$phrase_words_aref )->unique();
41
42
43=== added directory 'lib-mvhub/t/GuideSearch'
44=== added file 'lib-mvhub/t/GuideSearch/expand_synonyms.t'
45--- lib-mvhub/t/GuideSearch/expand_synonyms.t 1970-01-01 00:00:00 +0000
46+++ lib-mvhub/t/GuideSearch/expand_synonyms.t 2011-08-06 20:38:28 +0000
47@@ -0,0 +1,23 @@
48+#!/usr/bin/perl
49+
50+use strict;
51+use warnings;
52+
53+use Test::Deep;
54+use Test::More tests => 5;
55+
56+my @subs = qw ( expand_synonyms );
57+
58+use_ok( 'MVHub::GuideSearch', qw( expand_synonyms ) );
59+can_ok( 'MVHub::GuideSearch', 'expand_synonyms' );
60+
61+use ok( 'MVHub::Utils::DB', qw( get_dbh ) );
62+can_ok( 'MVHub::Utils::DB', 'get_dbh' );
63+
64+my $dbh = MVHub::Utils::DB::get_dbh( $ENV{MV_CONFIG_FILE} );
65+my @phrase = qw / search the kid /;
66+my @result = qw / search the kid youth children child /;
67+
68+MVHub::GuideSearch::expand_synonyms( $dbh, \@phrase );
69+
70+cmp_deeply( \@phrase, bag(@result), 'phrase is correctly expanded' );

Subscribers

People subscribed via source and target branches