Skip to content

Commit 5e42b69

Browse files
authored
#205 Add WhySearch (#217)
* #205 Initial draft * #205 Savepoint * #205 Savepoint * #205 Prepare for versioned release
1 parent e452e9f commit 5e42b69

13 files changed

Lines changed: 207 additions & 104 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning].
77

88
## [Unreleased]
99

10+
## [0.2.6] - 2025-04-16
11+
12+
### Added in 0.2.6
13+
14+
- `SzEngine.why_search`
15+
1016
## [0.2.5] - 2025-03-11
1117

1218
### Changed in 0.2.5

docs/source/_static/.placeholder.txt

Whitespace-only changes.

examples/szengine/why_search.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import json
2+
3+
from senzing import SzEngineFlags, SzError
4+
5+
from . import sz_engine
6+
7+
try:
8+
attributes = json.dumps({"NAME_FULL": "BOB SMITH", "EMAIL_ADDRESS": "bsmith@work.com"})
9+
ENTITY_ID = 1
10+
flags = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS
11+
SEARCH_PROFILE = "SEARCH"
12+
RESULT = sz_engine.why_search(attributes, ENTITY_ID, flags, SEARCH_PROFILE)
13+
print(f"\n{RESULT}\n")
14+
except SzError as err:
15+
print(f"\nERROR: {err}\n")

examples/szengine/why_search.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Output has been formatted for easier reading.
2+
{
3+
"WHY_RESULTS": [
4+
{
5+
"ENTITY_ID": 1,
6+
"MATCH_INFO": {
7+
"WHY_KEY": "+PNAME+EMAIL",
8+
"WHY_ERRULE_CODE": "SF1",
9+
"MATCH_LEVEL_CODE": "POSSIBLY_RELATED"
10+
}
11+
}
12+
],
13+
"ENTITIES": [
14+
{
15+
"RESOLVED_ENTITY": {
16+
"ENTITY_ID": 1
17+
}
18+
}
19+
]
20+
}

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = senzing
3-
version = 0.2.5
3+
version = 0.2.6
44
author = senzing
55
author_email = support@senzing.com
66
description = Python SDK method definitions

src/senzing/szengine.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,42 @@ def why_records(
932932
:language: json
933933
"""
934934

935+
@abstractmethod
936+
def why_search(
937+
self,
938+
attributes: str,
939+
entity_id: int,
940+
flags: int = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS,
941+
search_profile: str = "",
942+
) -> str:
943+
"""
944+
The `why_search` method retrieves entity data based on a specific entity Id and a
945+
user-specified set of entity attributes.
946+
947+
Args:
948+
attributes (str): A JSON document with the attribute data to search for.
949+
entity_id (int): The identifier of the entity to retrieve.
950+
flags (int, optional): _description_. Defaults to SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS.
951+
search_profile (str): The name of a configured search profile. Defaults to SEARCH.
952+
953+
Returns:
954+
str: A JSON document.
955+
956+
Raises:
957+
958+
.. collapse:: Example:
959+
960+
.. literalinclude:: ../../examples/szengine/why_search.py
961+
:linenos:
962+
:language: python
963+
964+
**Output:**
965+
966+
.. literalinclude:: ../../examples/szengine/why_search.txt
967+
:linenos:
968+
:language: json
969+
"""
970+
935971
# -------------------------------------------------------------------------
936972
# Convenience methods
937973
# -------------------------------------------------------------------------

src/senzing_mock/senzing_mock.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ def why_records(
328328
) -> str:
329329
return ""
330330

331+
def why_search(
332+
self,
333+
attributes: str,
334+
entity_id: int,
335+
flags: int = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS,
336+
search_profile: str = "",
337+
) -> str:
338+
return ""
339+
331340

332341
# -----------------------------------------------------------------------------
333342
# SzProductMock class

tests/szabstractfactory_test.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
TODO: szabstractfactory_test.py
55
"""
66

7-
87
import pytest
98

109
from senzing import (
@@ -17,55 +16,55 @@
1716
from senzing_mock import SzAbstractFactoryMock
1817

1918
# -----------------------------------------------------------------------------
20-
# SzAbstractFactory testcases
19+
# Test cases
2120
# -----------------------------------------------------------------------------
2221

2322

24-
def test_create_configmanager(szabstractfactory: SzAbstractFactory) -> None:
23+
def test_create_configmanager(sz_abstractfactory: SzAbstractFactory) -> None:
2524
"""Test SzAbstractFactory.create_configmanager()."""
26-
actual = szabstractfactory.create_configmanager()
25+
actual = sz_abstractfactory.create_configmanager()
2726
assert isinstance(actual, SzConfigManager)
2827

2928

30-
def test_create_diagnostic(szabstractfactory: SzAbstractFactory) -> None:
29+
def test_create_diagnostic(sz_abstractfactory: SzAbstractFactory) -> None:
3130
"""Test SzAbstractFactory.create_diagnostic()."""
32-
actual = szabstractfactory.create_diagnostic()
31+
actual = sz_abstractfactory.create_diagnostic()
3332
assert isinstance(actual, SzDiagnostic)
3433

3534

36-
def test_create_engine(szabstractfactory: SzAbstractFactory) -> None:
35+
def test_create_engine(sz_abstractfactory: SzAbstractFactory) -> None:
3736
"""Test SzAbstractFactory.create_engine()."""
38-
actual = szabstractfactory.create_engine()
37+
actual = sz_abstractfactory.create_engine()
3938
assert isinstance(actual, SzEngine)
4039

4140

42-
def test_create_product(szabstractfactory: SzAbstractFactory) -> None:
41+
def test_create_product(sz_abstractfactory: SzAbstractFactory) -> None:
4342
"""Test SzAbstractFactory.create_product()."""
44-
actual = szabstractfactory.create_product()
43+
actual = sz_abstractfactory.create_product()
4544
assert isinstance(actual, SzProduct)
4645

4746

48-
def test_help_1(szabstractfactory: SzAbstractFactory) -> None:
49-
"""Test SzAbstractFactory().help()."""
50-
szabstractfactory.help()
47+
def test_help_1(sz_abstractfactory: SzAbstractFactory) -> None:
48+
"""Test SzAbstractFactory.help()."""
49+
sz_abstractfactory.help()
5150

5251

53-
def test_help_2(szabstractfactory: SzAbstractFactory) -> None:
54-
"""Test SzAbstractFactory().help(...)."""
55-
szabstractfactory.help("create_configmanager")
52+
def test_help_2(sz_abstractfactory: SzAbstractFactory) -> None:
53+
"""Test SzAbstractFactory.help(...)."""
54+
sz_abstractfactory.help("create_configmanager")
5655

5756

58-
def test_reinitialize(szabstractfactory: SzAbstractFactory) -> None:
57+
def test_reinitialize(sz_abstractfactory: SzAbstractFactory) -> None:
5958
"""Test SzAbstractFactory.reinitialize()."""
60-
szabstractfactory.reinitialize(0)
59+
sz_abstractfactory.reinitialize(0)
6160

6261

6362
# -----------------------------------------------------------------------------
64-
# SzAbstractFactory fixtures
63+
# Fixtures
6564
# -----------------------------------------------------------------------------
6665

6766

68-
@pytest.fixture(name="szabstractfactory", scope="module")
67+
@pytest.fixture(name="sz_abstractfactory", scope="function")
6968
def szabstractfactory_fixture() -> SzAbstractFactory:
7069
"""
7170
Single sz_abstractfactory object to use for all tests.

tests/szconfig_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
TODO: szconfig_test.py
55
"""
66

7-
87
import pytest
98

109
from senzing import SzConfig
@@ -36,17 +35,17 @@ def test_get_data_sources(sz_config: SzConfig) -> None:
3635

3736

3837
def test_help_1(sz_config: SzConfig) -> None:
39-
"""Test SzConfig().help()."""
38+
"""Test SzConfig.help()."""
4039
sz_config.help()
4140

4241

4342
def test_help_2(sz_config: SzConfig) -> None:
44-
"""Test SzConfig().help(...)."""
43+
"""Test SzConfig.help(...)."""
4544
sz_config.help("add_data_source")
4645

4746

4847
# -----------------------------------------------------------------------------
49-
# szConfig fixtures
48+
# Fixtures
5049
# -----------------------------------------------------------------------------
5150

5251

tests/szconfigmanager_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def test_create_config_from_config_id(sz_configmanager: SzConfigManager) -> None
2020
sz_configmanager.create_config_from_config_id(0)
2121

2222

23-
def test_create_config_from_config_string(sz_configmanager: SzConfigManager) -> None:
24-
"""Test SzConfigManager.create_config_from_config_string()."""
23+
def test_create_config_from_string(sz_configmanager: SzConfigManager) -> None:
24+
"""Test SzConfigManager.create_config_from_string()."""
2525
sz_configmanager.create_config_from_string("")
2626

2727

28-
def test_create_config_from_config_template(sz_configmanager: SzConfigManager) -> None:
29-
"""Test SzConfigManager.create_config_from_config_string()."""
28+
def test_create_config_from_template(sz_configmanager: SzConfigManager) -> None:
29+
"""Test SzConfigManager.create_config_from_template()."""
3030
sz_configmanager.create_config_from_template()
3131

3232

@@ -41,17 +41,17 @@ def test_get_default_config_id(sz_configmanager: SzConfigManager) -> None:
4141

4242

4343
def test_help_1(sz_configmanager: SzConfigManager) -> None:
44-
"""Test SzConfigManager().help()."""
44+
"""Test SzConfigManager.help()."""
4545
sz_configmanager.help()
4646

4747

4848
def test_help_2(sz_configmanager: SzConfigManager) -> None:
49-
"""Test SzConfigManager().help(...)."""
49+
"""Test SzConfigManager.help(...)."""
5050
sz_configmanager.help("register_config")
5151

5252

5353
def test_register_config(sz_configmanager: SzConfigManager) -> None:
54-
"""Test SzConfigManager.add_config()."""
54+
"""Test SzConfigManager.register_config()."""
5555
sz_configmanager.register_config("", "")
5656

5757

@@ -71,7 +71,7 @@ def test_set_default_config_id(sz_configmanager: SzConfigManager) -> None:
7171

7272

7373
# -----------------------------------------------------------------------------
74-
# SzConfigManager fixtures
74+
# Fixtures
7575
# -----------------------------------------------------------------------------
7676

7777

0 commit comments

Comments
 (0)