Skip to content

Commit

Permalink
[api] Limit number of return rows by one during matching operation
Browse files Browse the repository at this point in the history
Closes chaoss#22
  • Loading branch information
andygrunwald authored and sduenas committed Nov 10, 2015
1 parent 96c3936 commit 238f196
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions sortinghat/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def match_identities(db, uuid, matcher):
The function will search in the registry for similar identities to 'uuid'.
The result will be a list matches containing unique identities objects.
This list will also include the given unique identity.
This list will not(!) include the given unique identity.
The criteria used to check when an identity matches with another one
is defined by 'matcher' parameter. This parameter is an instance
Expand All @@ -879,7 +879,8 @@ def match_identities(db, uuid, matcher):
if not uid:
raise NotFoundError(entity=uuid)

candidates = session.query(UniqueIdentity).all()
# Get all identities expect of the one requested one query above (uid)
candidates = session.query(UniqueIdentity).filter(UniqueIdentity.uuid != uuid).all()

for candidate in candidates:
if not matcher.match(uid, candidate):
Expand Down
12 changes: 6 additions & 6 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1922,37 +1922,37 @@ def test_default_matcher(self):
m1 = api.match_identities(self.db, 'John Smith', matcher)
uids = get_uuids(m1)

self.assertListEqual(uids, ['John Smith', 'Smith J.'])
self.assertListEqual(uids, ['Smith J.'])

# Smith J.
m1 = api.match_identities(self.db, 'Smith J.', matcher)
uids = get_uuids(m1)

self.assertListEqual(uids, ['John Smith', 'Smith J.'])
self.assertListEqual(uids, ['John Smith'])

# John Doe
m2 = api.match_identities(self.db, 'John Doe', matcher)
uids = get_uuids(m2)

self.assertListEqual(uids, ['John Doe'])
self.assertListEqual(uids, [])

# Jane Rae
m3 = api.match_identities(self.db, 'Jane Rae', matcher)
uids = get_uuids(m3)

self.assertListEqual(uids, ['Jane', 'Jane Rae', 'JRae'])
self.assertListEqual(uids, ['Jane', 'JRae'])

# JRae
m3 = api.match_identities(self.db, 'JRae', matcher)
uids = get_uuids(m3)

self.assertListEqual(uids, ['Jane', 'Jane Rae', 'JRae'])
self.assertListEqual(uids, ['Jane', 'Jane Rae'])

# Jane
m3 = api.match_identities(self.db, 'Jane', matcher)
uids = get_uuids(m3)

self.assertListEqual(uids, ['Jane', 'Jane Rae', 'JRae'])
self.assertListEqual(uids, ['Jane Rae', 'JRae'])


def test_empty_registry(self):
Expand Down

0 comments on commit 238f196

Please sign in to comment.