From: Thomas Berezansky Date: Wed, 12 Sep 2012 13:12:41 +0000 (-0400) Subject: QueryParser Driver: Improve anchored searches X-Git-Tag: sprint4-merge-nov22~3449 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0db54b56c88e540a44f1af2dbec126dd3c6409ba;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 Signed-off-by: Lebbeous Fogle-Weekley --- 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 c0e345b88c..358972ebee 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 @@ -827,7 +827,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') { @@ -922,6 +922,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; @@ -1230,6 +1234,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};