Skip to content

Commit

Permalink
Add search_fields attribute to Summary class
Browse files Browse the repository at this point in the history
This commit adds the `search_fields` attribute to the Summary class.
The `search_fields` attribute can be accessed to retrieve the last item
search related fields.

Signed-off-by: Jose Javier Merchante <[email protected]>
  • Loading branch information
jjmerchante committed Mar 7, 2024
1 parent 6bb1f96 commit f0a480c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions perceval/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ def __init__(self):
self.max_offset = None
self.last_offset = None
self.extras = None
self.last_search_fields = None

@property
def total(self):
Expand All @@ -1061,6 +1062,8 @@ def update(self, item):
self.min_offset = offset if self.min_offset is None else min(self.min_offset, offset)
self.max_offset = offset if self.max_offset is None else max(self.max_offset, offset)

self.last_search_fields = item.get('search_fields', None)


def uuid(*args):
"""Generate a UUID based on the given parameters.
Expand Down
7 changes: 6 additions & 1 deletion tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,7 @@ def test_init(self):
self.assertIsNone(summary.max_offset)
self.assertIsNone(summary.last_offset)
self.assertIsNone(summary.extras)
self.assertIsNone(summary.last_search_fields)

def test_update(self):
"""Test whether the method update properly works"""
Expand All @@ -1899,7 +1900,8 @@ def test_update(self):
},
{
"updated_on": 1483228700.0,
"uuid": "0fa16dc4edab9130a14914a8d797f634d13b4bb4"
"uuid": "0fa16dc4edab9130a14914a8d797f634d13b4bb4",
"search_fields": {"item_id": "08c2fc9c870c704a9e778db582f1ac98063f3198"}
}
]

Expand All @@ -1917,6 +1919,7 @@ def test_update(self):
self.assertIsNone(summary.min_offset)
self.assertIsNone(summary.max_offset)
self.assertIsNone(summary.last_offset)
self.assertIsNone(summary.last_search_fields)

item = items[1]
summary.update(item)
Expand All @@ -1930,6 +1933,7 @@ def test_update(self):
self.assertIsNone(summary.min_offset)
self.assertIsNone(summary.max_offset)
self.assertIsNone(summary.last_offset)
self.assertIsNone(summary.search_fields)

item = items[2]
summary.update(item)
Expand All @@ -1943,6 +1947,7 @@ def test_update(self):
self.assertIsNone(summary.min_offset)
self.assertIsNone(summary.max_offset)
self.assertIsNone(summary.last_offset)
self.assertDictEqual(summary.search_fields, item['search_fields'])

def test_update_offset(self):
"""Test whether the method update properly works on offset attributes"""
Expand Down

0 comments on commit f0a480c

Please sign in to comment.