drupal-graphql / graphql-search-api

GraphQL & Drupal Search API integration.
10 stars 22 forks source link

Condition Groups not taking effect #19

Closed eric-schmidt closed 5 years ago

eric-schmidt commented 5 years ago

Hopefully this is not user error; however, it seems that condition groups are not properly applying for any fields. I have the following query that is supposed to only results whose 'field_archive_date' is NULL OR greater than or equal to a certain date:

        {
          allResults: searchAPISearch(
            index_id: "sitewide"
            range: {start: 0, end: 12}        
            condition_group: {
              conjunction: OR,
              conditions: [
                {name: "field_archive_date", value: "NULL", operator: "="}
                 {name: "field_archive_date", value: "2019-03-18", operator: ">="}
                ]
            }
            sort: {field: "created" value: "desc"}
            facets: [
              {operator: "=", field: "product", limit: 0, min_count: 0, missing: false}
              {operator: "=", field: "resource_type", limit: 0, min_count: 0, missing: false}
              {operator: "=", field: "segement", limit: 0, min_count: 0, missing: false}
              {operator: "=", field: "solution", limit: 0, min_count: 0, missing: false}
            ]
          ) {
            result_count
            documents {
              ... on SitewideDoc {
                nid
                field_archive_date
              }
            }
            facets{
              name
              values{
                count
                name: filter
              }
            }
          }
        }

Unfortunately, the conditions, when applied in a condition group, are not taking effect. When they are independently applied outside of a condition group, they do apply properly. I've tested this with numerous fields, including default fields like node title, and the conditions do not seem to apply properly in that scenario as well.

duartegarin commented 5 years ago

Hi @eric-schmidt , That syntax doesn't look correct. You're missing the groups. For example:

    condition_group:{
      groups:[
        {
          conjunction:OR
          conditions:[
            {name: "node_type", value: "course", operator: "="},
            {name: "node_type", value: "scholarship", operator: "="},
          ]
        }
        {
          conditions:[
            {name: "gid", value: "2", operator: "="}
          ]
        }
      ]
    }

Let me know if that helps.

eric-schmidt commented 5 years ago

@duartegarin I've amended my query to the following; however, now I'm getting an Internal server error instead of results:

        {
          allResults: searchAPISearch(
            index_id: "sitewide"
            range: {start: 0, end: 12}
            condition_group: {
              groups: [
                {
                  conjunction: OR
                  conditions: [
                    {name: "field_archive_date", value: "NULL", operator: "="},
                    {name: "field_archive_date", value: "2019-03-18", operator: ">="},
                  ]
                }
                {
                  conditions: [
                    {name: "content_type", value: "resource", operator: "="}
                  ] 
                }
              ]
            }
            sort: {field: "created" value: "desc"}
            facets: [
              {operator: "=", field: "product", limit: 0, min_count: 0, missing: false}
              {operator: "=", field: "resource_type", limit: 0, min_count: 0, missing: false}
              {operator: "=", field: "segement", limit: 0, min_count: 0, missing: false}
              {operator: "=", field: "solution", limit: 0, min_count: 0, missing: false}
            ]
          ) {
            result_count
            documents {
              ... on SitewideDoc {
                nid
                field_archive_date
              }
            }
            facets{
              name
              values{
                count
                name: filter
              }
            }
          }
        }

No syntax errors are highlighted in the query, so perhaps the problem lies elsewhere 🤔

duartegarin commented 5 years ago

Hi @eric-schmidt , What error? Maybe there is a bad condition in there? You can turn on debug mode to see whats happening. Add this in your development.services.yml file, under parameters:

graphql.config:
  result_cache: false
  schema_cache: false
  development: true
eric-schmidt commented 5 years ago

@duartegarin Cool snippet! I'm now getting the following verbose error: Call to a member function getResultItems() on null. I believe it is stemming from the line {name: "field_archive_date", value: "NULL", operator: "="}, as when I swap that out for something else (e.g. checking on nid), I don't get the error. Is that the correct way to check for a field that does not have a value set?

It's also worth noting that field_archive_date is a Date field, perhaps that's not playing nice with the condition groups. {name: "field_archive_date", value: "NULL", operator: "="} does work fine when within non-grouped conditions.

duartegarin commented 5 years ago

Hi @eric-schmidt , Sincere apologies for the late reply on this, it seemed to slip through the cracks. I just tested it with a date field and had no issues. Here is my query:

{
  searchAPISearch(index_id:"anabranch_connect_index", conditions:[{name: "applications_close_date", value: "NULL", operator: "="}, {name:"type", value:"career_opportunity"}]){
    documents{
      ... on AnabranchConnectIndexDoc{
        type
        applications_close_date
      }
    }
    result_count
  }
}

Did you manage to work this out?

duartegarin commented 5 years ago

As I can't reproduce and no response for a while I'm making this closed. Feel free to reopen if need be.