-
-
Notifications
You must be signed in to change notification settings - Fork 40
Add documentation search API with Sprunje integration, wildcard support, caching, and metadata search #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
13
commits into
main
Choose a base branch
from
copilot/add-documentation-search-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
735bc48
Initial plan
Copilot cc01465
Add search feature implementation with API, indexing, and tests
Copilot 07b03ae
Address code review feedback: optimize search performance and improve…
Copilot 1a1decc
Fix error handling in preg_replace and cache retrieval
Copilot 0e1a628
Address code review feedback: add config values, validation, metadata…
Copilot 09445cb
Update tests for new index structure and validation behavior
Copilot 54b1f48
Integrate Sprunje for pagination and response formatting
Copilot 6869f42
Fix Sprunje integration issues: pagination, validation, and error han…
Copilot c984e86
Improve code comments for clarity and accuracy
Copilot 4e8b2e0
Major refactor: fix config structure, Sprunje integration, and addres…
Copilot 56f2180
Update tests for NotFoundException error handling
Copilot 6059737
Improve SearchSprunje: use named DummySearchModel class and fix comments
Copilot f0b6e57
Remove slop, apply better sprunje
lcharette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * UserFrosting Learn (http://www.userfrosting.com) | ||
| * | ||
| * @link https://github.com/userfrosting/Learn | ||
| * @copyright Copyright (c) 2025 Alexander Weissman & Louis Charette | ||
| * @license https://github.com/userfrosting/Learn/blob/main/LICENSE.md (MIT License) | ||
| */ | ||
|
|
||
| namespace UserFrosting\Learn\Bakery; | ||
|
|
||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use UserFrosting\Bakery\WithSymfonyStyle; | ||
| use UserFrosting\Learn\Search\SearchIndex; | ||
|
|
||
| /** | ||
| * Bakery command to rebuild the search index for documentation. | ||
| */ | ||
| class SearchIndexCommand extends Command | ||
| { | ||
| use WithSymfonyStyle; | ||
|
|
||
| /** | ||
| * @param SearchIndex $searchIndex | ||
| */ | ||
| public function __construct( | ||
| protected SearchIndex $searchIndex, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| protected function configure(): void | ||
| { | ||
| $this->setName('search:index') | ||
| ->setDescription('Build or rebuild the search index for documentation') | ||
| ->addOption( | ||
| 'doc-version', | ||
| null, | ||
| InputOption::VALUE_OPTIONAL, | ||
| 'Documentation version to index (omit to index all versions)' | ||
| ) | ||
| ->addOption( | ||
| 'clear', | ||
| null, | ||
| InputOption::VALUE_NONE, | ||
| 'Clear the search index before rebuilding' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| $this->io->title('Documentation Search Index'); | ||
|
|
||
| /** @var string|null $version */ | ||
| $version = $input->getOption('doc-version'); | ||
| $clear = $input->getOption('clear'); | ||
|
|
||
| // Clear index if requested | ||
| if ($clear === true) { | ||
| $this->io->writeln('Clearing search index...'); | ||
| $this->searchIndex->clearIndex($version); | ||
| $this->io->success('Search index cleared.'); | ||
| } | ||
|
|
||
| // Build index | ||
| $versionText = $version !== null ? "version {$version}" : 'all versions'; | ||
| $this->io->writeln("Building search index for {$versionText}..."); | ||
|
|
||
| try { | ||
| $count = $this->searchIndex->buildIndex($version); | ||
| $this->io->success("Search index built successfully. Indexed {$count} pages."); | ||
| } catch (\Exception $e) { | ||
| $this->io->error("Failed to build search index: {$e->getMessage()}"); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * UserFrosting Learn (http://www.userfrosting.com) | ||
| * | ||
| * @link https://github.com/userfrosting/Learn | ||
| * @copyright Copyright (c) 2025 Alexander Weissman & Louis Charette | ||
| * @license https://github.com/userfrosting/Learn/blob/main/LICENSE.md (MIT License) | ||
| */ | ||
|
|
||
| namespace UserFrosting\Learn\Controller; | ||
|
|
||
| use Psr\Http\Message\ResponseInterface as Response; | ||
| use Psr\Http\Message\ServerRequestInterface as Request; | ||
| use UserFrosting\Config\Config; | ||
| use UserFrosting\Learn\Search\SearchService; | ||
| use UserFrosting\Learn\Search\SearchSprunje; | ||
|
|
||
| /** | ||
| * Controller for the documentation search API. | ||
| */ | ||
| class SearchController | ||
| { | ||
| public function __construct( | ||
| protected SearchService $searchService, | ||
| protected Config $config, | ||
| protected SearchSprunje $sprunje, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * Search documentation pages. | ||
| * Request type: GET. | ||
| * | ||
| * Query parameters: | ||
| * - q: Search query (required, min length from config) | ||
| * - page: Page number for pagination (optional, from config) | ||
| * - size: Number of results per page (optional, from config, max from config) | ||
| * | ||
| * @param Request $request | ||
| * @param Response $response | ||
| */ | ||
| public function search(Request $request, Response $response): Response | ||
| { | ||
| $params = $request->getQueryParams(); | ||
|
|
||
| $this->sprunje->setOptions([ | ||
| 'query' => $params['q'] ?? '', | ||
| 'page' => $params['page'] ?? null, | ||
| 'size' => $params['size'] ?? null, | ||
| ]); | ||
|
|
||
| return $this->sprunje->toResponse($response); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * UserFrosting Learn (http://www.userfrosting.com) | ||
| * | ||
| * @link https://github.com/userfrosting/Learn | ||
| * @copyright Copyright (c) 2025 Alexander Weissman & Louis Charette | ||
| * @license https://github.com/userfrosting/Learn/blob/main/LICENSE.md (MIT License) | ||
| */ | ||
|
|
||
| namespace UserFrosting\Learn\Search; | ||
|
|
||
| /** | ||
| * Shared type definitions for search functionality. | ||
| * | ||
| * This interface defines the structure of indexed pages and search results. | ||
| * It uses @phpstan-type to create reusable type aliases that can be | ||
| * imported by other classes. | ||
| * | ||
| * Page indexed for search. | ||
| * @phpstan-type IndexedPage array{ | ||
| * title: string, | ||
| * slug: string, | ||
| * route: string, | ||
| * content: string, | ||
| * version: string, | ||
| * keywords: string, | ||
| * metadata: string | ||
| * } | ||
| * | ||
| * Search result with snippet. | ||
| * @phpstan-type SearchResult array{ | ||
| * title: string, | ||
| * slug: string, | ||
| * route: string, | ||
| * snippet: string, | ||
| * matches: int, | ||
| * version: string | ||
| * } | ||
| */ | ||
| interface IndexedPageShape | ||
| { | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make key name more descriptive, result in a sub array, index should be under search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 4e8b2e0. Moved
learn.indexconfiguration underlearn.search.indexwithmetadata_fieldsarray.