Search the database using unix glob-style matching (wildcards * and ?). Parameters ---------- pattern : str The wildcarded pattern to match when searching search_raw : bool If True, search the raw input, otherwise, the parsed input
(
self,
pattern: str = "*",
raw: bool = True,
search_raw: bool = True,
output: bool = False,
n: Optional[int] = None,
unique: bool = False,
)
| 476 | |
| 477 | @catch_corrupt_db |
| 478 | def search( |
| 479 | self, |
| 480 | pattern: str = "*", |
| 481 | raw: bool = True, |
| 482 | search_raw: bool = True, |
| 483 | output: bool = False, |
| 484 | n: Optional[int] = None, |
| 485 | unique: bool = False, |
| 486 | ) -> Iterable[tuple[int, int, InOrInOut]]: |
| 487 | """Search the database using unix glob-style matching (wildcards |
| 488 | * and ?). |
| 489 | |
| 490 | Parameters |
| 491 | ---------- |
| 492 | pattern : str |
| 493 | The wildcarded pattern to match when searching |
| 494 | search_raw : bool |
| 495 | If True, search the raw input, otherwise, the parsed input |
| 496 | raw, output : bool |
| 497 | See :meth:`get_range` |
| 498 | n : None or int |
| 499 | If an integer is given, it defines the limit of |
| 500 | returned entries. |
| 501 | unique : bool |
| 502 | When it is true, return only unique entries. |
| 503 | |
| 504 | Returns |
| 505 | ------- |
| 506 | Tuples as :meth:`get_range` |
| 507 | """ |
| 508 | tosearch = "source_raw" if search_raw else "source" |
| 509 | if output: |
| 510 | tosearch = "history." + tosearch |
| 511 | self.writeout_cache() |
| 512 | sqlform = "WHERE %s GLOB ?" % tosearch |
| 513 | params: tuple[typing.Any, ...] = (pattern,) |
| 514 | if unique: |
| 515 | sqlform += " GROUP BY {0}".format(tosearch) |
| 516 | if n is not None: |
| 517 | sqlform += " ORDER BY session DESC, line DESC LIMIT ?" |
| 518 | params += (n,) |
| 519 | elif unique: |
| 520 | sqlform += " ORDER BY session, line" |
| 521 | cur = self._run_sql(sqlform, params, raw=raw, output=output, latest=unique) |
| 522 | if n is not None: |
| 523 | return reversed(list(cur)) |
| 524 | return cur |
| 525 | |
| 526 | @catch_corrupt_db |
| 527 | def get_range( |