No results found when searching both body and title (fix)

beertje - January 23, 2009 - 08:37
Project:Search and Replace
Version:6.x-1.1-beta1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

I noticed search_and_replace does not display any links when you search for something in both title and body that only occurs in node bodies. It just says: "x results found in the following node bodies and titles:" and then nothing.

As it turned out this was just a minor shortcoming in the code, so I made a patch. I'm sure there are different, and possible better, ways of doing this but for now it just works.

AttachmentSize
search_and_replace.patch2.64 KB

#1

frewfrux - January 30, 2009 - 17:53

Will this patch only work for the 6.x version? I have the same issue, but with the 5.x version.

#2

beertje - February 11, 2009 - 22:37

Prob. only with the 6.x version. The patch is really simple though, just a few lines of code. So by looking at the patch, you should get a pretty good idea what to do to fix the 5.x version.

Basicly this is what happens with the original code (IIRC that is): first a node's body is searched for a term and then the node's title. If a match is found in the node's body but not in the node's title, the variable that stores the link to the node gets overridden by nothing and hence doesn't show up in the results at all. So all that needs to be done is to add an extra variable for the node's title, so it doesn't get in the way of results for the node's body.

A rather silly bug if you ask me...

To make things even worse, if you look at the code you'll see that every node get's overridden, even when you just do a search!!! This can lead to problems when you use pathauto I noticed. So stay away from this module if you can!

#3

btopro - February 12, 2009 - 03:42
Status:active» needs review

thanks for the patch I'll look at it tomorrow.

err...explain what you mean by "node get's overridden"? Are you talking about the fact that I load up and then modify the title of nodes and could potentially change a title and then it not match with the pathauto name? I think it would actually be more dangerous to change the pathauto generated path because that could break linkage within the site if you do it to a node's name and have made the change.

#4

beertje - February 12, 2009 - 11:19

I'm talking about the 'node_save($node);' part. Not sure what that does all together, but we were having trouble with a site that uses the search and replace module. Whenever we did a search (not search and replace) there were some drupal errors and paths like '/feed' were showing up in the database for the nodes the errors revered to. IIRC it looked like the combination of manual entered paths and pathauto were causing problems. I fixed the errors by setting pathauto not to save the path on update.

#5

btopro - February 12, 2009 - 13:03
Status:needs review» postponed (maintainer needs more info)

IIIIIII see. Hmm... so it sounds like what you're saying is that when titles got changed (or didn't cause node_save still ran) that it goofed up some links you had manually entered to override the pauthauto generated links. node_save is the function used to run everything that should happen upon saving a node to the database (part of which is pathauto if it's on I guess).

I'll have to look into this a bit more deeply but I see what you're saying. At the very least I should be able to fix it up so that it stops running node_save when it's just searched nodes and not done replacements. Maybe it's also a good idea if I give a warning with doing replacements on node titles as it can adversely affect paths dictated by pathauto / overridden by the user. I don't think I can account for the user having pathauto and behave differently because I don't want to override the user's settings for having pathauto auto update. If you save a node w/ an overridden path and then hit edit again and save it again I think it'll change the path. If that's not true please correct me and I'll see how I can fix it for this module but I believe that's how it works.

#6

beertje - February 13, 2009 - 09:06
Status:postponed (maintainer needs more info)» needs review

I've tested it for a node I know caused problems before with search and replace. When I leave 'automatic alias' ticked, the path that was entered manually before just disappears from the url_alias table, and with the default feed alias 'feed' a funny alias '/feed' (note the slash) is created. So it's a problem with pathauto settings, however since s&r updates all nodes by default things could get very messy!

#7

btopro - February 19, 2009 - 20:04
Status:needs review» fixed

I've also added a line that sees if the body / title have had changes committed to them. If not it doesn't save them so it won't do a save EVERY time like it was before (thanks for pointing that out).

I'll have a beta2 out shortly though I'm still looking for something to fix the issues with backslash character replacement.

#8

beertje - February 20, 2009 - 11:21

Thank you!

However now I get:

warning: Missing argument 1 for search_and_replace_menu() in /var/www/html/Projecten/sbo/webroot/sites/all/modules/search_and_replace/search_and_replace.module on line 41.

It seems drupal does not provide the may_cache argument to function search_and_replace_menu($may_cache). Also I'm missing the special permission for search_and_replace?

#9

System Message - March 6, 2009 - 11:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.