Search API support

Created on 29 September 2023, 9 months ago
Updated 19 October 2023, 8 months ago

Problem/Motivation

Not sure why, but Civi Contact and Event entities aren't indexed.
I've got Node search index configured correctly, but I've got:

Datasource CiviCRM Contact (2/2 indexed)
Datasource CiviCRM Event (0/0 indexed)

Steps to reproduce

- Setup Search API server and index at /admin/config/search/search-api
- Select Civi entities and add fields for indexing.
- Rebuild tracking information, doesn't report any new items for indexing.

In previous version there was a dedicated civicrm_entity_search_api module, but it's gone.
How Search API is integrated now, as I couldn't find any relevant code for it.

I've read the following resources (most outdated):
- https://civicrm.org/blog/jackrabbithanna/civicrm-entity-using-drupal-sea...
- https://www.drupal.org/docs/drupal-apis/entity-api/working-with-the-enti... β†’
- https://www.drupal.org/docs/8/api/entity-api/making-the-content-entity-s... β†’
but it's still not clear enough.

Is indexing of Civi entities should just work, or I need to write some extra classes for it implementing SearchIndexingInterface?

I've looked through the codebase, and I couldn't find anything Search API related.

πŸ’¬ Support request
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom kenorb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kenorb
  • πŸ‡ΊπŸ‡ΈUnited States markusa

    D8+ version doesn't work with Search API

    I did just try it recently actually, and if Civi tables are in a separate database, doesn't work at all as the DataSource tries to query from the Drupal database.

    Do you have Civi tables in the same database as Drupal?

  • πŸ‡΅πŸ‡­Philippines dsdeiz

    Yeah, can you export your search index configuration? I tested both CiviCRM contact and event and they are working as expected. I am just using search_api_db though.

    Is your CiviCRM database separate from Drupal?

  • πŸ‡¬πŸ‡§United Kingdom kenorb

    The configuration in civicrm.settings.php points to the different db than local Drupal. So maybe mistakenly is using Drupal local db instead of what's configured in Civi's settings file?

  • Status changed to Needs review 9 months ago
  • πŸ‡΅πŸ‡­Philippines dsdeiz

    Yeah, that was the case. Can you give this a try - https://github.com/eileenmcnaughton/civicrm_entity/pull/450? It's on 4.0.x although I think it can be applied to 8.x-3.5 as well.

  • πŸ‡¬πŸ‡§United Kingdom kenorb

    Thanks for the patch, I'm going to test it.
    I'm attaching patch for 8.x-3.x (so I can use it with Composer), since 4.x was slightly failing to apply.

  • Status changed to RTBC 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom kenorb

    Tested changes from PR and it seems to work fine. Search API indexing for Civi entities works while having 2 databases ($databases['default']['default'] & $databases['civicrm']['default']).

  • Status changed to Fixed 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States markusa

    Code was merged to 4.0.x branch in the github repo. We're gearing up to push updates to Drupal.org repo very soon for a new release.

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

Production build 0.69.0 2024