From: Thomas Berezansky Date: Wed, 12 Sep 2012 13:12:41 +0000 (-0400) Subject: QueryParser Driver: Improve anchored searches X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=da6dd5ee9c2cb144f860bdf7c7105bad714eaeb3;p=working%2FEvergreen.git QueryParser Driver: Improve anchored searches By checking individual atoms for ^ and $ anchors we can get better results, without needing to have people quote individual terms. Signed-off-by: Thomas Berezansky --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index 05e55d4c92..ee608b8723 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -825,7 +825,7 @@ sub rel_bump { my $bump = shift; my $multiplier = shift; - my $only_atoms = $node->only_atoms; + my $only_atoms = $node->only_real_atoms; return '' if (!@$only_atoms); if ($bump eq 'first_word') { @@ -920,6 +920,10 @@ sub flatten { $where .= '(' . $talias . ".id IS NOT NULL"; $where .= ' AND ' . join(' AND ', map {"${talias}.value ~* ".$self->QueryParser->quote_phrase_value($_)} @{$node->phrases}) if (@{$node->phrases}); $where .= ' AND ' . join(' AND ', map {"${talias}.value !~* ".$self->QueryParser->quote_phrase_value($_)} @{$node->unphrases}) if (@{$node->unphrases}); + for my $atom (@{$node->only_real_atoms}) { + next unless $atom->{content} && $atom->{content} =~ /(^\^|\$$)/; + $where .= " AND ${talias}.value ~* ".$self->QueryParser->quote_phrase_value($atom->{content}); + } $where .= ')'; push @rank_list, $node_rank; @@ -1228,6 +1232,18 @@ sub only_atoms { return \@only_atoms; } +sub only_real_atoms { + my $self = shift; + + my $atoms = $self->query_atoms; + my @only_real_atoms; + for my $a (@$atoms) { + push(@only_real_atoms, $a) if (ref($a) && $a->isa('QueryParser::query_plan::node::atom') && !($a->{dummy})); + } + + return \@only_real_atoms; +} + sub dummy_count { my $self = shift; return $self->{dummy_count};