• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

3rd parameter to \XF\Finder\Phrase::searchText : $prefixMatch = false

DragonByte Tech

Well-known member
#1
So I am currently building an add-on that uses the phrase system to save product titles, and I am creating another page that lists downloads belonging to those products, using the product title to construct the list.

Example:
1512399518589.png

This page is paginated, so I can't use the in-line filtering option, it needs to run an actual search, and in order to search product titles I have to do this:

PHP:
        if (strlen($filter['text']))
        {
            $downloadFinder->Product->MasterTitle->searchText($filter['text']);
        }
This effectively makes the "prefix" checkbox useless, but I can't turn it off from the filter_macros template. Therefore, I propose a change to \XF\Finder\Phrase::searchText that transforms the function into the following:

PHP:
    public function searchText($match, $caseSensitive = false, $prefixMatch = false)
    {
        if ($match)
        {
            $expression = 'phrase_text';
            if ($caseSensitive)
            {
                $expression = $this->expression('BINARY %s', $expression);
            }

            $this->where($expression, 'LIKE', $this->escapeLike($match, $prefixMatch ? '?%' : '%?%'));
        }

        return $this;
    }
Doing this should have no negative impact on existing code anywhere in XF or 3rd party products, and allows the prefix checkbox in the filter macro to do its job.

In addition, it would probably also be beneficial if there was an optional argument (default true) that let you turn off the prefix checkbox, just in case someone wanted to turn it off for whatever reason. Couldn't hurt, right? :p

Thank you for your time.


Fillip