Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 UTC on 18 March 2024, to get $100 off your ticket.
I detected that when you edit they keywords of a biblio node the Drupal search is not updated. In the 'update' case of the biblio_nodeapi()
hook search_update_totals()
is called, but this function call does not appear in the update hook biblio_update()
:
case 'update':
if (variable_get('biblio_index', 0)) {
// _node_index_node performs a node_load without resetting the node_load cache,
// so it would index the old version. We reset the cache here.
// Don't assign node_load to $node because node_load resets e.g. the menus mlid etc.
$mynode = node_load($node->nid, NULL, TRUE);
_node_index_node($mynode);
search_update_totals();
}
break;
So I copypasted the update code in the biblio_update()
hook, and everything seems to work smoothly. Edited nodes appear inmediatly both in the Biblio and Drupal search.
/**
* Implementation of hook_update().
*
* As an existing node is being updated in the database, we need to do our own
* database updates.
*/
function biblio_update($node) {
_biblio_prepare_submit($node);
// Update the node in the database:
if ($node->revision) {
drupal_write_record('biblio', $node);
}
else {
drupal_write_record('biblio', $node, 'vid');
}
biblio_save_contributors($node, TRUE);
biblio_save_keywords($node);
// code adition
// copied from biblio_nodeapi() so the search index is updated
$mynode = node_load($node->nid, NULL, TRUE);
_node_index_node($mynode);
search_update_totals();
// end of code adition
}
Sorry I did not create a patch file, I hope this helps.
Comments
Comment #1
franqui CreditAttribution: franqui commentedI haven't tried it, but I expect the same results when deleting a biblio node. Maybe with the same addition in the
biblio_delete()
hook would do.Comment #2
Frank Steiner CreditAttribution: Frank Steiner commentedI'll look at this.
Comment #3
Frank Steiner CreditAttribution: Frank Steiner commentedMan, that was hard to track down.
Ron, I need your help here. The problem comes from the static keyword variable in biblio_load_keywords which is not reset after biblio_save_keywords.
So whatever I do, _node_index_node will call "node_load", which will execute "biblio_load" which calls "biblio_load_keywords". And that returns the keywords from the static variable and so those are indexed, not the new ones. I cannot prevent node_index_node from doing it this way...
Do you see any way to reset the static variable when executing biblio_save_keywords? Like an additional boolean parameter for load_keywords for resetting the static variable, and then save_keywords could call load_keywords once? I'm not sure about this.
@franqui: At my site it doesn't work when copying the code snipped to hook_update additionally, and I don't know how it should. No matter how often you call _node_index_node, it will always fetch the cached keywords from the static variable, i.e., the old ones.
Comment #4
rjerome CreditAttribution: rjerome commentedI surprised that this is causing a problem since I thought that statics only had a lifetime of one "page load", and I would have thought that the load_keywords and save_keywords calls would be on different "page loads". I did notice that it's not really declared correctly, it should be
but I would be surprised if that was causing the problem.
There is probably really no need for a static there anyway since the likelihood of the same vid being loaded twice on the same page is quite low. I can remove it.
Comment #5
rjerome CreditAttribution: rjerome commentedI've removed the static caching in biblio_load_keywords() in the -dev version.
Ron.
Comment #6
Frank Steiner CreditAttribution: Frank Steiner commentedThanks, I will check that! The problem here is that while saving/updating a node the indexing function loads the node again. So while we are still in the same "page load" (which here I guess is the action of "saving the node") we save and load the node (and the keywords).
Comment #7
gpk CreditAttribution: gpk commentedHave you tried clearing the static node cache, like this:
Comment #8
Frank Steiner CreditAttribution: Frank Steiner commentedThat wouldn't influence the keywords as those are a biblio addition.
But it works in 1.7 with the static variable removed. Thanks!