[Dbix-class] match against ...

RAPPAZ Francois francois.rappaz at unifr.ch
Wed Apr 2 09:47:01 GMT 2014


I'm struggling with code as

	#sql I want to is SELECT * FROM jrn WHERE match(ti, ex, ad) against('+$bla' in boolean mode) ORDER BY tri");

  $bla is a string that holds the text to search
 
 my $sqlmaker = SQL::Abstract->new(special_ops => [  {regex => qr/^match$/i,
     handler => sub {
       my ($me, $field, $op, $arg) = @_;
       $arg = [$arg] if not ref $arg;
       my $label         = $me->_quote($field);
       my ($placeholder) = $me->_convert('?');
       my $placeholders  = join ", ", (($placeholder) x @$arg);
       my $sql           = $me->_sqlcase('match') . " ($label) " . $me->_sqlcase('against') . " ($placeholders) ";
       my @bind = $me->_bindtype($field, @$arg);
       return ($sql, @bind);
       }
     },
  ]);
	
	my ($where, @bind)= $sqlmaker->where("ti, ex, ad", "tri", $bla);
$self->{log}->debug($where);
	 my $rs = $self->{schema}->resultset('Jrn')->search_rs(undef, {where=> $where});

But keep having error message. What is @bind for if I don't use it ? 

Thanks for showing the right way to have this !

François


> -----Original Message-----
> From: Hailin Hu [mailto:i at h2l.name]
> Sent: vendredi, 28. mars 2014 18:36
> To: DBIx::Class user and developer list
> Subject: Re: [Dbix-class] match against ...
> 
> Hi,
> 
> Have a look at docs below:
> http://search.cpan.org/~ribasushi/DBIx-Class-
> 0.08270/lib/DBIx/Class/ResultSet.pm#where
> http://search.cpan.org/~ribasushi/SQL-Abstract-
> 1.77/lib/SQL/Abstract.pm#SPECIAL_OPERATORS
> 
> On Sat, Mar 29, 2014 at 12:46 AM, RAPPAZ Francois
> <francois.rappaz at unifr.ch> wrote:
> > Hi there
> >
> > I haven't look deep enough in the doc pages, sorry, but how can I
> > translate this with resultset('table')->search_rs();
> >
> > SELECT * FROM table WHERE match(field1, field2, field3)
> against('+$bla' in boolean mode) ORDER BY field1 ?
> >
> > $bla being taken from a field and having the spaces substituted with
> + :
> >
> > my $bla = $b->get_text();
> >
> > ($bla=$bla)=~s/\s+/ \+/g;
> >
> > Thanks
> >
> > François
> >
> > _______________________________________________
> > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> > IRC: irc.perl.org#dbix-class
> > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> > Searchable Archive:
> > http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
> 
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-
> class at lists.scsys.co.uk



More information about the DBIx-Class mailing list