我有一个简单的问题。我有一个apache solr视图,显示为特定节点发布的注释计数。当有人删除评论时,计数不会反映在那里。但是,如果添加了新评论,则在删除评论后,计数再次正常运行。
我在apachesolr_mark_entity()
内尝试了apachesolr_remove_entity()
和hook_comment_delete()
个功能,但没有成功。
有谁知道背后的原因可能是什么?
提前致谢...
答案 0 :(得分:0)
现有的apache solr模块似乎存在问题。
我想出了一个解决方法。如果他们找到更好的解决方案,将来发现这个帖子的任何人都会发帖。
/**
* Implements hook_comment_delete().
*/
function yourmodulename_comment_delete($comment) {
// While deleting a comment, the apache solr comment count field,
// "is_comment_count" does not get updated unlike comment addition. The reason
// is while deletion the apache solr module updates the comment entity but not
// the corresponding node entity. Hence the node needs to be explicitely re-
// indexed. Since I am already using the "apachesolr_realtime" module , the
// "apachesolr_realtime_index_now" function has been used for this purpose.
// Get the parent node of which this comment belongs to.
$parent_entity = entity_load('node', array($comment->nid), array(), TRUE);
$parent_entity = $parent_entity[key($parent_entity)];
// When the hook_comment_delete function is invoked, the comment count is
// still not reduced. Hence, drupal_register_shutdown_function has been used so that
// the call to apachesolr_realtime_index_now is invoked only after the comment
// and it's corresponding count has been uodated.
drupal_register_shutdown_function('apachesolr_realtime_index_now', $parent_entity, 'node');
}
由于