Automattic / WP-Job-Manager

Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
https://wpjobmanager.com
GNU General Public License v3.0
893 stars 366 forks source link

Expand job listing search #2821

Closed gikaragia closed 1 month ago

gikaragia commented 2 months ago

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:

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

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 in wp-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.


Plugin build for 07706c23923a9764b04c9cad2c9ba2f244912f10
📦 Download plugin zip
▶️ Open in playground
gikaragia commented 1 month ago

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.

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?

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.