From: miker Date: Thu, 18 Mar 2010 19:58:48 +0000 (+0000) Subject: support * as a truncation operator in FTS. NOTE: this will require Postgres 8.4... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7b9fb2818d9b7441ddf09ebe42c4ed79bd40dba0;p=evergreen%2Fbjwebb.git support * as a truncation operator in FTS. NOTE: this will require Postgres 8.4 or newer! git-svn-id: svn://svn.open-ils.org/ILS/trunk@15915 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index 56c1fc0aa..16e41de62 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -532,7 +532,14 @@ sub buildSQL { $sql = $n->{function}."($sql)"; } - $sql = "to_tsquery('$classname'," . ($self->prefix ? "\$_$$\$" . $self->prefix . "\$_$$\$||" : '') . "'('||regexp_replace($sql,E'(?:\\\\s+|:)','&','g')||')')"; + my $prefix = $self->prefix || ''; + my $suffix = $self->suffix || ''; + + $prefix = "'$prefix' ||" if $prefix; + my $suffix_op = ":$suffix" if $suffix; + my $suffix_after = "|| '$suffix_op'" if $suffix; + + $sql = "to_tsquery('$classname', $prefix '(' || regexp_replace($sql,E'(?:\\\\s+|:)','$suffix_op&','g') $suffix_after || ')')"; return $self->sql($sql); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/QueryParser.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/QueryParser.pm index 3b7fb335d..1be02e87b 100755 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/QueryParser.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/QueryParser.pm @@ -525,8 +525,9 @@ sub decompose { my $class_node = $struct->classed_node($current_class); my $negator = ($atom =~ s/^-//o) ? '!' : ''; + my $truncate = ($atom =~ s/\*$//o) ? '*' : ''; - $class_node->add_fts_atom( $atom, prefix => $negator, node => $class_node ); + $class_node->add_fts_atom( $atom, suffix => $truncate, prefix => $negator, node => $class_node ); $struct->joiner( '&' ); $_ = $after; @@ -865,6 +866,12 @@ sub prefix { return $self->{prefix}; } +sub suffix { + my $self = shift; + return undef unless (ref $self); + return $self->{suffix}; +} + #------------------------------- package QueryParser::query_plan::filter;