[wp-trac] [WordPress Trac] #54853: Search only searching phrases and not searching individual terms

WordPress Trac noreply at wordpress.org
Wed Jan 19 07:46:09 UTC 2022


#54853: Search only searching phrases and not searching individual terms
--------------------------+------------------------------
 Reporter:  jchang        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  5.8.3
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+------------------------------

Comment (by jchang):

 Replying to [comment:2 SergeyBiryukov]:
 > Hi there, welcome to WordPress Trac! Thanks for the ticket.
 >
 > > {{{
 > > get_posts(array(
 > >   "post_type" => "fruit",
 > >   "s" => "apple orange banana"
 > > ));
 > > }}}
 > >
 > > should search for each term separately, but it does not. It searches
 the entire string as a phrase.
 >
 > Just noting that the search ordering logic is slightly more advanced.
 >
 > Some history here:
 > * [4426] / #3177 (WordPress 2.1+) allowed "quoted strings" to be used in
 searches for exact matches.
 > * [25632] / #7394 (WordPress 3.7+) orders search results by relevance,
 rather than by date.
 >
 > > The ordering logic is as follows:
 > > * Full sentence matches in post titles.
 > > * All search terms in post titles.
 > > * Any search terms in post titles.
 > > * Full sentence matches in post content.
 > > Each section and any remaining posts are then sorted by date.
 >
 > Additionally, `WP_Query::parse_query()` has a [source:tags/5.8.3/src/wp-
 includes/class-wp-query.php?marks=723#L717 'sentence' argument] that
 controls whether to search by phrase.
 >
 > So it seems to me that the default search behavior works as intended and
 documented, I don't see a bug here. As noted above, this can be customized
 using the `posts_search` or `posts_search_orderby` filters.

 If left as it is, the "sentence" argument would have no effect on the
 outcome of a search. The documented behavior says it should search each
 term individually unless "sentence" is set to true (defaults to false).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54853#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list