Hello, can't install Database Search default because of missing comment type in article, but I can't create "comment", just field_comment. Thanks

Comments

Michal Kmet created an issue. See original summary.

drholera’s picture

It looks like you can't install Database Search Defaults module if you have changed one of 'body', 'comment', 'field_tags', 'field_image' fields in article CT. Or if you change 'body' field in CT Page to field_body for example.

You can fix it for your site:
1. Change - field.field.node.article.comment to - field.field.node.article.field_comment in your search_api_db_defaults/config/optional/core.entity_view_display.node.article.search_index.yml (line 7)
2. Change - field.field.node.article.comment to - field.field.node.article.field_comment in your search_api_db_defaults/config/optional/core.entity_view_display.node.article.search_result.yml (line 7)
3. Change 'article' => array('body', 'comment', 'field_tags', 'field_image'), to the 'article' => array('body', 'field_comment', 'field_tags', 'field_image'), in your search_api_db_defaults/search_api_db_defaults.install (line 19)

After these steps, Database Search Default will install correctly.

drunken monkey’s picture

Category: Bug report » Support request
Status: Active » Fixed

@ drholera: Thanks a lot for your help here!
Seems a good answer, I hope this solved it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

cpatrone’s picture

It is a good answer. I created Article and Page content, I made the changes and it worked. Thank you @drholera

geerlingguy’s picture

The suggestion also works for enabling the Solr Search Defaults module (just in the corresponding solr module files)—however, I still got a message:

An error occurred while trying to execute tasks. Check the logs for details.

But everything else was created successfully, and I didn't see anything in the database log, so go figure.

kate_raquel’s picture

Muchas Gracias, Solucionado a la perfección!

Thank you @drholera, perfect solutión.

carnerik’s picture

I'm having the same issue because I had uninstalled the Comments module prior to installing Search API. I can complete (and have completed) the first two steps as described in comment #1, but I guess the code has changed in search_api_db_defaults/search_api_db_defaults.install, because I don't see 'article' => array('body', 'comment', 'field_tags', 'field_image'),. Lines 10-27 in my file look like this:

/**
 * Implements hook_requirements().
 */
function search_api_db_defaults_requirements($phase) {
  $requirements = [];

  if ($phase == 'install') {
    $errors = IndexListBuilder::checkDefaultsModuleCanBeInstalled();
    foreach ($errors as $type => $error) {
      $requirements["search_api_db_defaults:$type"] = [
        'severity' => REQUIREMENT_ERROR,
        'description' => $error,
      ];
    }
  }

  return $requirements;
}

Is there somewhere else I should look?

carnerik’s picture

Found it. 'article' => array('body', 'comment', 'field_tags', 'field_image'), is located in search_api/src/IndexListBuilder.php on line 68. Changed 'comment' to 'field_comment' and now the module installs. (Again, this is after creating a Comment field called "field_comment" on the Article content type and following the first two steps from comment #1.) @drholera Thanks again!

benjarlett’s picture

#9 worked for me.

rfletcher73’s picture

Hi there, I just ran into this issue myself. Is there a way when the Search API module is installed that it can gather the name of the fields from in Drupal ? Maybe by writing it to a file or storing the settings into the database?

You could do a check that if any fields are missing read the settings from the db or the flat file.

I think there needs to be a way to "future" proof the installer otherwise if someone makes changes, deletes a field and what-not, you can't install your module.

I'm using the latest version of the Search API plugin. I do not think this issue is fixed.

I did follow the steps above and edited the couple of files and that did fix the issue.

Thanks for posting that work-around. I'd still like to see the improvement made to the module though.

rfay’s picture

So I got this problem by trying to use solr with the umami distribution, which does not have "article" set up with comments. And I guess that's the problem. With a standard install it worked OK.

oluwatoyint’s picture

#9 worked for me. You will also have to create the field_tags in the article content type.
For drupal 8.85 You have to go to structure/types on the admin menu, and then modify the article content type.

Doomd’s picture

I found this thread because I had the same exact problem when trying to install the corresponding Solr API Defaults modules (search_api_solr_defaults). Similar to the instructions above, the defaults module would fail to install unless I replaced references to the "comment" field with "field_comment" in the following files:

*/search_api_solr/modules/search_api_solr_defaults/config/optional/core.entity_view_display.node.article.search_index.yml
*/search_api_solr/modules/search_api_solr_defaults/config/optional/core.entity_view_display.node.article.search_result.yml
*/search_api_solr/modules/search_api_solr_defaults/search_api_solr_defaults.install

And of course, as mentioned in a comment above, since I had to install the comment module from scratch, I had to re-create the comment type "comment" (for content). In my articles content type, I added a comments field called "field_comment" which referenced this comment type.

I do agree with #11 that assuming that the comment field exists (since many sites don't need or want comments), AND assuming that the field is called "comment" is a bit inflexible, especially since re-installation of the comments module forces new fields to be prepended with "field_". At the very least, if it's too hard to perform a check for "comment" or "field_comment", if "comment" is missing...it should simply be skipped and the install should still proceed. Indexing comments is hardly necessary...AND they can always be added to an index later.

captaindav’s picture

I was able to work around this issue by:
1) Do a clean install of Drupal 8 Core w/comment enabled.
2) Export the config. (drush cex)
3) Enable Database Search Defaults, verify defaults are correctly set.
4) Determine which config changed by navigating to /admin/config/development/configuration
5) Export the changed config files manually and import them into the site where Database Search Defaults is not working.

subir_ghosh’s picture

This was very useful. #1 + #9.