[Rt-commit] r8047 - rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Search/Elements

ruz at bestpractical.com ruz at bestpractical.com
Sat Jun 30 22:30:39 EDT 2007


Author: ruz
Date: Sat Jun 30 22:30:39 2007
New Revision: 8047

Modified:
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Search/Elements/ProcessQuery

Log:
* get rid of another code duplication of queries parser we have

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Search/Elements/ProcessQuery
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Search/Elements/ProcessQuery	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Search/Elements/ProcessQuery	Sat Jun 30 22:30:39 2007
@@ -47,40 +47,12 @@
 
 # {{{ Parse the query
 my $ParseQuery = sub {
-    my ($string, $results) = shift;
+    my ($string, $results) = @_;
 
-    my %field = %{ RT::Tickets->new( $session{'CurrentUser'} )->FIELDS };
-    my %lcfield = map { ( lc($_) => $_ ) } keys %field;
+    use RT::Interface::Web::QueryBuilder::Tree;
+    my $tree = RT::Interface::Web::QueryBuilder::Tree->new('AND');
+    @$results = $tree->ParseSQL( Query => $string, CurrentUser => $session{'CurrentUser'} );
 
-    my ($tree, $node);
-    $node = $tree = RT::Interface::Web::QueryBuilder::Tree->new('AND');
-
-    my %callback;
-    $callback{'OpenParen'} = sub {
-        $node = RT::Interface::Web::QueryBuilder::Tree->new( 'AND', $node );
-    };
-    $callback{'CloseParen'} = sub { $node = $node->getParent };
-    $callback{'EntryAggregator'} = sub { $node->setNodeValue( $_[0] ) };
-    $callback{'Condition'} = sub {
-        my ($key, $op, $value) = @_;
-
-        my $class;
-        if ( exists $lcfield{ lc $key } ) {
-            $key   = $lcfield{ lc $key };
-            $class = $field{$key}->[0];
-        }
-        unless( $class ) {
-            push @$results, [ loc("Unknown field: $key"), -1 ]
-        }
-
-        $value = "'$value'" if $value =~ /[^0-9]/;
-        $key = "'$key'" if $key =~ /^CF./;
-
-        my $clause = { Key => $key, Op => $op, Value => $value };
-        $node->addChild( RT::Interface::Web::QueryBuilder::Tree->new( $clause ) );
-    };
-
-    RT::SQL::Parse($string, \%callback);
     return $tree;
 };
 


More information about the Rt-commit mailing list