Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#36195 closed defect (bug) (fixed)

Search for something with ' - ' will always return nothing

Reported by: romsocial's profile RomSocial Owned by: boonebgorges's profile boonebgorges
Milestone: 4.4.3 Priority: normal
Severity: normal Version: 4.4
Component: Query Keywords: fixed-major
Focuses: Cc:

Description

On fresh Wordpress install with stock theme, if I create post with the title:
"Great new post - now!" and publish it,

And I search for "Great new post" it will work.
But if I search for "Great new post - now" with or without quotes it will not work.
Even if I search for "Great new post – now" with or without quotes it returns nothing.

that seems to be happening because ' - ' gets converted to:

AND ((wp_posts.post_title NOT LIKE '%%') AND (wp_posts.post_content NOT LIKE '%%'))

And even though ndash gets converted into:

AND ((wp_posts.post_title LIKE '%–%') OR (wp_posts.post_content LIKE '%–%'))

it's not in the database either.

So, I would suggest to patch the

/wp-includes/query.php:2180
--- $include = '-' !== substr( $term, 0, 1 );
+++ $include = '-' !== substr( $term, 0, 1 ) || strlen($term) == 1;

Or something to this effect.

Attachments (1)

36195.diff (1.7 KB) - added by swissspidy 8 years ago.

Download all attachments as: .zip

Change History (8)

@swissspidy
8 years ago

#1 @swissspidy
8 years ago

  • Keywords has-patch has-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 4.4.2 to 4.4

#2 @boonebgorges
8 years ago

@RomSocial Thanks for the helpful bug report, and welcome to WordPress Trac!

@swissspidy I see you changed the version to 4.4 - is this a regression in 4.4?

#3 follow-up: @swissspidy
8 years ago

@boonebgorges Wasn't $s updated to support excluded search terms in 4.4?

#4 in reply to: ↑ 3 @boonebgorges
8 years ago

  • Milestone changed from Future Release to 4.4.3
  • Owner set to boonebgorges
  • Status changed from new to assigned

Replying to swissspidy:

@boonebgorges Wasn't $s updated to support excluded search terms in 4.4?

Oh right. Whoops. Let's slate this for a potential 4.4.3. It's minor but definitely a regression.

#5 @boonebgorges
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 36989:

Query: Ignore search terms consisting of a single dash.

Due to the "exclude" support added in WP 4.4, single dashes were being
converted to "NOT LIKE '%%'" clauses, causing all searches to fail.

Props RomSocial, swissspidy.
Fixes #36195.

#6 @boonebgorges
8 years ago

  • Keywords fixed-major added; has-patch has-unit-tests removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 4.4.3.

#7 @boonebgorges
8 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 37082:

Query: Ignore search terms consisting of a single dash.

Due to the "exclude" support added in WP 4.4, single dashes were being
converted to "NOT LIKE '%%'" clauses, causing all searches to fail.

Ports [36989] to the 4.4 branch.

Props RomSocial, swissspidy.
Fixes #36195.

Note: See TracTickets for help on using tickets.