Skip to content

Commit

Permalink
Fix: no order by score with empty search phrase
Browse files Browse the repository at this point in the history
Fixes #113
  • Loading branch information
ajaydsouza committed Nov 29, 2024
1 parent 71a7dcf commit a77b002
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions includes/class-better-search-core-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ public function posts_orderby( $orderby, $query ) {
// If orderby is set, then this was done intentionally and we don't make any modifications.
if ( ! empty( $query->get( 'orderby' ) ) ) {
// if orderby is set to relevance, then we need to set the orderby to the match clause.
if ( 'relevance' === $query->get( 'orderby' ) || 'relatedness' === $query->get( 'orderby' ) ) {
if ( ( 'relevance' === $query->get( 'orderby' ) || 'relatedness' === $query->get( 'orderby' ) ) && ! empty( $this->match_sql ) && $this->use_fulltext ) {
$orderby = ' score DESC ';
}
return apply_filters_ref_array( 'better_search_query_posts_orderby', array( $orderby, &$this ) );
Expand All @@ -916,7 +916,7 @@ public function posts_orderby( $orderby, $query ) {
// Initialize an array to build the orderby clauses.
$orderby_clauses = array();

if ( ! empty( $this->use_fulltext ) ) {
if ( ! empty( $this->use_fulltext ) || empty( $this->match_sql ) ) {
$orderby_clauses[] = ' score DESC ';
}

Expand Down

0 comments on commit a77b002

Please sign in to comment.