+1
-1
@@ -197,7 +197,7 @@ pre.raw-line { background: var(--bs-tertiary-bg); padding: .75rem; border-radius
|
|||||||
<input type="text" class="form-control" id="logSearchInput" placeholder="Search all log lines..." maxlength="200">
|
<input type="text" class="form-control" id="logSearchInput" placeholder="Search all log lines..." maxlength="200">
|
||||||
<button class="btn btn-primary" id="logSearchBtn"><i class="bi bi-search me-1"></i>Search</button>
|
<button class="btn btn-primary" id="logSearchBtn"><i class="bi bi-search me-1"></i>Search</button>
|
||||||
</div>
|
</div>
|
||||||
<small class="text-secondary mt-1 d-block">Use FTS5 syntax: <code>error</code>, <code>"disk full"</code>, <code>error NOT warning</code>, <code>auth*</code></small>
|
<small class="text-secondary mt-1 d-block">Search terms: <code>error 500</code>, <code>"disk full"</code>, <code>auth*</code>. Boolean operators like <code>NOT</code> not supported.</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|||||||
@@ -171,14 +171,34 @@ class Repository
|
|||||||
|
|
||||||
public function searchLogEntries(string $query, int $limit = 200, int $offset = 0): array
|
public function searchLogEntries(string $query, int $limit = 200, int $offset = 0): array
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
$stmt = $this->db->pdo()->prepare(
|
||||||
|
"SELECT e.* FROM log_entries e
|
||||||
|
JOIN log_entries_fts fts ON e.id = fts.rowid
|
||||||
|
WHERE log_entries_fts MATCH ?
|
||||||
|
ORDER BY rank
|
||||||
|
LIMIT ? OFFSET ?"
|
||||||
|
);
|
||||||
|
$stmt->execute([$query, $limit, $offset]);
|
||||||
|
return $stmt->fetchAll();
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
if (str_contains($e->getMessage(), 'fts5: syntax error')) {
|
||||||
|
return $this->searchLogEntriesLike($query, $limit, $offset);
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function searchLogEntriesLike(string $query, int $limit = 200, int $offset = 0): array
|
||||||
|
{
|
||||||
|
$like = '%' . str_replace(['%', '_'], ['\\%', '\\_'], $query) . '%';
|
||||||
$stmt = $this->db->pdo()->prepare(
|
$stmt = $this->db->pdo()->prepare(
|
||||||
"SELECT e.* FROM log_entries e
|
"SELECT e.* FROM log_entries e
|
||||||
JOIN log_entries_fts fts ON e.id = fts.rowid
|
WHERE e.line LIKE ?
|
||||||
WHERE log_entries_fts MATCH ?
|
ORDER BY e.created_at DESC
|
||||||
ORDER BY rank
|
|
||||||
LIMIT ? OFFSET ?"
|
LIMIT ? OFFSET ?"
|
||||||
);
|
);
|
||||||
$stmt->execute([$query, $limit, $offset]);
|
$stmt->execute([$like, $limit, $offset]);
|
||||||
return $stmt->fetchAll();
|
return $stmt->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user