[wp-trac] [WordPress Trac] #43634: WP_Query returns wrong result if 10+ search terms and all negative.
WordPress Trac
noreply at wordpress.org
Mon Mar 26 15:09:44 UTC 2018
#43634: WP_Query returns wrong result if 10+ search terms and all negative.
-------------------------------+-----------------------------
Reporter: johnh10 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------------+-----------------------------
Set up: create single post with title or body "Don't match this one!"
Use WP_query with 's' parameter:
{{{
-one -two -three -four -five -six -seven -eight -nine -ten
}}}
WP_Query will find and return the single post and it shouldn't.
Less than 10 negative search terms works fine.
I believe it has to do with a special 'if clause' in the function
'''parse_search''' in ''class-wp-query.php''
{{{
// if the search string has only short terms or stopwords, or is 10+ terms
long, match it as sentence
if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ) {
$q['search_terms'] = array( $q['s'] );
}
}}}
this makes
{{{
JPH q['search_terms'] : Array
(
[0] => -one -two -three -four -five -six -seven -eight -nine -ten
)
}}}
and later in the function the search variable becomes
{{{
JPH search variable is: AND (((testsite_posts.post_title NOT LIKE
'{07e030b91cb064568b0acafd83d99152667b06f2ffd415e48cd2d2f458c2c217}one
-two -three -four -five -six -seven -eight -nine
-ten{07e030b91cb064568b0acafd83d99152667b06f2ffd415e48cd2d2f458c2c217}')
AND (testsite_posts.post_excerpt NOT LIKE
'{07e030b91cb064568b0acafd83d99152667b06f2ffd415e48cd2d2f458c2c217}one
-two -three -four -five -six -seven -eight -nine
-ten{07e030b91cb064568b0acafd83d99152667b06f2ffd415e48cd2d2f458c2c217}')
AND (testsite_posts.post_content NOT LIKE
'{07e030b91cb064568b0acafd83d99152667b06f2ffd415e48cd2d2f458c2c217}one
-two -three -four -five -six -seven -eight -nine
-ten{07e030b91cb064568b0acafd83d99152667b06f2ffd415e48cd2d2f458c2c217}')))
AND (testsite_posts.post_password = '')
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43634>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list