Jump to content
  • Status: Moved to Github

The code's intention is that you can create a ContentFilter instance with onlyFirstComment() set to TRUE to group and only return the first result in a content item that requires comments (i.e. topics). At a technical level, this is implemented like so (for MySQL):

			/* Only first comment? */
			if ( $filter->onlyFirstComment )
			{
				$clause[] = "index_title IS NOT NULL";
			}

The problem is, in practice this does not work as expected because the topic title is set for "index_title" for every single post within the topic. Subsequently, if I create a ContentFilter and set the onlyFirstComment property to TRUE, all comments within the topic are still returned.

I rebuilt the search index to verify the search index behavior wasn't legacy or something.

Note that my testing around this was limited explicitly to topics. I do not know if this is a topics-specific concern, or applies to everything with the $firstCommentRequired property set.

Sample code to show the issue:

		$search = Query::init();
		$search->setLimit(10);
		$search->setPage(1);
		$search->setOrder( Query::ORDER_NEWEST_UPDATED );

		$contentFilters[] = ContentFilter::init( 'IPS\forums\Topic', TRUE, TRUE, FALSE )->onlyFirstComment();

		$search->filterByContent( $contentFilters );

		$results = $search->search( NULL, NULL);

With the onlyFirstComment() flag we should only be seeing the first comment in the topics, but all replies will be returned.

User Feedback

Recommended Comments

There are no comments to display.