Skip to content
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

Search: add filters to allow customization of the search algorithm #7975

Open
jeherve opened this Issue Oct 11, 2017 · 7 comments

Comments

Projects
None yet
5 participants
@jeherve
Copy link
Member

jeherve commented Oct 11, 2017

We do weight the default search query to boost recent content higher
https://github.com/Automattic/jetpack/blob/5.4/modules/search/class.jetpack-search.php#L906

It would be nice if such parameters could be filtered by site owners, so they can for example give more recent posts a bigger boost.

Read more about it in 1115-gh-jpop-issues

@tmmbecker

This comment has been minimized.

Copy link

tmmbecker commented Oct 12, 2017

Some useful feedback in 725559-zen as to the filters that he's set up for WordPress search that weren't working in Jetpack search.

We’ve modified the search query to sort by date displaying the newest stories first.

// Sort search results by date
function my_sort_search_query( $query ) {
	// not an admin page and is the main query
	if ( ! is_admin() && $query->is_main_query() ) {
		if ( is_search() ) {
			$query->set( 'orderby', 'date' );
		}
	}
}
add_action( 'pre_get_posts', 'my_sort_search_query' );

The built-in WordPress search adheres to our function limiting the amount of posts that display per page on archives and search results. The Jetpack Search, however, did not.

// Limit the number of posts per page in archives and search results
function my_archive_mod( $query ) {
	// Don't change in WordPress admin.
	if ( is_admin() || ! $query->is_main_query() ) {
		return;
	}

	// Display only 20 posts for the original blog archive.
	if ( $query->is_main_query() ) {
		$query->set( 'posts_per_page', '20' );
	}
}
@douglsmith

This comment has been minimized.

Copy link

douglsmith commented Nov 22, 2017

Another use case would be to boost WooCommerce products so a store / site would show those before blog posts or page content.

@ebinnion ebinnion added this to the 5.8 milestone Jan 5, 2018

@gibrown

This comment has been minimized.

Copy link
Member

gibrown commented Jan 25, 2018

Going to have to punt on adding boosting by post type for the next release too many dependencies. Adjusting scores by recency should make it in.

Just adding some notes on boosting.

The way I want to do this looks something like:

		$boosted_post_types = apply_filters(
			'jetpack_search_boost_post_types',
			array(),
			$args
		);

		if ( ! empty( $boosted_post_types ) ) {
			$parser->add_weighting_function( array(
				'filter' => array( 'terms' => array( 'post_type' => $boosted_post_types ) ),
				'weight' => 6.0,
			) );
		}

Three problems:

  1. add_weighting_function() is not yet ported from WP.com to Jetpack. This is the main blocker. Too close to code freeze to get it in.
  2. Need a better way to boost by the weight
  3. This is probably not the only case we want to easily boost on a single matching field, so should probably make this more generic.

@gibrown gibrown changed the title Search: add filter to allow customization of the search algorithm Search: add filters to allow customization of the search algorithm Jan 25, 2018

@gibrown

This comment has been minimized.

Copy link
Member

gibrown commented Jan 26, 2018

The parts of this that are going to make it into 5.8 have been merged, so I am removing from that milestone. I want to get to the other ideas, but am worried they are too big of a change and that I am not sure what the filters should look like yet. Suspect the query will change some more.

@gibrown gibrown removed this from the 5.8 milestone Jan 26, 2018

@gibrown

This comment has been minimized.

Copy link
Member

gibrown commented Feb 21, 2018

A request for boosting by post type more easily (this is the same as the boosting of products mentioned above): https://wptavern.com/jetpack-5-8-adds-lazy-loading-for-images-module#comment-244890

I think there should be an easy filter for doing this boosting.

@gibrown

This comment has been minimized.

Copy link
Member

gibrown commented May 9, 2018

Should probably boost by title a bit more than we currently are. Especially comes up for older posts where there are many other posts with similar content. Example post when searching for exact title: https://fabiusmaximus.com/2006/01/31/myth/

Maybe try a 4x boost rather than 2x on title.

Also kinda related to #9426

Having an easier way to adjust the boosting for different fields would also help here a lot I think.

@stale

This comment has been minimized.

Copy link

stale bot commented Nov 5, 2018

This issue has been marked as stale. This happened because:

  • It has been inactive in the past 6 months.
  • It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

@stale stale bot added the [Status] Stale label Nov 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.