Product search

For additional examples see here.

For additional examples see here.

The Product Search Tag executes a search on the company's experiences, it then paginates those results.

Parameters

ParameterRequiredDescription
active_promotionWhen true, only returns items with an active promotion.
categoryEasol predefined category (single value or array).
countryCountry code or name (single value or array).
departure_dateDate filter object with equal_to, greater_than, greater_or_equal_than, or less_than.
departure_monthMonth name or number.
durationDuration filter object with equal_to, greater_than, or less_than.
namePartial match on product name.
subcategoryEasol predefined subcategory (single value or array).
page_sizeResults per page (default 12).
include_organisation_productsWhen true, includes products from linked organisation companies.
sortSort order: name_asc, name_desc, duration_asc, duration_desc, departure_date_asc, departure_date_desc.
input
{% product_search name: 'Beyond', duration: { greater_than: 3, less_than: 8 }, page_size: 12, sort: 'departure_date_asc' %}
  {% for item in result.items %}
    <p>{{ item.name }}</p>
  {% endfor %}
  <div>
    {{ paginate.collection_size }} Results
    {{ paginate | default_pagination }}
  </div>
{% endproduct_search %}
output
<p>Beyond Sahara</p>
<p>Beyond Archipelago</p>
<p>Beyond Sahara Friends & Family</p>
<p>Beyond Archipelago Friends & Family</p>
<p>Beyond Asia</p>
<div>
  112 Results
  <span class="prev">
    <a href="http://beyondadventures.com/pagination-test?page=2">Previous</a>
  </span>
  <span class="page">
    <a href="http://beyondadventures.com/pagination-test?page=1">1</a>
  </span>
  <span class="page">
    <a href="http://beyondadventures.com/pagination-test?page=2">2</a>
  </span>
  <span class="page current">3</span>
  <span class="page">
    <a href="http://beyondadventures.com/pagination-test?page=4">4</a>
  </span>
  <span class="page">
    <a href="http://beyondadventures.com/pagination-test?page=5">5</a>
  </span>
  <span class="deco">&hellip;</span>
  <span class="page">
    <a href="http://beyondadventures.com/pagination-test?page=9">9</a>
  </span>
  <span class="next">
    <a href="http://beyondadventures.com/pagination-test?page=4">Next</a>
  </span>
</div>

The tag returns an items array and a Paginate pagination object to the block passed in, the items array represents 1 page of the results from the search.

Pagination

The results of this search are paginated for performance reasons, with this you can define the number of results to display per page as the page_size attribute, which defaults to 12.

For performance, do not exceed a page_size of 12. Use infinite scroll or load-more patterns when displaying larger result sets.

Available months

The product search returns available_months, an array of Date objects, which can be used to construct the month and year filters for searching.

Each Date is dated 1st of the month, and there is one for each month in which a product's slot start_on date occurs.

E.g. Today is 1st Jan 2024. You have a product with a 10 day duration, with the following slots (all future or ongoing);

  • 31th Dec 2023
  • 15th Jan 2024
  • 20th Jan 2024
  • 31th Jan 2024
  • 28th Feb 2024 The available_months will be Dates with the following dates:
  • 1st Dec 2023
  • 1st Jan 2024
  • 1st Feb 2024

You can use these to construct search filters, e.g.

input
{% product_search %}
  <select name="departure_month">
    {% for month in available_months %}
      <option value="{{ month | date: "%m" }}">
        {{ month | date: "%B" }}
      </option>
    {% endfor %}
  </select>
{% endproduct_search %}
output
<select name="departure_month">
  <option value="12">December</option>
  <option value="01">January</option>
  <option value="02">February</option>
</select>

Search Params

Search params can be handled in one of two ways:

Passing explicit attributes

It's possible to use any of the following attributes in the search tag itself, this is useful for building a page responsible for a specific type of product.

active_promotion

Passing true to this will mean all items returned will have a currently active promotion.

category

Will search for products which match the category passed, this must use one of Easol's predefined categories and will accept either a single Category or an array.

country

This attribute accepts either Country Codes or Country Names and can be passed as a single attribute or as an array, e.g. country: ['FR', 'DE']

departure_date

This attribute takes an object which specifies how to handle the search, through equal_to greater_than greater_or_equal_than or less_than each taking a date in SQL format YYYY-MM-DD e.g. departure_date: {greater_than: 'now', less_than: '2019-12-28' }

departure_month

This allows you to specify which month the trips should depart in, e.g. passing departure_date: 'Apr' would return any trips departing in april 2020, april 2021 ..., You can also pass the number of the month i.e. departure_month: 4 would return the same results.

duration

This attribute takes an object which specifies how to handle the search, through equal_to greater_than or less_than each taking a number of days e.g. duration: {greater_than: 3, less_than: 8 }

name

This executes a partial search on the string passed in and will return any products whose name matches the argument.

subcategory

Will search for products which match the subcategory passed, this must use one of Easol's predefined subcategories and will accept either a single Subcategory or an array.

page_size

Will determine how many results are shown per page. If this is not included it will default to 12 results per page. e.g. page_size: 12

include_organisation_products

This allows you to include products from other companies which are linked in the same organisation. e.g. include_organisation_products: true

sort

The sorting order of results. The available options are: name_asc, name_desc, duration_asc, duration_desc, departure_date_asc and departure_date_desc, where the _asc and _desc parts represent ascending and descending orders respectively.

product_id

Filters products by their ID. This attribute accepts either a single product ID or an array of product IDs, e.g. product_id: 'abc123' or product_id: ['abc123', 'def456']

series_id

The id of the series to filter by.

As query params

It's also possible to pass search params as query params, this is useful when building dynamic search pages.

Any of the above attributes can be used as a query param and should all be namespaced to search

e.g. http://beyondadventures.com/search?search[name]=beyond&search[departure_date][greater_than]=2021-11-22

Params passed through a query param will overwrite any of those specified as an attribute

Tag-based filtering

If the company has added tags to their products, these can be used to filter the results outputted by the search tag.

Product tags are textual values that identify attributes of the products. They are grouped under categories which the company is also able to define.

Some examples of these might be Amenities, Difficulty, Distance, etc. Consult the company for the available tags and categories.

Star rating for accommodations is a separate product field, not a tag — do not use tag categories to represent it in examples.

Syntax

product_search filters results if one or more search query parameters are present in the URL. The search query parameters are in the format search[<tag category>][]=<tag value>; add as many as needed to filter the results.

You can specify multiple categories and values by repeating the search[][] query parameter.

Filtering returns products that match at least one of the provided values in all of the filtered categories.

Examples

  • ?search[Difficulty][]=Easy - Products tagged Easy under Difficulty only.
  • ?search[Difficulty][]=Easy&search[Difficulty][]=Moderate - Products tagged Easy or Moderate under Difficulty.
  • ?search[Amenities][]=Pool&search[Difficulty][]=Hard - Products tagged Pool under Amenities and Hard under Difficulty.
  • ?search[Amenities][]=Pool&search[Amenities][]=Gym&search[Difficulty][]=Hard - Products tagged Pool or Gym under Amenities, and Hard under Difficulty.

Sorting

It's possible to also sort the results by name, departure date and duration. This can be done either through an attribute on the tag or through the search query param.

These should be passed as a string describing the dimension to sort on and the direction either ascending or descending. i.e. one of

name_asc name_desc duration_asc duration_desc departure_date_asc departure_date_desc

{% product_search name: 'Beyond', sort: 'name_asc' %}
  {% for item in result.items %}
    <p>{{ item.name }}</p>
  {% endfor %}

  <div>
    {{ paginate.collection_size }} Results
    {{ paginate | default_pagination }}
  </div>
{% endproduct_search %}

or

http://beyondadventures.com/search?search[name]=beyond&search[sort]=name_asc

Accessing the query params

Once the search has been executed, it can be helpful to get a reference to the params and values in the search. For that, we can use the Search object. It exposes the fixed params listed under Passing explicit attributes when they appear in the URL’s search[...] query string.

The search assign is only defined when the request includes those query params. On pages that can load with or without a search query, wrap reads in {% if search %}. See also Product search — Accessing query params.

Tag-based filtering values from the URL are not separate assigns: read them on the same object with the category name in brackets, for example {{ search["Difficulty"] }} or {{ search["Amenities"] }} (match the company’s category name exactly).

{% if search %}
  {{ search.departure_date }}
  {{ search["departure_date"] }}
  {{ search["Amenities"] }}
{% endif %}

On this page