pyutils.search package
Submodules
pyutils.search.logical_search module
logical_search.py - In-memory boolean and property query engine.
Supports: - Boolean: and, or, not, () - Tags: exact string match - Properties: key:val, key==val, key<val, key>val, key<=val, key>=val - Temporal: ISO 8601 strings (YYYY-MM-DD[THH:MM:SS]) support full comparison - Regex: key~^pattern - IN: key:[val1,val2] - BETWEEN: key:min..max
- class pyutils.search.logical_search.Corpus[source]
Bases:
objectThe indexing and search engine.
- add_doc(doc: Document) None[source]
Indexes a document. Supports the list-of-tuples properties.
- Parameters:
doc (Document)
- Return type:
None
- get_doc(docid: str) Document | None[source]
Given a docid, retrieve the previously added Document.
- Parameters:
docid (str) – the docid to retrieve
- Returns:
The Document with docid or None to indicate no match.
- Return type:
Document | None
- get_docids_by_exact_tag(tag: str) Set[str][source]
Return the set of docids that have a particular tag.
- Parameters:
tag (str) – the tag for which to search
- Returns:
A set containing docids with the provided tag which may be empty.
- Return type:
Set[str]
- get_docids_by_property(key: str, value: str) Set[str][source]
Return the set of docids that have a particular property with a particular value.
- Parameters:
key (str) – the key to search for
value (str) – the value that key must have in order to match a doc.
- Returns:
A set of docids that contain key with value which may be empty.
- Return type:
Set[str]
- get_docids_by_searching_tags(tag: str) Set[str][source]
Return the set of docids with a tag that contains a str.
- Parameters:
tag (str) – the tag pattern for which to search
- Returns:
A set containing docids with tags that match the pattern provided. e.g., if the arg was “foo” tags “football”, “foobar”, and “food” all match.
- Return type:
Set[str]
- get_docids_with_property(key: str) Set[str][source]
Return the set of docids that have a particular property no matter what that property’s value.
- Parameters:
key (str) – the key value to search for.
- Returns:
A set of docids that contain the key (no matter what value) which may be empty.
- Return type:
Set[str]
- class pyutils.search.logical_search.Document(docid: str = '', tags: ~typing.Set[str] = <factory>, properties: ~typing.List[~typing.Tuple[str, str]] = <factory>, reference: ~typing.Any | None = None)[source]
Bases:
objectA searchable unit. Properties remain a list of tuples for compatibility.
- Parameters:
docid (str)
tags (Set[str])
properties (List[Tuple[str, str]])
reference (Any | None)
- docid: str = ''
- properties: List[Tuple[str, str]]
- reference: Any | None = None
- tags: Set[str]