Searching a specific section by four different types of parameters? I'll do my best to explain this.

I have a Portfolio of companies, which I have as a structure, that I need to be able to filter/search through by using up to four different parameters.


Keyword - a basic search field that a user can type into
Industry - a category field
Company Status - a dropdown field
Board Members - a relation to a different structure


I know how to search these individually but I'm not quite sure how to use any combo of these all at once. Whether that be using a keyword and industry to search, all four items to search, maybe just by industry and board members, or maybe just by industry.

Below is what I have so far. Hoping someone will be able to point me in the right direction or help me piece this together.

This handles the search

{# What is being searched #}
{% set portfolio = craft.entries.section('portfolio') %}

{# Potential Query Strings #}
{% set query = craft.request.getParam('q') %}
{% set industryParam = craft.request.getParam('industry') %}
{% set statusParam = craft.request.getParam('status') %}
{% set boardMemberParam = craft.request.getParam('boardMember') %}

{# Related to Industry and/or Board Member #}
{% set industry = craft.categories.group('industries').slug(industryParam).first %}

{# Here's where I'm not sure how to combine the relatedTo for the industry, status, and/or board members #}
{% set relationParam = industryParam ? {targetElement: industry} : '' %}

{% set entries = portfolio.relatedTo(relationParam).search(query) %}

{# Probably best to not use search, as it's slower than relatedTo, so I commented this out. #}
{# .search('companyStatus::"' ~ statusParam ~ '"') #}

{# Spit out the entries #}
{% if entries|length %}

  {% for entry in entries %}
    &lt;article class="portfolio-item grid-3"&gt;
      &lt;a class="portfolio-item-content" href="{{ entry.url }}"&gt;
        &lt;h3 class="portfolio-item-title"&gt;{{ entry.title }}&lt;/h3&gt;
      &lt;/a&gt;
    &lt;/article&gt;
  {% endfor %}

{% else %} {# If nothing matches the search criteria #}

  &lt;p&gt;Sorry, no results.&lt;/p&gt;

{% endif %}


Stripped down version of where the user sets the parameters

&lt;form action="{{ url('portfolio') }}"&gt;
  &lt;h3 class="sidebar-title"&gt;Filter by Keyword&lt;/h3&gt;
  &lt;input type="search" name="q" placeholder="Search"&gt;

  &lt;h3 class="sidebar-title"&gt;Filter by Industry&lt;/h3&gt;
  &lt;select class="fancy" name="industry"&gt;
    &lt;option value=""&gt;All Industries&lt;/option&gt;

    {# Only get categories that are being used. #}
    {# This will definitely need some cache tags. #}
    {% set categories = craft.categories.group('industries').order('title asc') %}
    {% set entriesWithCategories = craft.entries.relatedTo(categories) %}
    {% set categoriesInUse = craft.categories.relatedTo(entriesWithCategories) %}

    {% for category in categoriesInUse %}
      &lt;option value="{{ category.slug }}"&gt;{{ category.title }}&lt;/option&gt;
    {% endfor %}
  &lt;/select&gt;

  &lt;h3 class="sidebar-title"&gt;Filter by Status&lt;/h3&gt;
  &lt;select class="fancy" name="status"&gt;
    &lt;option value=""&gt;All Statuses&lt;/option&gt;
    &lt;option value="active"&gt;Active&lt;/option&gt;
    &lt;option value="past"&gt;Past&lt;/option&gt;
  &lt;/select&gt;

  &lt;h3 class="sidebar-title"&gt;Filter by Board Member&lt;/h3&gt;
  &lt;select class="fancy" name="boardMember"&gt;
    &lt;option value=""&gt;All Board Memebers&lt;/option&gt;
    {% set team = craft.entries.section('team') %}
    {% for member in team %}
      &lt;option value="{{ member.slug }}"&gt;{{ member.title }}&lt;/option&gt;
    {% endfor %}
  &lt;/select&gt;

  &lt;input type="submit" value="Go"&gt;
&lt;/form&gt;


And if possible, how would I do this with AJAX? This can come later, initial search function is 100% okay. I know I could do the the AJAX filter completely on the Front-End but there's potential that the client will want to eventually add pagination if they start adding a bunch of companies to their portfolio.

Thanks in advance.
One method is to build your params before performing the search.

{# set base params #}
{% set params = {
    section: 'portfolio',
    limit: null
} %}
{% set relatedParams = ['and'] %}

{# status #}
{% if craft.request.getParam('status') %}
    {% set status = craft.request.getParam('status') %}
    {% set params = params|merge({'companyStatus':status}) %}
{% endif %}

{# industry #}
{% if craft.request.getParam('industry') %}
    {% set category = craft.categories.group('industries').slug(craft.request.getParam('industry')).first %}
    {% set relatedParams = relatedParams|merge([{ targetElement:category }]) %}
{% endif %}

{# board member #}
{% if craft.request.getParam('boardMember') %}
    {% set boardMember = craft.entries.section('team').slug(craft.request.getParam('boardMember')).first %}
    {% set relatedParams = relatedParams|merge([{ targetElement:boardMember }]) %}
{% endif %}

{# add relatedParams to params #}
{% if relatedParams|length &gt; 1 %}
    {% set params = params|merge({'relatedTo':relatedParams}) %}
{% endif %}

{# perform search #}
{% set searchParams = craft.request.getParam('q') %}
{% set entries = craft.entries(params).search(searchParams|trim) %}

{# display results #}
{% for entry in entries %}
    {{ entry.title }}
    ...
{% endfor %}


To AJAX load results you would place this in another template and load it dynamically with jquery. See this answer for an example.

To paginate the results you will need to submit your form as "GET" and append the query to your nextPage and prevPage links. See this answer for an example.