Basic Search
The streams plugin allows you to set up a basic search for your data and display the results on another page. You can select the fields to search, and also paginate the results.
It's important to note that this search only searches what is in the streams table itself. So, for instance, the image field type only stores the foreign key of the image record in the files table, so you cannot search for image metadata through this search method.
The Search Form
The streams plugin search form allows you to set up some of the basic bits of info about your search. Here is an example form:
{{ streams:search_form stream="artists" fields="name|bio" results_page="search" }}
{{ form_open }}
<p>{{ search_input }}</p>
<p>{{ form_submit }}</p>
{{ form_close }}
{{ /streams:search_form }}
Parameters
| Parameter | Default | Description |
|---|---|---|
| stream | Stream to search. | |
| fields | Fields in the stream to search separated by a pipe character (|). | |
| search_type | full_phrase | The type of search to preform. Values can be full_phrase or keywords. A full phrase search will perform a LIKE search for the full search term, and the keywords search will break the search term down into keywords and search for them separately. |
| results_page | URI where you want to display the results. This should be a page with the search_results tag. |
Tags
| Tag | Description |
|---|---|
| {{ form_open }} | Form open tag. |
| {{ form_close }} | Form close tag. |
| {{ search_input }} | The search input. |
| {{ form_submit }} | The search from submit. |
Search Results
The search results tag allows you to display search results from your search_form input.
{{ streams:search_results per_page="10" cache_segment="2" }}
<p>Your search for {{ search_term }} returned {{ total_results }} results.</p>
{{ results }}
<h2>{{ name }}</p>
{{ /results }}
{{ pagination }}
{{ /streams:search_results }}
Parameters
| Parameter | Default | Description |
|---|---|---|
| paginate | no | Should we paginate the results? Yes or no. |
| per_page | 25 | Number of items per page with pagination. |
| cache_segment | 3 | Each search has a cache id in the url. You can specify the segment in this parameter. The segment after this should be clear for pagination offsets if need be. |
| per_page | 25 | Number of items per page with pagination. |
Tags
| Tag | Description |
|---|---|
| {{ results }} {{ /results }} | Tag pair to loop through results. |
| {{ pagination }} | Pagination, if you are paginating results. |
| {{ search_term }} | The search term that was submitted. |
| {{ total_results }} | The total number of results returned. |
The Results Page URI
Your results page should have room in the URI for the cache segment and pagination offset (if necessary). To accomplish this, you should create a page with strict URI matching turned off, so PyroCMS will ignore the segment where the cache key segment is placed.
