Created
January 6, 2016 18:49
-
-
Save gibrown/23dc6ee65f5bcd41cd09 to your computer and use it in GitHub Desktop.
Query WP posts and weight recent posts more heavily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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