Collection filtering not working when query is numbers only

  • I have a search results page that works like this:



    That last 'keywords' region is a simple textarea where the client can add keywords separated by spaces to return the item in a search. This is working great, except when the keyword is all numbers with no letters (client is mainly using this functionality for variations on part numbers). So for example, "01884433CX" works, "01-888456" works because it has a dash, but "01888456" doesn't.


    What can I do to make the filter also look for number-only matches?


    Thanks,

    Shane

  • drewm

    Approved the thread.
  • Hey Drew,


    Looking at the debug messages, it looks like the leading 0 on the second query is somehow getting trimmed off when Runway creates the REGEXP for SQL. This only happens if the query is all numbers, it doesn't get trimmed off when there's a letter or dash in the query.


    This works (keyword "01884373C"):


    This doesn't (keyword "01988614"):

  • Add _{0} onto the end of your $search_query:

    Code
    1.     [
    2. 'filter'=>'part_number',
    3. 'match'=>'contains',
    4. 'value'=>$search_query . '_{0}'
    5. ]

    This is will stop Perch casting the value to a number (because it's now not numeric) but it won't impact the result of the regular expression.