String "0" not printed as suggestion suffix

Created on 11 December 2024, 3 months ago

Problem/Motivation

If the suggestion suffix in search-api-autocomplete-suggestion.html.twig is a string with value "0", the suggestion suffix is not printed.

Steps to reproduce

Example:

  • Autocomplete suggestions for a SKU field activated.
  • We have following SKUs: SKU1, SKU10, SKU11, SKU12
  • Now if we type SKU1, four suggestions are given, but there is two times "SKU1", but "SKU10" is missing.
  • If we instead type only SKU: "SKU1" and "SKU10" are shown.

Proposed resolution

This is because of checking for empty variable in TWIG with {% if suggestion_suffix %}. This gives false if suggestion_suffix string is "0". To avoid this, one should better check like this:{% if suggestion_suffix is not empty %}.

It seems that at least for suggestion_prefix this should be changed too. For results_count probably not, for others I am unsure.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

General code

Created by

πŸ‡©πŸ‡ͺGermany stefan.korn Jossgrund

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @stefan.korn
  • Pipeline finished with Success
    3 months ago
    Total: 177s
    #365766
  • πŸ‡©πŸ‡ͺGermany stefan.korn Jossgrund
  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    drunken monkey β†’ made their first commit to this issue’s fork.

  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    Great catch, thanks a lot for reporting this and already providing an MR.
    Based on a quick test, I think all of those should actually be checked with … is not empty, it seems like '0' (or 0) would be a valid value for all of those (though more likely for some than for others).
    I amended the MR. Please test/review!

  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    *bump* Please test/review so I can merge this.

  • πŸ‡©πŸ‡ͺGermany stefan.korn Jossgrund

    @drunkenmonkey: Sorry, missed the hint about test and review.

    I can confirm that it works for me as expected now with the patch, though I am probably only really testing the suffix/prefix part.

    Regarding the other variables, I do not have a case to test on.

    In principle, I think the "not empty" check is preventing ambiguousness and should be favored. Only with the result count I am in doubt if a value of "0" should be considered empty or is expected to be empty? But is it possible at all to have a result count "0" and appear in the autocomplete suggetions at all?

  • Pipeline finished with Skipped
    about 1 month ago
    #412581
  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    In principle, I think the "not empty" check is preventing ambiguousness and should be favored. Only with the result count I am in doubt if a value of "0" should be considered empty or is expected to be empty? But is it possible at all to have a result count "0" and appear in the autocomplete suggetions at all?

    It’s admittedly unlikely, but since the value can be NULL it should be assumed that 0 represents a valid count that should be reported, I think. If anything, I’d just stick with this for the sake of consistency.

    I merged the MR now. Thanks a lot again!

  • Status changed to Fixed 18 days ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024