Search with string, entry type and category So I have been asked to build a resource center just like hubspot's. (insert rolleyes here)

https://www.hubspot.com/resources

You can click into a type, and then click at topic and it creates a url like so:

https://www.hubspot.com/resources/ebook/advertising

You can also click a topic and then click type and it will do the same.

I have this part pretty much working. In my category template I have done this: 

    Filter by type:

    &lt;a href="/resources/case-studies/{{category.slug}}"&gt;case studies&lt;/a&gt;

    &lt;br/&gt;&lt;br/&gt;

    &lt;a href="/resources/ebooks/{{category.slug}}"&gt;ebooks&lt;/a&gt;

    &lt;br/&gt;&lt;br/&gt;

    &lt;a href="/resources/webinars/{{category.slug}}}"&gt;webinars&lt;/a&gt;

    &lt;br/&gt;&lt;br/&gt;

    &lt;a href="/resources/whitepapers/{{category.slug}}"&gt;whitepapers&lt;/a&gt;


then I have a routes for each type setup like this: 

if the URI looks like this: 

/resources/case-studies/*

Loads this template: 

resources/_filtered.html 

and in that template filtered I do the filtering like this: 

        {% set resourceType = craft.request.segment(2) %}

        {% set resourceCatSlug = craft.request.segment(3) %}

        {% set resourceCat = craft.categories.slug(resourceCatSlug).first() %}

        {{resourceType}}

        {{resourceCat}}

        {% set filteredEntries = craft.entries({
            section:    ['resources'],
            orderBy:    {postDate: SORT_DESC},
            type:       resourceType,
            relatedTo:  resourceCat,
        }).all() %}


This all works and I planned to do the same method on the resources types to get to the filtered template. 

But where I'm stuck is it was also requested that you could filter your search even further with a string search. 

So from this:

&lt;form class="control txt-center" action="{{ url('resources/search/results-filtered') }}"&gt;

&lt;input class="input margin-auto-left-right display-block is-narrow-field " type="search" name="q" placeholder="Search"&gt;

&lt;button class="margin-top-1 button is-info" role="button" type="submit"&gt; Search the library &lt;/button&gt;




How can I pass entry type and category to my filtered results?

{% set searchTerm = craft.app.request.getParam('q') %}
{% set searchResults = craft.entries.search(searchTerm).section('resources').orderBy('score') %}


PS, If anyone has a more elegant way to handle this I'm all ears!
A more elegant way to handle it would be to use PHP, rely on a more complex routing system with default values, don't rely on segments but on routing parameters. Use real URLs instead of relative paths and build your URLs dynamically instead of just inserting the string hard coded in order to be able to filter by multiple values without loosing the already set filters.

However - to include your parameters all you need to do

{% set searchResults = craft.entries
    .search(searchTerm)
    .section('resources')
    .type(resourceType)
    .orderBy('score') 
    .relatedTo(resourceCat)
%}


I would create a dynamic rule

$event-&gt;rules[] = [
    'pattern'  =&gt; '/resources/&lt;type:\S+&gt;/&lt;category:\S+&gt;/&lt;search:[a-zA-Z0-9-]+&gt;',
    'route'    =&gt; 'module/search/search-elements',
    'defaults' =&gt; [
        'type' =&gt; '',
        'category' =&gt; '',
        'search' =&gt; '',
    ]
];


and search in PHP

public function actionSearchElements(string $type, string $category, string $search)


You can then create a Twig function/filter in order to change those

&lt;a href="/resources/ebooks/{{category.slug}}"&gt;ebooks&lt;/a&gt;


to something like 

&lt;a href="{{ getSearchUrl({category: category.slug}) }}"&gt;ebooks&lt;/a&gt;


And build your URL based on your route params + overwrite the new category. It will make it more re-usable and easier to change in the future if you would like to add an additional parameter or need to change the order you only need to change one place instead of many