Bug #15648


Group forum search doesn't always return correct results

Added by Boone Gorges about 2 years ago. Updated almost 2 years ago.

Priority name:
Category name:
Group Forums
Target version:
Start date:
Due date:
% Done:


Estimated time:
Deployment actions:


From #15646:

2. Failed Search: My browsing through the forum post list was occasioned by a failed search. I was looking for "excellence fee" in this private group - . When I searched for those words, with or without quotation marks, nothing came up. But, as evidenced by this post -- -- there was a post with the subject "excellence fee" included (fyi, I tried both "fee" and "fees")

Ray, could you have a look? I wonder whether it has to do with private posts.

Related issues

Related to CUNY Academic Commons - Feature #15646: Forum improvementsDuplicateBoone Gorges2022-03-16

Actions #1

Updated by Boone Gorges about 2 years ago

Actions #2

Updated by Raymond Hoh about 2 years ago

This bug is caused when searching for multiple terms due to unnecessary sanitizing of the search terms. I've just fixed this in the following commit: This should fix the immediate issue. I'm going to push this fix to 1.19.x branch as well.

As far as searching with quotations around the search term, forum search (and WordPress) doesn't support this functionality natively. Was surprised to find that no-one had attempted to add this functionality, so I've written some code to allow searches wrapped with double quotations here: What I'm doing in this code snippet is removing double-quoted search terms from the 's' field and then appending the double-quoted search term to the end of the SQL query. Boone, can you take a look to see if there are any problems with this approach before I commit this? I've opted to do this sitewide, rather than limit this functionality to forum search because I think this would be really beneficial on the frontend as well as in the admin area. But if we wanted to only limit this to forum search, we could do that as well.

When combined with WP's native exclusion search terms support, it would be possible to do a search like this:

"match this" -notthis -orthis

So the search would include posts for match this exactly and omit posts including notthis or orthis. This could really help users trying to find something specific.

Actions #3

Updated by Boone Gorges about 2 years ago

Thanks for the digging here, Ray. The general approach looks good to me, and I agree that it should be useful sitewide.

This is only sort of related, but I wrote something similar for the OpenLab a few years ago - it adds support for quoted search and also wildcards for BP search.

Actions #4

Updated by Raymond Hoh almost 2 years ago

  • Status changed from New to Staged for Production Release

I've added the code snippet here:

Double-quoted searches can now be tested on cdev. Try in a group forum or if you are an administrator of a sub-site, try doing a double-quoted search when on the "Posts" admin dashboard page. On the "Appearance > Widgets" page, you can also add the "Search" widget to your site; then on the frontend, you can use the Search widget to do a double-quoted search as well.

Actions #5

Updated by Boone Gorges almost 2 years ago

  • Status changed from Staged for Production Release to Resolved

Also available in: Atom PDF