Skip to content

Instantly share code, notes, and snippets.

@gibrown
Created January 6, 2016 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gibrown/23dc6ee65f5bcd41cd09 to your computer and use it in GitHub Desktop.
Save gibrown/23dc6ee65f5bcd41cd09 to your computer and use it in GitHub Desktop.
Query WP posts and weight recent posts more heavily
//These are some params I've used elsewhere, may want to try adjusting
$date_scale = '5d';
$date_decay = 0.99999;
$date_origin = date( 'Y-m-d' );
$query = array(
'query' => array(
"function_score" => array(
'query' => array( 'filtered' => array(
'query' => array( 'multi_match' => array(
'query' => $query,
'fields' => array( 'content', 'title', 'tag.name', 'category.name', 'author' ),
'cross_fields' => true, //look for each word in any field rather than all words in one field
'operator' => 'and',
) ),
'filter' => $filter, //whatever filter you have
) ),
"functions" => array(
array(
'gauss'=> array(
'date_gmt' => array(
'origin' => $date_origin,
'scale' => $date_scale,
'decay' => $date_decay
)
)
)
),
'score_mode' => 'multiply',
'boost_mode' => 'multiply',
) )
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment