Skip to main content

Creating a Pipes2 Search endpoint

A Pipes2 search endpoint should output a regular Pipes2 feed. The only difference is that the endpoint gets a query param (q) of the search term the end user is typing on her mobile/TV device.

Create an endpoint on your server that expects q as a query param. Bellow you can see an expressjs example but you can implement it on whatever server infrastructure you are using.

const express = require('express')
const app = express()
const port = 3000

app.get('/search', async (req, res) => {
const searchTerm = req.query.q;
// Create a fetchItemsBySearchTerm function that calls your API and fetches items according to the given search term.
const items = await fetchItemsBySearchTerm(searchTerm);
// Create a renderItemsAsFeed function that renders items to the Pipes2 schema (https://docs.applicaster.com/integrations/feed-json-protocol)
const feed = renderItemsAsFeed(items);
res.json(feed);
})

To integrate the endpoint you just created just add it as feed inside Zapp according to the instructions written here.

For the example above your feed URL will be https://example.com/search?q={{q}} The device will dynamically replace {{q}} with the user's typed search term.

Search filters

Search Filters implementation requires adding support for filterTag query parameter to your search endpoint like it shown in the example below.

app.get('/search', async (req, res) => {
const searchTerm = req.query.q;
// Create a fetchItemsBySearchTerm function that calls your API and fetches items according to the given search term.
const items = await fetchItemsBySearchTerm(searchTerm);

// Create a filterItems function that filters search results based on the filterTag parameter value.
const filterTag = req.query.filterTag;
const filteredItems = filterItems(items, filterTag);

// Create a renderItemsAsFeed function that renders items to the Pipes2 schema (https://docs.applicaster.com/integrations/feed-json-protocol)
const feed = renderItemsAsFeed(filteredItems);
res.json(feed);
})

You should also create a feed that will provide data for the tabs displaying categorized search results. It can be an endpoint on your server or a static feed configured with Zapp's manual feed tool.

This data feed should have the structure similar to the screen picker datasource with entries including an extension for filter tag e.g extensions.filterTag.

{
"entry": [
{
"id": "2831b0f2-e15f-41ce-b15e-3fe35fda6f97",
"title": "title1",
"type": {
"value": "filter-search"
},
"extensions": {
"filterTag": "all"
},
},
{
"id": "a8af7cb5-244c-4241-bb1c-c1b124ef350a",
"title": "title2",
"type": {
"value": "filter-search"
},
"extensions": {
"filterTag": "news"
},
},
]
}

filterTag - a query parameter to filter the search results based on a certain tag e.g https://example.com/search?q={{q}}&filterTag={{filterTag}}