From 58b3128a3aa0fb0be78bc7e012ec1f444a86bda0 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 26 Sep 2006 20:34:59 +0000 Subject: [PATCH] Fixed the search function that broke in 7.0.7. also fixed a user profile problemm --- docs/changelog/7.x.x.txt | 4 +++ docs/gotcha.txt | 8 +++++ docs/upgrades/upgrade_7.0.7-7.0.8.pl | 14 ++++---- lib/WebGUI/Search.pm | 53 +++++++++++++--------------- lib/WebGUI/Search/Index.pm | 4 +-- lib/WebGUI/User.pm | 5 ++- 6 files changed, 51 insertions(+), 37 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ad05f9a89..e2e48d44d 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -27,6 +27,10 @@ - fix: File Upload - documented HTTP file upload size limitations in File Pile Assets Hover help as well as the WebGUI settings documentation for Max Upload size. + - Eliminated several hundred queries to the database during certain user + profile field options. + - Fixed the search function that broke in 7.0.7. + 7.0.7 - rfe: Image Management (funded by Formation Design Systems) diff --git a/docs/gotcha.txt b/docs/gotcha.txt index ce1935aaf..075dd8e75 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -7,6 +7,14 @@ upgrading from one version to the next, or even between multiple versions. Be sure to heed the warnings contained herein as they will save you many hours of grief. +7.0.8 +-------------------------------------------------------------------- + * 7.0.7 was released with a critical bug that broke the search engine + for many sites, but not all. This bug has been corrected and tests + have been written to help ensure it doesn't happen again. However, + as a result you must rerun the search indexer program (sbin/search.pl) + on all your sites. + 7.0.4 -------------------------------------------------------------------- diff --git a/docs/upgrades/upgrade_7.0.7-7.0.8.pl b/docs/upgrades/upgrade_7.0.7-7.0.8.pl index a49fd69fe..42ddde6d2 100644 --- a/docs/upgrades/upgrade_7.0.7-7.0.8.pl +++ b/docs/upgrades/upgrade_7.0.7-7.0.8.pl @@ -20,19 +20,21 @@ my $quiet; # this line required my $session = start(); # this line required fixRobotsTxtMimeType($session); +fixSearch(); # upgrade functions go here finish($session); # this line required -##------------------------------------------------- -#sub exampleFunction { -# my $session = shift; -# print "\tWe're doing some stuff here that you should know about.\n" unless ($quiet); -# # and here's our code -#} +#------------------------------------------------- +sub fixSearch { + print "\tFixing search.\n" unless ($quiet); + $session->db->write("alter table assetIndex add column lineage varchar(255)"); +} + +#------------------------------------------------- sub fixRobotsTxtMimeType { my $session = shift; print "\tFixing MIME type of robots.txt snippet.\n" unless $quiet; diff --git a/lib/WebGUI/Search.pm b/lib/WebGUI/Search.pm index 946406555..467f35c0e 100644 --- a/lib/WebGUI/Search.pm +++ b/lib/WebGUI/Search.pm @@ -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; diff --git a/lib/WebGUI/Search/Index.pm b/lib/WebGUI/Search/Index.pm index a1e5b9385..3433ab654 100644 --- a/lib/WebGUI/Search/Index.pm +++ b/lib/WebGUI/Search/Index.pm @@ -131,10 +131,10 @@ sub create { #-------------------- added by zxp end my $add = $self->session->db->prepare("insert into assetIndex (assetId, title, url, creationDate, revisionDate, - ownerUserId, groupIdView, groupIdEdit, className, synopsis, keywords) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + ownerUserId, groupIdView, groupIdEdit, lineage, className, synopsis, keywords) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"); $add->execute([$asset->getId, $asset->get("title"), $asset->get("url"), $asset->get("creationDate"), $asset->get("revisionDate"), $asset->get("ownerUserId"), $asset->get("groupIdView"), $asset->get("groupIdEdit"), - $asset->get("className"), $synopsis, $keywords]); + $asset->get("lineage"), $asset->get("className"), $synopsis, $keywords]); return $self; } diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 3ed07e1d3..5df481e48 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -439,7 +439,10 @@ sub profileField { $self = shift; $fieldName = shift; $value = shift; - die "No such profile field: $fieldName" unless $self->session->db->quickArray("SELECT COUNT(*) FROM userProfileField WHERE fieldName = ?", [$fieldName]); + if (!exists $self->{_profile}{$fieldName} && !$self->session->db->quickArray("SELECT COUNT(*) FROM userProfileField WHERE fieldName = ?", [$fieldName])) { + $self->session->warn("No such profile field: $fieldName"); + return undef; + } if (defined $value) { $self->uncache; $self->{_profile}{$fieldName} = $value;