Skip to content

Commit

Permalink
fix: allow to query tags without normalization (#11008)
Browse files Browse the repository at this point in the history
This is to be able to run commands with update_all_products.pl like:

./scripts/update_all_products.pl --query
categories_tags=en:some-old-entry-that-is-now-a-synonym!

the ending ! means that the value should not be normalized with the
taxonomy, but instead should be searched for as specified in mongodb
  • Loading branch information
stephanegigandet authored Nov 14, 2024
1 parent 3551ef8 commit d8f4a2b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4920,9 +4920,17 @@ sub add_params_to_query ($params_ref, $query_ref) {
foreach my $tag2 (split(/\|/, $tag)) {
my $tagid2;
if (defined $taxonomy_fields{$tagtype}) {
$tagid2 = get_taxonomyid($tag_lc, canonicalize_taxonomy_tag($tag_lc, $tagtype, $tag2));
if ($tagtype eq 'additives') {
$tagid2 =~ s/-.*//;
# if the tagid ends with !, we want to search for products with this exact tag, without canonicalization
# this is useful in particular when we change the main id of a tag entry in the taxonomy,
# so that we can find products that have not been reprocessed yet and that still have the old tag
if ($tag2 =~ /^([a-z]{2}:.*)!$/) {
$tagid2 = $1;
}
else {
$tagid2 = get_taxonomyid($tag_lc, canonicalize_taxonomy_tag($tag_lc, $tagtype, $tag2));
if ($tagtype eq 'additives') {
$tagid2 =~ s/-.*//;
}
}
}
else {
Expand Down Expand Up @@ -4951,9 +4959,17 @@ sub add_params_to_query ($params_ref, $query_ref) {
else {
my $tagid;
if (defined $taxonomy_fields{$tagtype}) {
$tagid = get_taxonomyid($tag_lc, canonicalize_taxonomy_tag($tag_lc, $tagtype, $tag));
if ($tagtype eq 'additives') {
$tagid =~ s/-.*//;
# if the tagid ends with !, we want to search for products with this exact tag, without canonicalization
# this is useful in particular when we change the main id of a tag entry in the taxonomy,
# so that we can find products that have not been reprocessed yet and that still have the old tag
if ($tag =~ /^([a-z]{2}:.*)!$/) {
$tagid = $1;
}
else {
$tagid = get_taxonomyid($tag_lc, canonicalize_taxonomy_tag($tag_lc, $tagtype, $tag));
if ($tagtype eq 'additives') {
$tagid =~ s/-.*//;
}
}
}
else {
Expand Down

0 comments on commit d8f4a2b

Please sign in to comment.