Stop avoiding db_rewrite_sql() in node_search()

moshe weitzman - March 18, 2006 - 03:30
Project:Drupal
Version:7.x-dev
Component:search.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (code needs work)
Description

node_search() passes an empty query to db_rewrite_sql() instead of the actaul query to perform. this is not the spirit of this hook. move db_rewrite_sql() call to later during the query build process.

#1

Robrecht Jacques - September 13, 2006 - 18:03

Does this still apply?

I don't find a call to db_rewrite_sql() in node_search(). I do find a _db_rewrite_sql() in node_search('search'). Is that what you mean?

Please elaborate.

#2

moshe weitzman - September 13, 2006 - 20:50
Title:Pass real sql through db_rewrite_sql()» Stop avoiding db_rewrite_sql() in node_search()

yes, i refer to _db_rewrite_sql()

changed title to be more clear.

#3

moshe weitzman - January 6, 2008 - 04:41
Version:x.y.z» 7.x-dev

#4

robertDouglass - April 15, 2008 - 10:28

Yes. This needs to be done as part of a refactoring of do_search since the query fragments present in node_search aren't really sufficient to do the db_rewrite_sql() in their current form. I suppose it belongs in do_search and any specific information that db_rewrite_sql needs has to be passed into do_search as well. Or we make a nice query builder that can replace do_search.

#5

David Lesieur - May 10, 2008 - 22:52
Status:active» patch (code needs work)

LIVE FROM THE MINNESOTA SEARCH SPRINT! Here's a patch that refactors do_search() slightly... It has some pros and cons:

Pros:

  • Private function _db_rewrite_sql() no longer called from node_search(); db_rewrite_sql() is used instead.
  • New function search_build_query() allows modules to get the SQL and then call whatever query function they need (e.g. db_query(), pager_query(), db_query_temporary()).

Cons:

  • An additional query is necessary for finding out whether the search has any results (before, do_search() returned immediately with an empty result set when the normalization query failed).
  • do_search() becomes quite empty and perhaps not very relevant.

However, this patch might become a (small) first step towards a larger issue encompassing search query parsing and building...

AttachmentSize
do_search.patch5.77 KB
 
 

Drupal is a registered trademark of Dries Buytaert.