【问题标题】:Apache Solr comment count not updatedApache Solr 评论计数未更新
【发布时间】:2016-10-07 06:24:38
【问题描述】:

我有一个简单的问题。我有一个 apache solr 视图,它显示为特定节点发布的 cmets 的计数。当有人删除评论时,计数不会反映在那里。但是,如果添加了新评论,则删除评论后,计数会再次正常工作。

我在hook_comment_delete() 中尝试过apachesolr_mark_entity()apachesolr_remove_entity() 函数,但没有成功。

有谁知道这背后的原因是什么?

提前谢谢...

【问题讨论】:

  • 视图显示drupal节点对应的结果以及每个节点的cmet数量,对吗?
  • 能直接在Solr中看到吗?如果是,请尝试发出提交并查看它是否消失。如果它消失了,则表明 Drupal 模块忘记了提交命令。
  • @ericLavault:没错。我正在使用前面提到的 apache solr 视图和is_comment_count solr 字段来显示该特定drupal 节点的计数。 @AlexandreRafalovitch:是的,我已经直接签入了 solr,并且在删除评论后它没有显示减少的数量。这就是为什么视图没有依次提取正确计数的原因。您能否详细说明一下 commit 命令的含义以及如何实现它?我对这个 Solr drupal 模块比较陌生。
  • 模块 apachesolr 已经实现了 hook_comment_*(),它为包括comment deletion在内的所有操作调用apachesolr_mark_entity()。确保在删除评论时调用此挂钩。如果正确调用它,那么问题可能来自@AlexandreRafalovitch 建议的提交策略。
  • apachesolr_mark_entity() 确实被调用了。我已经检查过了。但是,在调试时,我发现虽然调用了它,但删除评论的节点实际上并没有被重新索引。最可能的原因是,在删除的情况下,此重新索引是在评论实体而不是节点实体上完成的。因此,is_comment_count 字段的值也没有得到更新,这与添加评论的情况不同。我想出了一个解决方案,我很快就会在这个帖子中发布。

标签: solr drupal-7


【解决方案1】:

似乎是现有的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');
}

谢谢

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多