Is it possible to index comments together with nodes? I've got a node index, and I can index the number of comments, but not the content of those comments. I'd like searches to return nodes where either the node content *or* comment content contains the search term. (I'd simply weight the node content more heavily.) I see no way to do this currently. Am I just missing it?

A huge portion of the content on this site is in the comments. I know I can create a separate index just for comments, but I don't want to search for individual comments. I want to search for nodes. Does that make sense?

Thanks much for any help.

-Joseph

Comments

jtbayly’s picture

Here is a pertinent use-case example:

On Drupal.org, when I search the issue queue of a module, I'm not only searching the text of the original issue, but also all of the comments on that issue. That's basically what I'd like to be able to do, but I can't figure out how.

jtbayly’s picture

Title: Indexing comments with nodes » Can node indexes include comment content?

clarifying title

jtbayly’s picture

Ok, now this is very ironic. I have figured out how to include node content in a comment index, but not vice-versa. Am I just missing the obvious? Certainly there must be a way to do what I want. Help?

-Joseph

jtbayly’s picture

Title: Can node indexes include comment content? » allow node indexes to include the comment content
Category: support » feature

I guess it's not possible. Seems pretty basic to me.

I thought I was getting somewhere when I read #1068334: Add a data alteration for indexing the viewed entity . But entity_view doesn't include comments when viewing a node, so far as I can tell.

phreestilr’s picture

No responses to this yet...huh. I wish I could help you, but I'm actually trying to do the same thing and have not been able to figure out a way so far.

You say you can include node content in a comment index. Wouldn't that do the trick?

jtbayly’s picture

One would think so, but not really. Assume the word "grog" is in a post, and then there are 100 comments on that post, and you include the post data in the comment index. Now when you search for the word grog, you are going to get 100 results--one for each comment, even though they will all take you to the same page. Not very helpful in my opinion.

Please post back here if you find anything that works. I'm guessing we might have to switch to the apachesolr module, and I'm not very excited about the prospect. I just keep thinking this *has* to be possible. It seems so basic.

-Joseph

phreestilr’s picture

Yeah, you're right. It does seem like it *should* be possible, but I'm stumped. Please let me know if you figure something out, and I'll do the same.

jtbayly’s picture

Title: allow node indexes to include the comment content » node indexes not showing all related entities as index options (e.g. comments)
Version: 7.x-1.0-rc1 » 7.x-1.1
Component: Miscellaneous » Framework
Category: feature » bug

I went back and read the description of the module, and it's supposed to be able to do this, so I'm daring to switch this to a bug report. It says, "All of an entity's properties, as well as those of related entities (e.g. a node's author's name), are available as fields..." I'm pretty sure that a comment is a related entity to a node, which means that the comment content should be an available field to index. Plus, this comment indicates that it was one of the primary benefits of this module over the Apache Solr Search Integration module. But at this point, this functionality has been added over there, but is missing here.

-Joseph

P.S. It occurs to me that this could maybe be a bug with Entity API?

Edited to add, maybe it's a question of which direction the relationship between the node entity and comment entity goes? Just another guess.

phreestilr’s picture

I've only skimmed this because I don't have time to really work on it now, but I happened upon this article, which may be of use...

http://ygerasimov.com/add-custom-field-search-api-apachesolr-index

drunken monkey’s picture

Title: node indexes not showing all related entities as index options (e.g. comments) » Include reference to comments in Node metadata
Project: Search API » Entity API
Version: 7.x-1.1 » 7.x-1.x-dev
Component: Framework » Core integration
Category: bug » feature

This is a problem with Entity API, which doesn't include a reference to the comments in the node properties, and since we only look at those, we can't index a node's comments.

The best way to fix this would be for the Entity API to just add a "comments" property to nodes (if the comment module is enabled). If fago would be OK with that, I'd even code it. However, I can understand why they aren't included, as the relation goes from comments to nodes, not the other way round, and is thus not really part of the node in the same way that taxonomy term references are. While I think it would be cool to be able to do this, I don't know how fago'll see this.

The other way is, as mentioned in #9, to manually add this property to nodes. The linked tutorial seems pretty good to me, the official documentation, sadly, is a bit sparse.
Effectively, you'll just have to add a property "comments" to nodes and return an array containing the node's comments in the getter callback.

fashionary’s picture

I also encounter this problem and find this post.
Did anyone succeed in method proposed in comments #9 and 10?
It would be great if Drunken Monkey can code it.

Thanks for you input.

adams.garfield’s picture

me too having the same problem. Any solution for it yet ?

drunken monkey’s picture

Status: Active » Closed (duplicate)