---
# System prepended metadata

title: 'Scribr Search : filter by contextual data'
tags: [allomedia, ' scribr', ' blueprint']

---

---
title: 'Scribr Search : filter by contextual data'
tags: allomedia, scribr, blueprint
---

Scribr Search : Filter by contextual data
===

## Table of Contents

[TOC]

## Why

As of now, all our automated clients (https://scribr.allo-media.net/admin/api/classificationmodel/?automated_moderation__exact=1) have calls qualified via the Pathfinder with decisional and contextual data (https://twist.com/a/79983/ch/195958/t/766523/c/51596644). So, we need to be able to filter calls based on these two types.

We will need this feature to adress the Use Case "[Spot unsatisfied customers, and call them back to help them](https://twist.com/a/79983/ch/196350/t/797297)".

Finally, the Prod team will use this feature to identify calls to annotate them.


## Who

- Scribr backend: will make available to the UI and provide a way to search it via the corresponding API payload.
- Scribr UI: will provide a way to search calls by contextual data
- Clients: will be able to search calls by contextual data
- Internal team (R&D and Prod): will be able to identify interesting calls to be annotated

## What

### What we currently have

We are already able to filter calls based on decisional data on Scribr search.


### What should be done

On the Search tab, we should provide another input tab to select a contextual data for filtering the results. A first filter for contextual categories, and a second level for contextual values.

Or, we could setup a generic input tag to search for qualifications of several types and several providers.

#### Use UUID as key instead of name

A first iteration could be to use the UUID as key instead of name for the filter request, as proposed in CH (https://app.clubhouse.io/allomedia/story/8096/facets-should-return-key-name-and-count)

```json
{
    "contextual": [{
        "key": "d47827f2-6d51-4089-b42a-c6331a540b21",
        "name": "Echec paiement",
        "count": 76
    }]
}
```

#### Make sure that contextual data is indexed in ES

The contextual data should be indexed in ES as the decisional data.

Currently, the contextual data are indexed in ES call document under two fields ```contextual_classification_labels``` and ```tag_values```. For example : 
```json
  "last_cp_moderation": {
    "author": "trusty",
    "comment": "AI estimation.",
    "created_at": "2019-06-11T14:10:16.577037+00:00",
    "moderation_group": "Allomedia Bots",
    "classification_label": {
      "unique_id": "b9be4ac3-8655-4362-a73e-28895ea0bae3",
      "name": "Echec paiement",
      "description": null
    },
    "contextual_classification_labels": [
      {
        "unique_id": "795bcc08-7d4d-4e24-8b59-cb75c42a0638",
        "name": "Aide réservation",
        "description": null
      },
      {
        "unique_id": "95b84f91-11c9-433e-be01-f01724750763",
        "name": "Carte / abonnement",
        "description": null
      },
      {
        "unique_id": "fb59af29-97f4-45b7-89fd-2eac37e07da5",
        "name": "Problématique site Internet",
        "description": null
      }
    ],
    "tag_values": [
      {
        "id": 33301,
        "name": "Aide réservation",
        "description": null
      },
      {
        "id": 33300,
        "name": "Carte / abonnement",
        "description": null
      },
      {
        "id": 33303,
        "name": "Problématique site Internet",
        "description": null
      }
    ]
```

On the Search response payload, under ```qualification``` : 
```json
{
	"qualification": {
		"decisional": {
			"unique_id": "b9be4ac3-8655-4362-a73e-28895ea0bae3",
			"display_name": "Echec paiement",
			"description": null
		},
		"contextual": [{
			"unique_id": "795bcc08-7d4d-4e24-8b59-cb75c42a0638",
			"display_name": "Aide réservation",
			"description": null
		}, {
			"unique_id": "95b84f91-11c9-433e-be01-f01724750763",
			"display_name": "Carte / abonnement",
			"description": null
		}, {
			"unique_id": "fb59af29-97f4-45b7-89fd-2eac37e07da5",
			"display_name": "Problématique site Internet",
			"description": null
		}]
	}
}
```

#### Update the transcription search endpoint to provide contextual data facets

The transcription search endpoint ```api/v1/search/transcription/``` should provide in the response payload the facets for the contextual data, as the decisional data : 

```json
{
    "_facets": {
		"clients": [],
		"decisional": [],
		"contextual": [{
				"key": "fb59af29-97f4-45b7-89fd-2eac37e07da5",
				"name": "Problématique site Internet",
				"count": 76
			},
			{
				"key": "795bcc08-7d4d-4e24-8b59-cb75c42a0638",
				"name": "Aide réservation",
				"count": 12
			}
		]
	}
}
```
Limit to the first 100 contextual data items.

#### Provide in the Scribr client UI an input to select one or several contextual labels

Provide a way for the user to select one or more contextual labels as it is available for decisional data, for filtering the calls list.

Maybe should we select a decisional label prior to be able to select one or more contextual labels available.