[Rt-commit] rt branch, 4.0/fts-mysql-multiple-queries, updated. rt-4.0.4-283-g19e8a32
? sunnavy
sunnavy at bestpractical.com
Fri Feb 10 00:05:10 EST 2012
The branch, 4.0/fts-mysql-multiple-queries has been updated
via 19e8a32a332ca69ba6af5980a5465c75a315cba2 (commit)
from 97e4fed09b396885e5b9db461f8ea50cb78b8265 (commit)
Summary of changes:
lib/RT/Tickets_SQL.pm | 125 ++++++++++++++++++++++++++++---------------------
1 files changed, 71 insertions(+), 54 deletions(-)
- Log -----------------------------------------------------------------
commit 19e8a32a332ca69ba6af5980a5465c75a315cba2
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Feb 10 12:57:59 2012 +0800
put "Content LIKE" combination into method PrepareSQL
diff --git a/lib/RT/Tickets_SQL.pm b/lib/RT/Tickets_SQL.pm
index ec51775..c3c83a7 100644
--- a/lib/RT/Tickets_SQL.pm
+++ b/lib/RT/Tickets_SQL.pm
@@ -294,18 +294,80 @@ sub FromSQL {
return (1, $self->loc("No Query")) unless $query;
$self->{_sql_query} = $query;
+ ( my $ret, $query ) = $self->PrepareSQL( $query );
+ return ( $ret, $query ) unless $ret;
+
+ eval { $self->_parser( $query ); };
+ if ( $@ ) {
+ $RT::Logger->error( $@ );
+ return (0, $@);
+ }
+
+ # We only want to look at EffectiveId's (mostly) for these searches.
+ unless ( exists $self->{_sql_looking_at}{'effectiveid'} ) {
+ #TODO, we shouldn't be hard #coding the tablename to main.
+ $self->SUPER::Limit( FIELD => 'EffectiveId',
+ VALUE => 'main.id',
+ ENTRYAGGREGATOR => 'AND',
+ QUOTEVALUE => 0,
+ );
+ }
+ # FIXME: Need to bring this logic back in
+
+ # if ($self->_isLimited && (! $self->{'looking_at_effective_id'})) {
+ # $self->SUPER::Limit( FIELD => 'EffectiveId',
+ # OPERATOR => '=',
+ # QUOTEVALUE => 0,
+ # VALUE => 'main.id'); #TODO, we shouldn't be hard coding the tablename to main.
+ # }
+ # --- This is hardcoded above. This comment block can probably go.
+ # Or, we need to reimplement the looking_at_effective_id toggle.
+
+ # Unless we've explicitly asked to look at a specific Type, we need
+ # to limit to it.
+ unless ( $self->{looking_at_type} ) {
+ $self->SUPER::Limit( FIELD => 'Type', VALUE => 'ticket' );
+ }
+
+ # We don't want deleted tickets unless 'allow_deleted_search' is set
+ unless( $self->{'allow_deleted_search'} ) {
+ $self->SUPER::Limit( FIELD => 'Status',
+ OPERATOR => '!=',
+ VALUE => 'deleted',
+ );
+ }
+
+ # set SB's dirty flag
+ $self->{'must_redo_search'} = 1;
+ $self->{'RecalcTicketLimits'} = 0;
+
+ return (1, $self->loc("Valid Query"));
+}
+
+=head2 PrepareSQL
+
+Prepare the query.
+
+Returns (1, $query ) on success and (0, 'Error Message') on failure.
+
+=cut
+
+sub PrepareSQL {
+ my $self = shift;
+ my $query = shift;
my $config = RT->Config->Get('FullTextSearch') || {};
if ( $config->{Indexed} && RT->Config->Get('DatabaseType') eq 'mysql' ) {
-# mysql doesn't bother asking sphinx if there are different query clauses.
-# I guess it's because mysql thinks there can't be a field who can meet
-# both "query='foo'' and "query='bar'", so it returns empty set directly.
-# that's why we combine those query into one here.
-# currently only continuous content queries are supported.
+ # mysql doesn't bother asking sphinx if there are different query clauses.
+ # I guess it's because mysql thinks there can't be a field who can meet
+ # both "query='foo'' and "query='bar'", so it returns empty set directly.
+ # that's why we combine those query into one here.
+ # currently only continuous content queries are supported.
my $re_delim = $RE{delimited}{ -delim => qq{\'\"} };
- my $re_content = '(?:^|\s+)Content\s+(?:(NOT)\s+)?LIKE\s+(' . $re_delim . ')';
+ my $re_content =
+ '(?:^|\s+)Content\s+(?:(NOT)\s+)?LIKE\s+(' . $re_delim . ')';
my $first_escaped;
while ( $query =~ /($re_content\s+(AND|OR)\s*$re_content)/i ) {
my $whole = $1;
@@ -344,58 +406,13 @@ sub FromSQL {
}
if ( $query =~ /$re_content.*$re_content/s ) {
- return (0, $self->loc("Incontinuous Content queries"));
+ return ( 0, $self->loc("Incontinuous Content queries") );
}
elsif ( $query =~ /$re_content/ && $1 ) {
- return (0, $self->loc("Single NOT operator is not supported"));
+ return ( 0, $self->loc("Single NOT operator is not supported") );
}
}
-
- eval { $self->_parser( $query ); };
- if ( $@ ) {
- $RT::Logger->error( $@ );
- return (0, $@);
- }
-
- # We only want to look at EffectiveId's (mostly) for these searches.
- unless ( exists $self->{_sql_looking_at}{'effectiveid'} ) {
- #TODO, we shouldn't be hard #coding the tablename to main.
- $self->SUPER::Limit( FIELD => 'EffectiveId',
- VALUE => 'main.id',
- ENTRYAGGREGATOR => 'AND',
- QUOTEVALUE => 0,
- );
- }
- # FIXME: Need to bring this logic back in
-
- # if ($self->_isLimited && (! $self->{'looking_at_effective_id'})) {
- # $self->SUPER::Limit( FIELD => 'EffectiveId',
- # OPERATOR => '=',
- # QUOTEVALUE => 0,
- # VALUE => 'main.id'); #TODO, we shouldn't be hard coding the tablename to main.
- # }
- # --- This is hardcoded above. This comment block can probably go.
- # Or, we need to reimplement the looking_at_effective_id toggle.
-
- # Unless we've explicitly asked to look at a specific Type, we need
- # to limit to it.
- unless ( $self->{looking_at_type} ) {
- $self->SUPER::Limit( FIELD => 'Type', VALUE => 'ticket' );
- }
-
- # We don't want deleted tickets unless 'allow_deleted_search' is set
- unless( $self->{'allow_deleted_search'} ) {
- $self->SUPER::Limit( FIELD => 'Status',
- OPERATOR => '!=',
- VALUE => 'deleted',
- );
- }
-
- # set SB's dirty flag
- $self->{'must_redo_search'} = 1;
- $self->{'RecalcTicketLimits'} = 0;
-
- return (1, $self->loc("Valid Query"));
+ return ( 1, $query );
}
=head2 Query
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list