Support » Plugin: ACF: Better Search » Search whole words only

  • Resolved codemonkeynorth

    (@codemonkeynorth)


    Hi,

    if I search ‘oug’ it matches pages with ‘through’ on them.

    Would be great if we could have a setting to ‘match whole words only’

    there’s an implementation here as an idea although some of the code is deprecated
    https://tinygod.pt/make-wordpress-search-exact/

    essentially replacing eg
    $list[] = 'd.post_title LIKE \'%' . $word . '%\'';
    with
    $list[] = 'd.post_title REGEXP \'[[:<:]]'.$word.'[[:>:]]\'';
    etc

    thanks
    J

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @codemonkeynorth,

    Thank you for your message.

    You can do this with the posts_search WordPress filter and create the appropriate regex in it. But that is a very good idea. I will try to implement it in the new version of the plugin.

    This functionality will appear in the latest version of the plugin.

    If you have the opportunity, please test the beta version and give your feedback:
    https://gbiorczyk.pl/acf-better-search-3.5.0.zip

    seems to work well so far. I’ll give it a thorough test tomorrow.

    as per my example “oug” now does not bring back search results, but “through” does… which is what we want

    it also picks up a search for “studies” when the copy is “… studies.”, so it’s correctly ignoring punctuation there which I’d expect from that expression.

    I know regex is supposedly slow, but it’s alright mostly

    thanks for looking into this!

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @codemonkeynorth, please run tests and let me know if I can help you with anything else.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @codemonkeynorth Unfortunately, I have not received any response from you. I have released a plugin update – please download it and test the search.

    If there is a problem, let me know. If I do not receive an answer within the next 7 days, I will close the thread, considering the problem to be resolved.

    Hi Mateusz,

    sorry we’ve been tied up with deadlines!

    All seems good so far, I’ll test this new release out on our dev site

    thanks again for your work
    J.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search whole words only’ is closed to new replies.