Skip to content

Commit 10eddf7

Browse files
committed
Make the `fullname' field also match the demangled symbol name
* bdx/index.py (DatabaseField.key): Also accept a list of strings. (Schema.__post_init__): Use all provided keys as handlers. (SymbolIndex.SCHEMA): Modify `fullname' to also match `demangled' attribute. * tests/test_index.py (test_searching_by_exact_name_2): New test.
1 parent fc9ebe7 commit 10eddf7

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

bdx/index.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
List,
2626
Optional,
2727
Type,
28+
Union,
2829
)
2930

3031
import xapian
@@ -62,9 +63,9 @@ class DatabaseField:
6263
prefix: str
6364

6465
# This DatabaseField will be responsible for indexing the
65-
# following key/attribute of each document (Symbol) added to the
66-
# index.
67-
key: str
66+
# following key(s)/attribute(s) of each document (Symbol) added to
67+
# the index.
68+
key: Union[str, list[str]]
6869

6970
def index(self, document: xapian.Document, value: Any):
7071
"""Index ``value`` in the ``document``."""
@@ -418,7 +419,11 @@ def __post_init__(self):
418419
msg = f"'{db_field.name}' is duplicated in the schema"
419420
raise ValueError(msg)
420421
self._field_dict[db_field.name] = db_field
421-
self._handlers[db_field.key].append(db_field)
422+
if isinstance(db_field.key, str):
423+
self._handlers[db_field.key].append(db_field)
424+
else:
425+
for key in db_field.key:
426+
self._handlers[key].append(db_field)
422427

423428
def __getitem__(self, key):
424429
if not self.fields:
@@ -470,7 +475,13 @@ def __iter__(self) -> Iterator[Symbol]:
470475
optional_field(
471476
SymbolNameField("demangled", "XD", key="demangled")
472477
),
473-
DatabaseField("fullname", "XFN", key="name"),
478+
optional_field(
479+
# This field is optional as `demangled' attribute can
480+
# be None. In case it is None, this field will still
481+
# be indexed, as `name' is not optional, but it will
482+
# not index the None value.
483+
DatabaseField("fullname", "XFN", key=["name", "demangled"])
484+
),
474485
DatabaseField("section", "XSN", key="section"),
475486
IntegerField("address", "XA", slot=0, key="address"),
476487
IntegerField("size", "XSZ", slot=1, key="size"),

tests/test_index.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,20 @@ def test_searching_by_exact_name(fixture_path, readonly_index):
518518
assert not_matching_exactly[2].name == "uses_foo"
519519

520520

521+
def test_searching_by_exact_name_2(fixture_path, readonly_index):
522+
symbols = list(
523+
readonly_index.search('fullname:"CppCamelCaseSymbol(char const*)"')
524+
)
525+
symbols2 = list(
526+
readonly_index.search("fullname:_Z18CppCamelCaseSymbolPKc")
527+
)
528+
529+
assert symbols
530+
assert symbols == symbols2
531+
532+
assert symbols[0].name == "_Z18CppCamelCaseSymbolPKc"
533+
534+
521535
def test_searching_camel_case(readonly_index):
522536
symbols = set(readonly_index.search("camel"))
523537
assert symbols

0 commit comments

Comments
 (0)