diff --git a/swh/indexer/storage/in_memory.py b/swh/indexer/storage/in_memory.py --- a/swh/indexer/storage/in_memory.py +++ b/swh/indexer/storage/in_memory.py @@ -388,17 +388,17 @@ sorted(self._content_ctags._data.items()): if id_ <= (last_sha1 or bytes(0 for _ in range(SHA1_DIGEST_SIZE))): continue - nb_matches += 1 for ctags_item in item['ctags']: if ctags_item['name'] != expression: continue + nb_matches += 1 yield { 'id': id_, 'tool': _transform_tool(self._tools[tool_id]), **ctags_item } - if nb_matches >= limit: - return + if nb_matches >= limit: + return def content_fossology_license_get(self, ids): """Retrieve licenses per id. diff --git a/swh/indexer/tests/storage/test_storage.py b/swh/indexer/tests/storage/test_storage.py --- a/swh/indexer/tests/storage/test_storage.py +++ b/swh/indexer/tests/storage/test_storage.py @@ -560,6 +560,12 @@ 'line': 119, 'lang': 'Python', }, + { + 'name': 'hello', + 'kind': 'variable', + 'line': 210, + 'lang': 'Python', + }, ] } @@ -573,6 +579,12 @@ 'line': 100, 'lang': 'C', }, + { + 'name': 'result', + 'kind': 'variable', + 'line': 120, + 'lang': 'C', + }, ] } @@ -626,6 +638,14 @@ 'lang': 'Python', }, { + 'id': ctag1['id'], + 'tool': tool, + 'name': 'hello', + 'kind': 'variable', + 'line': 210, + 'lang': 'Python', + }, + { 'id': ctag2['id'], 'tool': tool, 'name': 'hello', @@ -648,6 +668,20 @@ 'lang': 'Python', }]) + # 5. when + actual_ctags = list(self.storage.content_ctags_search('result', + limit=1)) + + # then + self.assertEqual(actual_ctags, [{ + 'id': ctag2['id'], + 'tool': tool, + 'name': 'result', + 'kind': 'variable', + 'line': 120, + 'lang': 'C', + }]) + def test_content_ctags_search_no_result(self): actual_ctags = list(self.storage.content_ctags_search('counter'))