Hi,

I'm using Solr joins to perform queries relating two entities types (cvs and applications). 1 cv can be related to n applications. Here is an example of the query params:

q: bundle:cv
fq: {!join from=is_field_app_cv to=entity_id}sm_field_app_job:"node:1"

This query will give me the cvs inside the job with id:1.

However, if I want it to return the cvs that are not in job 1, I need to negate the full join condition:

q: bundle:cv
fq: -{!join from=is_field_app_cv to=entity_id}sm_field_app_job:"node:1"

(to negate just the job condition won't be accurate fq: {!join from=is_field_app_cv to=entity_id} -sm_field_app_job:"node:1", because a cv can be in job 1 and also in job 2.

The problem is that, if I invoke apachesolr_drupal_query with a negative join in fq params, the function makeFilterQuery will put the exclude condition behind the join (detected as Local Param). Here is the piece of code that is doing the trick:

public function makeFilterQuery(array $filter) {
    $prefix = empty($filter['#exclude']) ? '' : '-';
    if ($filter['#local']) {
        $prefix = '{!' . $filter['#local'] . '}' . $prefix;
    }
...

But, as I explained before, that won't give me the right results... I need to negate the whole join condition.

The patch in the following comment allows to perform negative joins. Not sure that is the right way to do it...

CommentFileSizeAuthor
#1 2480929--negative-joins-1.patch1.1 KBsandra.ramil
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sandra.ramil’s picture

Status: Active » Needs review
FileSize
1.1 KB
sandra.ramil’s picture

Issue summary: View changes