Fast search with filters and pagination.
(
self,
query: str = "",
trigger_filter: str = "all",
complexity_filter: str = "all",
active_only: bool = False,
limit: int = 50,
offset: int = 0,
)
| 537 | return stats |
| 538 | |
| 539 | def search_workflows( |
| 540 | self, |
| 541 | query: str = "", |
| 542 | trigger_filter: str = "all", |
| 543 | complexity_filter: str = "all", |
| 544 | active_only: bool = False, |
| 545 | limit: int = 50, |
| 546 | offset: int = 0, |
| 547 | ) -> Tuple[List[Dict], int]: |
| 548 | """Fast search with filters and pagination.""" |
| 549 | conn = sqlite3.connect(self.db_path) |
| 550 | conn.row_factory = sqlite3.Row |
| 551 | |
| 552 | # Build WHERE clause |
| 553 | where_conditions = [] |
| 554 | params = [] |
| 555 | |
| 556 | if active_only: |
| 557 | where_conditions.append("w.active = 1") |
| 558 | |
| 559 | if trigger_filter != "all": |
| 560 | where_conditions.append("w.trigger_type = ?") |
| 561 | params.append(trigger_filter) |
| 562 | |
| 563 | if complexity_filter != "all": |
| 564 | where_conditions.append("w.complexity = ?") |
| 565 | params.append(complexity_filter) |
| 566 | |
| 567 | # Use FTS search if query provided |
| 568 | if query.strip(): |
| 569 | # FTS search with ranking |
| 570 | base_query = """ |
| 571 | SELECT w.*, rank |
| 572 | FROM workflows_fts fts |
| 573 | JOIN workflows w ON w.id = fts.rowid |
| 574 | WHERE workflows_fts MATCH ? |
| 575 | """ |
| 576 | params.insert(0, query) |
| 577 | else: |
| 578 | # Regular query without FTS |
| 579 | base_query = """ |
| 580 | SELECT w.*, 0 as rank |
| 581 | FROM workflows w |
| 582 | WHERE 1=1 |
| 583 | """ |
| 584 | |
| 585 | if where_conditions: |
| 586 | base_query += " AND " + " AND ".join(where_conditions) |
| 587 | |
| 588 | # Count total results |
| 589 | count_query = f"SELECT COUNT(*) as total FROM ({base_query}) t" |
| 590 | cursor = conn.execute(count_query, params) |
| 591 | total = cursor.fetchone()["total"] |
| 592 | |
| 593 | # Get paginated results |
| 594 | if query.strip(): |
| 595 | base_query += " ORDER BY rank" |
| 596 | else: |
no test coverage detected