[Catalyst] Search example in any docs?

Dr. Jennifer Nussbaum bg271828 at yahoo.com
Tue Sep 23 21:21:25 BST 2008

--- On Tue, 9/23/08, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:

> From: Zbigniew Lukasiak <zzbbyy at gmail.com>
> Subject: Re: [Catalyst] Search example in any docs?
> To: bg271828 at yahoo.com, "The elegant MVC web framework" <catalyst at lists.scsys.co.uk>
> Date: Tuesday, September 23, 2008, 1:02 PM
> On Tue, Sep 23, 2008 at 9:38 PM, Dr. Jennifer Nussbaum
> <bg271828 at yahoo.com> wrote:
> > Hi.
> >
> > Im working on a new app which is working well. While
> doing it though i realised that i never get my serach done
> right. I mean, it works, but
> > i end up spending a lot of code munging parameters,
> making adjustments,
> > and so forth, and this cant be right. What should be a
> few lines takes a page or two of code, just for a simple one
> or two table search.
> >
> > I tried looking through the docs for a best-practices
> approach and unless i missed something there arent ANY
> examples of search in the docs, the tutorial, the wiki, the
> Advent.... (Oh in one place there was something about harder
> searches, fulltext in PostGres, but nothing general.)
> >
> > Is there any place that shows a simple example of a
> web form -> DBIC search in Catalyst? And if not, shouldnt
> there be?
> Hi there,
> I am sure you are referring to
> http://www.catalystframework.org/calendar/2007/16 :)  I
> don't really
> know what you need, but I start that article with a very a
> simple
> solution:
> my @records = $schema->ResultSet( 'MyTable'
> )->search(
>         $reqest->params,
>         { page => 1, rows => 5 }
>     );
> Only after presenting that I start discussing what to do
> when you need
> to add some more complex predicates to the query and
> propose a
> solution to that.

Yes i did see that and i did try it, but i quickly found that i ran into all sorts of problems. For example my params would usually include something
like a "action" param with the value "Submit query", whihc doesnt work so well when it hits the database ;-)

Thanks to Peter Karman for his other suggestion, which i will look at in more detail. I guess i do stuff like that by hand all the time--i have
code that looks like 

  if ( $c->req->params->{title} ) {
    my $title = "%" . $c->req->params->{title} . "%";
    push (@$query, { title => { like => $title } });

  # exact match here
  if ( $c->req->params->{author} ) {
    my $performer = $c->req->params->{author};
    push (@$query, { author => { '=' => $author} });

etc., which just looks messy.

In any case i do think this should be at least MENTIONED in some of the docs. The fact that it gets complicated doesnt mean it should be ignored, 
surely everyone has to do this in Cat.




More information about the Catalyst mailing list