Regex in refbase

  • timt

    The issue you're seeing is due to the parentheses in the title. By default, refbase interprets search queries as regualr expression.

    This gets in the way here, and, in this case, refbase should probably escape the query string. That's actually only half of the story, since under the hood, things are even more complicated (due to two different search variants being used), but that's probably something for another thread.

    If one were to try to create a fix for this problem, where would be the place to start?

  • Hi Tim,

    if you just want to suppress regular expression searches for the Quick Search field (i.e. the search field at the top right of the refbase pages), you could go to function 'extractFormElementsQuick()' in file 'search.php' and change the two last occurrences of "RLIKE" to just "LIKE" (in lines 5219 and 5226, for refbase-0.9.5). In other words, change this line:

    "_query"   => $userMainField . " RLIKE " . quote_smart($quickSearchName));

    to this:

    "_query"   => $userMainField . " LIKE " . quote_smart($quickSearchName));

    Similarily, change this line:

    "_query"   => $quickSearchSelector . " RLIKE " . quote_smart($quickSearchName));

    into this:

    "_query"   => $quickSearchSelector . " LIKE " . quote_smart($quickSearchName));

    Note that when using "… LIKE …" the characters "%" and "_" are still regarded as wildcard characters:

    %  -> Matches any number of characters, even zero characters.
    _  -> Matches exactly one character.

    See the MySQL docs for more info:

    If you want to suppress regular expression searches everywhere, then things might get a bit more tricky, but I'd have to think about that in more detail.

    HTH, Matthias