Do you have a working example on how to search non-Drupal Solr-indexes? I've managed to do it in 7.x but I fail when I try to do the same in 8.x.

For starters I have:
* A class which extends DatasourcePluginBase
* A class which extends SearchApiSolrBackend so I can have my own Solr-backend.

I would like to now the best way on how to do this so an example would be nice.

CommentFileSizeAuthor
#3 kau_solr-8.x-1.0.tar_.gz6.78 KBjseffel
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jseffel created an issue. See original summary.

drunken monkey’s picture

It largely works the same as in D7, I'd say. You need to retrieve the property information from Solr, expose that via the datasource, and implement all other necessary operations/methods in the datasource. (Also, you'll have to adapt the field mapping in Sorl, of course, if your proprety paths already have the Solr data type prefixes.)
What exactly is not working for you, when using the same approach as in D7?

One little detail you have to be careful about is that the field identifiers now don't necessarily reflect the underlying properties' names anymore, so in the backend plugin you'll need to use the second part of the property paths instead.

If this will work in general with non-Drupal Solr data, it would probably help a lot of people if you'd create a module for that. Then people could also more easily help you by reviewing it.
Or, maybe even create an issue in the Solr module's issue queue – I can imagine it might even be possible to integrate this into the module directly. (I'm not working on its D8 version at the moment, though.)

jseffel’s picture

FileSize
6.78 KB

I've managed to get things working more or less. I would be thankful if you could look at my code and let me know if I've done something really weird.

Explanation of files:
src/Plugin/search_api/backend/SearchApiKauBackend.php
- Needed this one to remove Drupal-specific things.

src/Plugin/search_api/datasource/KauPersonalDatasource.php
- The external datasource. The only functions which seems to do anything is getPropertyDefinitions.

src/Plugin/search_api/tracker/NonDrupalTracker.php
- Had issues with an endless loop when I saved my index. Needed this to fix the problem as the things stored in the index does not reside in Drupal.

src/Routing/KauSolrRoutes.php
- I had to bypass the search page for search_api_page as it tried to load entites which simply did not exist in the system.

I also had to create my own theme function for the search result as I don't have an entity.

Anyways, I would be grateful if you could have a look.

drunken monkey’s picture

Looks pretty sensible to me. If this works, then great!
You shouldn't need to have to override part of the Search Pages module, though, that sounds like it would be a bug.

(However, in your backend plugin, when creating the search results, you can also create an object of a custom class implementing ComplexDataInterface and set that as the "original item". That might also solve some problems. You could then also implement at least some of the getItem*() methods from the datasource properly, based on that "original object" class.)

legolasbo’s picture

Status: Active » Closed (outdated)

This issue has not seen activity in over 2,5 years. I am therefore closing this issue to clean up the issue queue. Feel free to re-open and update this issue if you feel this issue is still relevant and of importance.