# Copyright (c) 2002 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: ItemSearchList.pm,v 2.1 2006/10/16 21:08:04 moeller Exp $ package Bivio::PetShop::Model::ItemSearchList; use strict; $Bivio::PetShop::Model::ItemSearchList::VERSION = sprintf('%d.%02d', q$Revision: 2.1 $ =~ /\d+/g); $_ = $Bivio::PetShop::Model::ItemSearchList::VERSION; =head1 NAME Bivio::PetShop::Model::ItemSearchList - search items by keywords =head1 RELEASE SCOPE bOP =head1 SYNOPSIS use Bivio::PetShop::Model::ItemSearchList; =cut =head1 EXTENDS L =cut use Bivio::PetShop::Model::ItemList; @Bivio::PetShop::Model::ItemSearchList::ISA = ('Bivio::PetShop::Model::ItemList'); =head1 DESCRIPTION C produces a list of items to found by keyword. =cut =head1 CONSTANTS =cut =for html =head2 PAGE_SIZE : int Returns a low number so we can demonstrate paging on search page. =cut sub PAGE_SIZE { return 8; } #=IMPORTS #=VARIABLES =head1 METHODS =cut =for html =head2 internal_initialize() : hash_ref; B =cut sub internal_initialize { my($self) = @_; my($parent_info) = $self->SUPER::internal_initialize; delete($parent_info->{parent_id}); return $self->merge_initialize_info($parent_info, { other => [ 'Product.category_id', ], }); } =for html =head2 internal_pre_load(Bivio::SQL::ListQuery query, Bivio::SQL::ListSupport support, array_ref params) : string Uses the category search parameter to refine the query if present. =cut sub internal_pre_load { my($self, $query, $support, $params) = @_; my($where) = ''; # search for any word across name/description/category foreach my $word (split(' ', $query->get('search') || '')) { $where .= ' AND ' if $where; $where .= '(' . join(" || ' ' || ", map({"LOWER($_)"} qw( item_t.attr1 product_t.name product_t.description product_t.category_id ))) . ') LIKE ?'; push(@$params, lc("%$word%")); } return $where && "($where)"; } #=PRIVATE SUBROUTINES =head1 COPYRIGHT Copyright (c) 2002 bivio Software, Inc. All Rights Reserved. Visit http://www.bivio.biz for more info. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; If not, you may get a copy from: http://www.opensource.org/licenses/lgpl-license.html =head1 VERSION $Id: ItemSearchList.pm,v 2.1 2006/10/16 21:08:04 moeller Exp $ =cut 1;