-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand job listing search #2821
Conversation
This expands job listing meta and term search to have similar functionality to WP core's search. As the core's search includes clauses that are aggregated with ORs and ANDs, the only way to include meta fields in this search was to rebuild the search query from scratch. With this change, get_job_listings_keyword_search generates the clauses that are generated in WP_Query::parse_search and adds additional clauses that search the post meta and terms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working great! Added a few questions and noticed one issue, but generally code looks good too.
$conditions = apply_filters( 'job_listing_search_conditions', $conditions, $job_manager_keyword ); | ||
if ( empty( $conditions ) ) { | ||
return $search; | ||
$default_search_columns = [ 'post_title', 'post_excerpt', 'post_content' ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more big improvement to the search would be to prioritize matches in the title — and generally to sort results by relevance. Maybe we could do multiple searches, first just in the post title, then in content, metas? It could actually be faster for the first pages in some cases, since if there are enough results in the title, we don't need to do the content/meta searches.
Just bringing it up to discuss here, it'd be its own PR probably as there would be some extra complexity, like handling pagination. Could also do some weighting maybe?
fb592cd
to
d8c2737
Compare
In this PR I focused on fixing what seemed like buggy behavior. Although we included some meta fields in searches, it didn't work as expected previously and returned weird results.
These are great suggestions, there is a lot of room for improvement. We could look into implementing these in the future. Another option would be to integrate with plugins that expand WP's search capabilities as it has been suggested in the past. |
Fixes #2749
Overview
There are many requests for improving the job search functionality in #1707. The most frequent one being to allow an 'OR' operator when searching. So if for example, a user enters 'software engineer' in search then the listings that contain either 'software' or 'engineer' should be returned. I don't think that we should make this the default behavior as:
If we want to ever allow this, we should specifically support 'OR' and 'AND' operators.
Another, confusing part is that WP core search does partial searches which means that if someone searches for "Java" it will return listings that contain "JavaSript".
Finally, there are also the issues mentioned in #2749. We currently also search the meta fields but not in a consistent way with core. We also don't support negations (-) and phrase searches ("") for meta fields and categories.
This PR solves the issues in #2749 by providing the same functionality for meta and term searches with WP Core (which searches title content and excerpt). This means that for meta and categories:
Changes Proposed in this Pull Request
job_listing_search_conditions
hook as it wasn't possible to maintain anymore. Users can always override the wholeget_job_listings_keyword_search
function with the previous version to revert to the previous functionality.Testing Instructions
Release Notes
New or Updated Hooks and Templates
job_listing_search_conditions: Removed as it isn't possible to have it anymore. Users can rollback to previous functionality by overriding
get_job_listings_keyword_search
inwp-job-manager-functions.php
Next Steps
Regarding further improvements in job listing search in general I think that we should avoid them as I think that the implementation is already complex. Any future steps should instead focus on integrating with well known plugins that expand core WP search.