Skip to content

Commit

Permalink
indexation class: add indexation property to IlsRecord
Browse files Browse the repository at this point in the history
* Adds indexation class property to IlsRecord

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep and rerowep committed Jul 30, 2019
1 parent c9b4fb3 commit 56111da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
7 changes: 4 additions & 3 deletions rero_ils/modules/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class IlsRecord(Record):
fetcher = None
provider = None
object_type = 'rec'
indexer = IlsRecordIndexer

@classmethod
def create(cls, data, id_=None, delete_pid=False,
Expand Down Expand Up @@ -274,14 +275,14 @@ def dbcommit(self, reindex=False, forceindex=False):
def reindex(self, forceindex=False):
"""Reindex record."""
if forceindex:
RecordIndexer(version_type="external_gte").index(self)
self.indexer(version_type="external_gte").index(self)
else:
RecordIndexer().index(self)
self.indexer().index(self)

def delete_from_index(self):
"""Delete record from index."""
try:
RecordIndexer().delete(self)
self.indexer().delete(self)
except NotFoundError:
pass

Expand Down
8 changes: 1 addition & 7 deletions rero_ils/modules/items/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class Item(IlsRecord):
minter = item_id_minter
fetcher = item_id_fetcher
provider = ItemProvider
indexer = ItemsIndexer

statuses = {
'ITEM_ON_LOAN': 'on_loan',
Expand Down Expand Up @@ -482,13 +483,6 @@ def actions(self):
# actions.add('lose')
return actions

def reindex(self, forceindex=False):
"""Reindex record."""
if forceindex:
ItemsIndexer(version_type="external_gte").index(self)
else:
ItemsIndexer().index(self)

def status_update(self, dbcommit=False, reindex=False, forceindex=False):
"""Update item status."""
loan = get_loan_for_item(self.pid)
Expand Down
26 changes: 13 additions & 13 deletions tests/ui/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ def test_ilsrecord(app, es_default_index, ils_record, ils_record_2):
with pytest.raises(IlsRecordError.NotDeleted):
record = record.undelete()

"""Test IlsRecord es search."""
search_all = list(
SearchTest().filter('match_all').source().scan()
)
assert len(search_all) == 3
search = list(
SearchTest()
.filter('term', pid='ilsrecord_pid_2')
.source(includes=['pid'])
.scan()
)
assert search[0]['pid'] == 'ilsrecord_pid_2'

"""Test IlsRecord update."""
record = RecordTest.get_record_by_pid('ilsrecord_pid')
record.delete(delindex=True)
Expand All @@ -195,16 +208,3 @@ def test_ilsrecord(app, es_default_index, ils_record, ils_record_2):
record.delete(delindex=True)
assert len(RecordTest.get_all_pids()) == 0
assert len(RecordTest.get_all_ids()) == 0

"""Test IlsRecord es search."""
search_all = list(
SearchTest().filter('match_all').source().scan()
)
assert len(search_all) == 3
search = list(
SearchTest()
.filter('term', pid='ilsrecord_pid_2')
.source(includes=['pid'])
.scan()
)
assert search[0]['pid'] == 'ilsrecord_pid_2'

0 comments on commit 56111da

Please sign in to comment.