3

I'm not sure if it's actually doing this; I can't see any options for comment fields in the configuration. How can I check? Does it say explicitly somewhere?

0

Apachesolr Comments

By default the apachesolr module index comments attached to the node. So you can not search comments directly. This module separates comments from the nodes and allows you to search them directly.

UPDATE:

For search api apply this patch

diff --git a/modules/callbacks.inc b/modules/callbacks.inc
index dca9e1d..e12be6a 100644
--- a/modules/callbacks.inc
+++ b/modules/callbacks.inc
@@ -80,6 +80,12 @@ function entity_metadata_comment_get_node_properties($node, array $options, $nam

     case 'comment_count_new':
       return comment_num_new($node->nid);
+
+    case 'comments':
+      $select = db_select('comment', 'c')
+        ->fields('c', array('cid'))
+        ->condition('c.nid', $node->nid);
+      return array_keys($select->execute()->fetchAllKeyed(0, 0));
   }
 }

diff --git a/modules/comment.info.inc b/modules/comment.info.inc
index 4321b4c..a9d7fe9 100644
--- a/modules/comment.info.inc
+++ b/modules/comment.info.inc
@@ -136,6 +136,13 @@ function entity_metadata_comment_entity_property_info_alter(&$info) {
     'setter permission' => 'administer comments',
     'type' => 'integer',
   );
+  $properties['comments'] = array(
+    'label' => t("Comments"),
+    'type' => 'list<comment>',
+    'description' => t("The node comments."),
+    'getter callback' => 'entity_metadata_comment_get_node_properties',
+    'computed' => TRUE,
+  );
   $properties['comment_count'] = array(
     'label' => t("Comment count"),
     'description' => t("The number of comments posted on a node."),

Taken from the source https://drupal.org/node/1414688#comment-7037540 and also worth looking at this http://blog.merge.nl/shorts/search-api-indexing-nodes-including-comments

  • Might be worth mentioning it's currently in dev... – Clive Sep 5 '13 at 11:52
  • I'm sorry but I'm not using the Apachsolr module, I'm using Search API Solr. – cjm2671 Sep 5 '13 at 12:15
  • @Clive I updated my answer – Bala Sep 5 '13 at 12:34
  • An Updated answer to Drupal 8 would be awesome. – Insasse Apr 30 at 11:55
0

For Drupal 8 I had to write custom properties to get my comments into the index.

I followed this documentation https://www.drupal.org/docs/8/modules/search-api/developer-documentation/create-custom-fields-using-a-custom-processor

And than queried my Entity in addFieldValues() Method.

Like

$object = $item->getOriginalObject()->getValue();
$comment_ids = $this->entityTypeManager()->getStorage('comment')->getQuery()
 ->condition('comment_type', '<comment_type>')
 ->condition('entity_id', $object->id())
 ->execute();
$comments = $this->getEntityTypeManager()
  ->getStorage('comment')
  ->loadMultiple($comment_ids);
$fields = $this->getFieldsHelper()
  ->filterForPropertyPath($item->getFields(), NULL, '<my_property_definition>');
foreach ($fields as $field) {
  /** @var \Drupal\comment\Entity\Comment $answer */
  foreach ($comments as $comment) {
    $field->addValue($comment->comment_body->value);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.