Fixed the search function that broke in 7.0.7.

also fixed a user profile problemm
This commit is contained in:
JT Smith 2006-09-26 20:34:59 +00:00
parent 41bd19736c
commit 58b3128a3a
6 changed files with 51 additions and 37 deletions

View file

@ -37,17 +37,23 @@ These methods are available from this package:
#-------------------------------------------------------------------
sub _getQuery {
=head2 _getQuery ( columnsToSelect )
This is a private method and should never be used outside of this class.
=cut
sub _getQuery {
my $self = shift;
my $selectsRef = shift;
return
('select ' . join(', ', @$selectsRef,
($self->{_score}? $self->{_score} : ())) .
' from assetIndex inner join asset on assetIndex.assetId = asset.assetId where ' .
($self->{_isPublic}? 'isPublic = 1 and ' : '') . '('.$self->{_where}.')' .
($self->{_score}? ' order by score desc' : ''));
return ('select ' . join(', ', @$selectsRef, ($self->{_score} ? $self->{_score} : ())) . ' from assetIndex where '
. ($self->{_isPublic}? 'isPublic = 1 and ' : '')
. '('.$self->{_where}.')'
. ($self->{_score} ? ' order by score desc' : '')
);
}
#-------------------------------------------------------------------
=head2 getAssetIds ( )
@ -58,7 +64,7 @@ Returns an array reference containing all the asset ids of the assets that match
sub getAssetIds {
my $self = shift;
my $query = $self->_getQuery(['assetIndex.assetId']);
my $query = $self->_getQuery(['assetId']);
my $rs = $self->session->db->prepare($query);
$rs->execute($self->{_params});
my @ids = ();
@ -79,8 +85,7 @@ Returns an array reference containing asset objects for those that matched.
sub getAssets {
my $self = shift;
my $query = $self->_getQuery(['assetIndex.assetId', 'assetIndex.className',
'assetIndex.revisionDate']);
my $query = $self->_getQuery([qw(assetId className revisionDate)]);
my $rs = $self->session->db->prepare($query);
$rs->execute($self->{_params});
my @assets = ();
@ -126,11 +131,7 @@ sub getPaginatorResultSet {
my $paginate = shift;
my $pageNumber = shift;
my $formVar = shift;
my $query = $self->_getQuery(['assetIndex.assetId', 'assetIndex.title',
'assetIndex.url', 'assetIndex.synopsis',
'assetIndex.ownerUserId', 'assetIndex.groupIdView',
'assetIndex.groupIdEdit', 'assetIndex.creationDate',
'assetIndex.revisionDate', 'assetIndex.className']);
my $query = $self->_getQuery([qw(assetId title url synopsis ownerUserId groupIdView groupIdEdit creationDate revisionDate className)]);
my $paginator = WebGUI::Paginator->new($self->session, $url, $paginate, $pageNumber, $formVar);
$paginator->setDataByQuery($query, undef, undef, $self->{_params});
return $paginator;
@ -146,18 +147,14 @@ Returns a WebGUI::SQL::ResultSet object containing the search results with colum
sub getResultSet {
my $self = shift;
my $query = $self->_getQuery(['assetIndex.assetId', 'assetIndex.title',
'assetIndex.url', 'assetIndex.synopsis',
'assetIndex.assetId', 'assetIndex.title',
'assetIndex.url', 'assetIndex.synopsis',
'assetIndex.ownerUserId', 'assetIndex.groupIdView',
'assetIndex.groupIdEdit', 'assetIndex.creationDate',
'assetIndex.revisionDate', ' assetIndex.className']);
my $query = $self->_getQuery([qw(assetId title url synopsis ownerUserId groupIdView groupIdEdit creationDate revisionDate className)]);
my $rs = $self->session->db->prepare($query);
$rs->execute($self->{_params});
return $rs;
}
#-------------------------------------------------------------------
=head2 new ( session [ , isPublic ] )
@ -291,15 +288,15 @@ sub search {
$keywords = join(" ", @terms);
}
push(@params, $keywords, $keywords);
$self->{_score} = "match (assetIndex.keywords) against (?) as score";
push(@clauses, "match (assetIndex.keywords) against (? in boolean mode)");
$self->{_score} = "match (keywords) against (?) as score";
push(@clauses, "match (keywords) against (? in boolean mode)");
}
if ($rules->{lineage}) {
my @phrases = ();
foreach my $lineage (@{$rules->{lineage}}) {
next unless defined $lineage;
push(@params, $lineage."%");
push(@phrases, "asset.lineage like ?");
push(@phrases, "lineage like ?");
}
push(@clauses, join(" or ", @phrases)) if (scalar(@phrases));
}
@ -308,20 +305,20 @@ sub search {
foreach my $class (@{$rules->{classes}}) {
next unless defined $class;
push(@params, $class);
push(@phrases, "assetIndex.className=?");
push(@phrases, "className=?");
}
push(@clauses, join(" or ", @phrases)) if (scalar(@phrases));
}
if ($rules->{creationDate}) {
my $start = $rules->{creationDate}{start} || 0;
my $end = $rules->{creationDate}{end} || 9999999999999999999999;
push(@clauses, "assetIndex.creationDate between ? and ?");
push(@clauses, "creationDate between ? and ?");
push(@params, $start, $end);
}
if ($rules->{revisionDate}) {
my $start = $rules->{revisionDate}{start} || 0;
my $end = $rules->{revisionDate}{end} || 9999999999999999999999;
push(@clauses, "assetIndex.revisionDate between ? and ?");
push(@clauses, "revisionDate between ? and ?");
push(@params, $start, $end);
}
$self->{_params} = \@params;