wearefuturegov / Outpost-Platform

The Outpost Platform repository
0 stars 1 forks source link

Filters to have AND logic rather than OR #19

Open apricot13 opened 1 year ago

apricot13 commented 1 year ago

Description of request or change

Currently in Scout the filters work on or logic, this issue describes a request to add in AND logic support as well.

Original request:

For example currently, when someone selects autism and deafness, the results shown have both listed and not those that are only both.

Scope

This issue only covers filters, it does not cover taxonomies, see Caveats

User Story

As a user, I want to be able to request a list of services that have specific filters assigned to them. Specifically, I want to be able to filter services by the suitability tag, so that I can find services that are appropriate for my needs. Additionally, I want to be able to filter services by taxonomy tags, so that I can find services that are relevant to my interests.

Definition of Done

Acceptance Criteria

Using this data:

[
  {
    "name": "Service A",
    "suitabilities": [
      {
        "name": "Suitability 1"
      },
      {
        "name": "Suitability 2"
      }
    ]
  },
  {
    "name": "Service B",
    "suitabilities": [
      {
        "name": "Suitability 1"
      }
    ]
  },
  {
    "name": "Service C",
    "suitabilities": [
      {
        "name": "Suitability 2"
      }
    ]
  }
]

Scenario 1: Requesting a list of services with suitability_1 AND suitability_2 assigned to them

 suitabilities=suitability_1,suitability_2
[
  {
    "name": "Service A",
    "suitabilities": [
      {
        "name": "Suitability 1"
      },
      {
        "name": "Suitability 2"
      }
    ]
  }
]

Scenario 2: Requesting a list of services with suitability_1 OR suitability_2 assigned to them

Note: In all of the above scenarios, the API should return only the services that match the specified filter parameters. Any services that do not match the filters should be excluded from the results.

[
  {
    "name": "Service A",
    "suitabilities": [
      {
        "name": "Suitability 1"
      },
      {
        "name": "Suitability 2"
      }
    ]
  },
  {
    "name": "Service B",
    "suitabilities": [
      {
        "name": "Suitability 1"
      }
    ]
  },
  {
    "name": "Service C",
    "suitabilities": [
      {
        "name": "Suitability 2"
      }
    ]
  }
]

Notes

Looking into how ORUK uses taxonomies

It doesn't specify whether or not to default to 'AND' and 'OR' but it does seem to imply AND/OR, which is what Outpost currently supports.

Examples given here are:

/services/?service_types=esdServiceType:298service_types=esdServiceType:1755 

finds services of types: 298 - Carers support groups and/or 1755 - Carers assessment.

/services/?circumstance=esdCircumstance:Gender_Female&circumstance=esdCircumstance:AddictSubstanceAbuser_Smoking 

finds services of types associated with circumstance Gender_Female - Female and/or AddictSubstanceAbuser_Smoking - Smoker.

/services/?need=esdNeed:69&esdNeeds=need:71 

finds services of types associated with needs 69 - Social inclusion and/or 71 - Community facilities

Caveats

Outpost doesn't currently support vocabularies but will do in the future so any solution should bear this in mind

Hence this call is used to find all services of service type 298 in the LGA Service Type list:

services/?taxonomy_id=esdServiceType:242&taxonomy_type=service&vocabulary=esdServiceTypes

Note that all the above filter parameters are applied with a Boolean AND operator. Hence the above syntax cannot be used to find services with one of a number of given service types via a single API call.

In the ORUK standard when you request a list of services by taxonomy you must include three pieces of data (the taxonomy ID, the taxonomy type, and the vocabulary) in order to return a result

{
  "taxonomy_id": "esdServiceType:242",
  "taxonomy_type": "service",
  "vocabulary": "esdServiceTypes"
}

Tasks

Future work

apricot13 commented 1 year ago

Have asked about this in ORUK forum

apricot13 commented 1 year ago

My understanding is that query parameters should be combined with a Boolean AND - so all filter conditions should be valid for all results.

So if you want to do an OR, you need to do two (or more) queries and combine the responses.

it is boolean AND.

/services?taxonomy_id=XXX&organization_id=YYY

So this is searching for taxonomy_id XXX AND organization_id YYY