Create custom search plugins to extend Ayase Quart’s search functionality
Search plugins allow you to add custom search fields and logic to Ayase Quart. They integrate with the existing search form and can filter results based on custom criteria.
Search plugins return post numbers grouped by board. These results are then intersected with other plugin results and native search results to produce the final search results.The plugin system:
Collects results from all enabled search plugins
Intersects the results (if plugin #1 returns 0 results and plugin #2 returns 100, the final result is 0)
Performs native search filtering on the intersection
class SearchPluginResult: # Dictionary mapping board names to sets of post numbers board_2_nums: dict[str, set[int]] = {} # HTML message to display to the user flash_msg: str = '' # Whether a search was actually performed performed_search: bool = False
Here’s the complete example from src/ayase_quart/plugins/search/search_example.py:
from jinja2 import Templatefrom wtforms import Field, StringFieldfrom wtforms.validators import DataRequiredfrom ...forms import SearchFormfrom ...templates import envfrom ..i_search import SearchPlugin, SearchPluginResultclass SearchPluginExample(SearchPlugin): # Define custom form fields fields: list[Field] = [ StringField( label='sha256', name='sha256', id='sha256', validators=[DataRequired(message='Please enter a sha256sum.')] ), ] # Define the HTML template for rendering fields # WARNING: Any HTML in this string WILL be rendered template: Template = env.from_string(""" {% from 'macros/macros.html' import render_field %} <link rel="stylesheet" href="/static/plugins/example.css"> {{render_field(form.sha256)}} """) async def get_search_plugin_result(self, form: SearchForm) -> SearchPluginResult: # Perform your search based on the sha256 input... result = SearchPluginResult() # Example: populate with post numbers by board # result.board_2_nums = {'g': {1, 2, 3}, 'b': {1, 3, 5}} return result
The example is wrapped in if 0: to maintain syntax highlighting without loading it by default. Remove this condition in your actual plugin.
All plugin results are intersected. If your plugin returns an empty board_2_nums, the final search result will be empty regardless of what other plugins return.