Re: [Dbix-class] match against ...

2014-04-02 Thread Hailin Hu
You should at least give out the error message if you expect any
feedback from others.

Others will not create a same environment as yours and run the codes
you pasted. Generally, they just analyze the problem with the
description only. Me, too :)

On Wed, Apr 2, 2014 at 6:47 PM, RAPPAZ Francois
 wrote:
> 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...@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
>>  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-
>> cl...@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@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@lists.scsys.co.uk


Re: [Dbix-class] match against ...

2014-04-02 Thread RAPPAZ Francois
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...@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
>  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-
> cl...@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@lists.scsys.co.uk