I know that the concept of join doesn't exist in Search API but the reality is that some backend can implement a join and I don't know if exist any way to implement it using Search API.

For example, for a Solr backend, we can do this:

http://solrserver:8983/solr/drupal/select?q={!join%20from=its_uid%20to=its_uid}its_nid:(99786)

This query return a nid list in which the uid are one of the uids related with 99786. It is a recommendation engine and the query return the typical product relationships (Really the query is a little bit more complex, but it's enough for the example).

I could replicate the Solr query using Search api except this condition because it's a join. Do you know the way to replicate it using Search API? or some documentation related?

Thanks!

Comments

estoyausente created an issue. See original summary.

estoyausente’s picture

I could reproduce it with this Option:

$query->setOption('solr_param_q', "{!join from=its_uid to=its_uid}its_nid:($nidsString)");

But I think that it is a little bit dirty, I'm not sure if I have another option o I can patch search_api to allow create option like this. Any ideas?

drunken monkey’s picture

Status: Active » Fixed

As you've discovered, Solr already gives you the option to specify custom parameters. Also, using the direct ("Direct query") query parse mode, you should be able to just input the desired q parameter as the keywords and have it passed through as-is by the Solr backend. And then, you also have the option of implementing hook_search_api_solr_query_alter() to alter the Solr query in any way you like. You could also set some specific option on the Search API query option before, to help with that.

For implementing this in a more generic way, to be published as a contrib module, you'd more or less just properly document this last mentioned system (set a Search API query option and the Solr query will be altered accordingly) as a backend feature and have the Solr backend implement it (using hook_search_api_server_features_alter() if the code is in a different contrib module, not in the Solr module itself).

Hope this helps.

estoyausente’s picture

Hi, @drunken monkey!

really usefull info. I will continue using Search API and Search Api Solr and if the project requirement evolves and I have to work in this maybe I can extend Search Api Solr or provide an extra module following this guidelines.

Thanks!

Status: Fixed » Closed (fixed)

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

medwassim’s picture

Hi,
can we make join between 2 indexes in the same solr core ? any example please ?

i have to get documents from index1 having id related in other documents in index2

Thanks.

medwassim’s picture

Now i understand how join work : https://wiki.apache.org/solr/Join
work like a sharm !
Thank you for sharing this tips.

Regards.