mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-12-29 16:08:38 +00:00
* Implement function to convert legacy filters to new style * Reduce return statements in conversion to fix linting * Move convert function in different module * Fix typos in docstrings Co-authored-by: Agnieszka Marzec <97166305+agnieszka-m@users.noreply.github.com> --------- Co-authored-by: Agnieszka Marzec <97166305+agnieszka-m@users.noreply.github.com>
43 lines
1.7 KiB
YAML
43 lines
1.7 KiB
YAML
---
|
|
prelude: >
|
|
Following the proposal to introduce a new way of declaring filters
|
|
in Haystack 2.x for Document Stores and all Components that use them,
|
|
we introduce a utility function to convert the legacy style to the new style.
|
|
|
|
This will make life easier for developers when implementing new Document Stores
|
|
as it will only be necessary for filtering logic for the new style filters, as
|
|
conversion will be completely handled by the utility function.
|
|
|
|
An example usage would be something similar to this:
|
|
```python
|
|
legacy_filter = {
|
|
"$and": {
|
|
"type": {"$eq": "article"},
|
|
"date": {"$gte": "2015-01-01", "$lt": "2021-01-01"},
|
|
"rating": {"$gte": 3},
|
|
"$or": {"genre": {"$in": ["economy", "politics"]}, "publisher": {"$eq": "nytimes"}},
|
|
}
|
|
}
|
|
assert convert(legacy_filter) == {
|
|
"operator": "AND",
|
|
"conditions": [
|
|
{"field": "type", "operator": "==", "value": "article"},
|
|
{"field": "date", "operator": ">=", "value": "2015-01-01"},
|
|
{"field": "date", "operator": "<", "value": "2021-01-01"},
|
|
{"field": "rating", "operator": ">=", "value": 3},
|
|
{
|
|
"operator": "OR",
|
|
"conditions": [
|
|
{"field": "genre", "operator": "in", "value": ["economy", "politics"]},
|
|
{"field": "publisher", "operator": "==", "value": "nytimes"},
|
|
],
|
|
},
|
|
],
|
|
}
|
|
```
|
|
|
|
For more information on the new filters technical specification see [proposal #6001](https://github.com/deepset-ai/haystack/blob/main/proposals/text/6001-document-store-filter-rework.md)
|
|
preview:
|
|
- |
|
|
Introduce a function to convert legacy filters to the new style
|