I need to implement a external datasource with Search API but the I haven't found much documentation to help during this process.

Is it possible to get some examples?

Regards,
Francisco

Comments

drunken monkey’s picture

There are a few examples listed in #1559428: Searching through non-entity, external, read-only data.
Other than that, I fear there isn't any documentation yet . However, I'm currently working on expanding what's there, so expect to see the information pop up here in the next week(s).

Finn Lewis’s picture

Hey!

I am in the same boat, I'd like to implement an external datasource with Search API.

There is some great new documentation here https://drupal.org/node/2004270 and here https://drupal.org/node/2006396 which is certainly getting me on the right track.

What I would love is to find an example of a module that implements SearchApiAbstractDataSourceController with a non-Drupal based data source.

The SearchApiEntityDataSourceController class in datasource_entity.inc is also helpful, but it would be useful to see an example where the data is coming from another database, to understand how methods like getMetadataWrapper work with data that is not from a Drupal entity.

If anyone knows of a module that already implements SearchApiAbstractDataSourceController for external data, I'd love to know.

My specific interest is in exposing CiviCRM contacts to SearchAPI.

Many thanks.

Finn

mikeocc’s picture

Issue summary: View changes

I am interested if there has been any movement on this item.

I am attempting to search external data (a web api returning search result) and have created a class which extends SearchApiExternalDataSourceController, this class overrides the getPropertyInfo() method. The hook_search_api_data_type_info() function is being called but nothing much else works - I do not see any attempts to construct an instance of my data source controller.

A simple, working, example demonstrating the correct use of SearchApiExternalDataSourceController and anything else is necessary to get it working would be invaluable - does such an example exist?

Normally I would start reading through the search_api code to figure things out but am on a very tight budget so need to know if I should cut my losses and develop my own search module.

Thanks,
Mike

drunken monkey’s picture

Sorry, I'm still not aware of any examples in that direction. I tried drupalcontrib.org, but it seems that doesn't show inheritance across project boundaries.
I'd love to create an example for this to help others implement such functionality, but sadly my time is really limited at the moment, with the D8 port and literally a hundred other D7 issues.

So, if you don't have the time to look into this and maybe post more specific questions, then probably a custom solution is your only option.

Regarding the information you provided: hook_search_api_data_type_info() is the wrong hook, that's got nothing to do with datasources, you want hook_search_api_item_type_info(). When you return an item type there, you can then create a new index using that type, and then your data source should be used.
However, note that you can only use an external data source if the data already gets indexed by some other means, or your service class (which should then probably also be custom) accesses the data (through the web API in your case) directly. In both cases, the results' field need to be returned by the service class right in the results.
If you want to use the datasource controller also for loading, so that you get a more or less "normal" new item type, you should rather subclass the abstract datasource controller directly and override the necessary methods (as described in its class doc).

retrodans’s picture

Did anyone have any luck on this? I am looking at doing this now to pull in the data from a SOLR index for an external Drupal site, so any pointers would be great, otherwise, I will look at the links posted throughout this issue.

abrlam’s picture

@retrodans Have you tried the Sarnia module?

retrodans’s picture

@abrlam yes thanks, we did use Sarnia in the end. It was not the easiest of configurations from what I recall, but did appear to be the best solution for what we were trying to do.