Private
Public Access
91 lines
3.1 KiB
PHP
91 lines
3.1 KiB
PHP
<?php
|
|
require_once __DIR__.'/../lib/docset_repository.php';
|
|
|
|
URL::$route['page-title'] = 'Search';
|
|
$repo = new DocsetRepository();
|
|
$docsets = $repo->listDocsets();
|
|
$query = trim((string)($_GET['q'] ?? ''));
|
|
$selected = trim((string)($_GET['docset'] ?? ''));
|
|
$results = array();
|
|
$error = '';
|
|
if($query !== '')
|
|
{
|
|
try
|
|
{
|
|
$results = $repo->search($query, $selected, (int)cfg('docsets/search_limit'));
|
|
}
|
|
catch(Throwable $e)
|
|
{
|
|
$error = $e->getMessage();
|
|
Log::text('search', $error);
|
|
}
|
|
}
|
|
?>
|
|
<section class="hero card docset-hero">
|
|
<div>
|
|
<p class="eyebrow">Local Dash/Zeal documentation</p>
|
|
<h1>Search Zeal docsets</h1>
|
|
<p>Search indexed symbols, classes, methods, and guide pages from installed docsets.</p>
|
|
</div>
|
|
<div class="docset-count"><?= count($docsets) ?><span>docsets</span></div>
|
|
</section>
|
|
|
|
<section class="card search-panel">
|
|
<form method="get" action="<?= URL::Link('') ?>" class="search-form">
|
|
<label for="q">Search term</label>
|
|
<input id="q" name="q" type="search" value="<?= asafe($query) ?>" placeholder="array_map, PDO, DateTime..." autofocus>
|
|
<label for="docset">Docset</label>
|
|
<select id="docset" name="docset">
|
|
<option value="">All docsets</option>
|
|
<?php foreach($docsets as $docset) { ?>
|
|
<option value="<?= asafe($docset['id']) ?>"<?= $selected === $docset['id'] ? ' selected' : '' ?>><?= safe($docset['name']) ?></option>
|
|
<?php } ?>
|
|
</select>
|
|
<button type="submit">Search</button>
|
|
</form>
|
|
<?php if(!$docsets) { ?>
|
|
<p class="notice">No docsets found. Add Zeal/Dash <code>*.docset</code> folders to <code>data/docsets/</code>.</p>
|
|
<?php } ?>
|
|
</section>
|
|
|
|
<?php if($docsets) { ?>
|
|
<section class="card installed-docsets">
|
|
<div class="section-heading">
|
|
<h2>Installed docsets</h2>
|
|
<p>Open a docset directly or narrow searches with the selector above.</p>
|
|
</div>
|
|
<div class="docset-grid">
|
|
<?php foreach($docsets as $docset) { ?>
|
|
<a class="docset-card" href="<?= URL::Link('view', array('docset' => $docset['id'], 'path' => $docset['index_file'])) ?>">
|
|
<span class="docset-card-title"><?= safe($docset['name']) ?></span>
|
|
<span class="docset-card-meta"><?= number_format($docset['entry_count']) ?> indexed entries</span>
|
|
<?php if($docset['family'] !== '') { ?><span class="docset-card-family"><?= safe($docset['family']) ?></span><?php } ?>
|
|
</a>
|
|
<?php } ?>
|
|
</div>
|
|
</section>
|
|
<?php } ?>
|
|
|
|
<?php if($error !== '') { ?>
|
|
<section class="card warning"><h2>Search failed</h2><p><?= safe($error) ?></p></section>
|
|
<?php } ?>
|
|
|
|
<?php if($query !== '') { ?>
|
|
<section class="card results-card">
|
|
<h2><?= count($results) ?> results for “<?= safe($query) ?>”</h2>
|
|
<?php if(!$results) { ?>
|
|
<p>No matching entries found.</p>
|
|
<?php } else { ?>
|
|
<div class="result-list">
|
|
<?php foreach($results as $result) { ?>
|
|
<a class="result-row" href="<?= $result['href'] ?>">
|
|
<span class="result-title"><?= safe($result['name']) ?></span>
|
|
<span class="result-meta"><?= safe($result['type']) ?> · <?= safe($result['docset_name']) ?></span>
|
|
<span class="result-path"><?= safe($result['path']) ?></span>
|
|
</a>
|
|
<?php } ?>
|
|
</div>
|
|
<?php } ?>
|
|
</section>
|
|
<?php } ?>
|