Skip to main content

MyContent Search Introduction

CleverReach offers you a pretty easy way to integrate your very own content by using the wizard. To do so, you have to set up a simple dynamic script (php, asp, jsp, perl, ...) which has to return JSON formated data based on two steps.

Setup custom filter values like f.e. product name and category Return searchresults and some settings.

Take a look at this basic PHP example should get you started:

<?php

//if($_POST["password"]!="mysecretpassword") die();

switch ($_POST["get"]) {
case "filter":
$filters = array();

$filter = new stdClass();
$filter->name = "Category"; # short description
$filter->description = "Basic dropdown example. Doesnt actualy filter anything.";
$filter->required = false;
$filter->query_key = "category"; # query key which will be used in form GET to query this filter
$filter->type = "dropdown"; # dropdown, input;
$filter->values = array(
array("text" => "", "value" => ""),
array("text" => "cat 1", "value" => 1),
array("text" => "cat 2", "value" => 2),
array("text" => "cat 3", "value" => 3),
array("text" => "&nbsp;&nbsp;&nbsp;subcat 1", "value" => 4),
);
$filters[] = $filter;

$filter = new stdClass();
$filter->name = "Product";
$filter->description = "Basic example. Doesnt actualy filter anything either.";
$filter->required = false;
$filter->query_key = "product";
$filter->type = "input";
$filters[] = $filter;

echo json_encode($filters);
exit;
break;

case 'search':
$items = new stdClass();
$items->settings = new stdClass();
$items->settings->type = "product"; // product | rss | content > description
$items->settings->link_editable = false;
$items->settings->link_text_editable = false;
$items->settings->image_size_editable = false;

$out = new stdClass();
$out->title = "Batman";
$out->description = "Batman and Robin battle the combined forces of four supercriminals who have stolen an invention and intend to use it maliciously.";
//$out->content = "<b>preformated text</b>";
$out->image = "http://ecx.images-amazon.com/images/I/51P7GPFd8NL._SX500_.jpg";
$out->price = "$8.49";
$out->display_info = "additional info text";
$out->url = "http://www.amazon.com/Batman/dp/B000N54NGO/ref=sr_1_15?ie=UTF8&qid=1335258671&sr=8-15";
$items->items[] = $out;

$out = new stdClass();
$out->title = "DC Direct Batman: Arkham City: Series 1: Batman Action Figure";
$out->description = 'Welcome to Arkham City, the new maximum security “home” for all of Gotham City’s thugs, gangsters, and insane criminal masterminds. Set inside the heavily fortified walls of a sprawling district in the heart of Gotham City, it’s filled with the most murderous villains from DC Comics’ Batman universe. But Batman is ready to tackle it with all-new gadgets and his greatest—and most dangerous—allies. Which is good, because he’ll need all the help he can get for his journey into the darkest corners of Gotham. Among those he’ll encounter: Tim Drake battles crime as Robin, delivering punches (and signature quips) to aid in the Caped Crusader’s mission to shut down Arkham City. In a nice new outfit, Harley Quinn has taken to the front lines to personally fulfill the Joker’s sickest wishes of mischief and mayhem. She’s not going to let anyone get in her way—least of all Batman. Based on the upcoming blockbuster video game published by Warner Bros. Interactive Entertainment, developed by Rocksteady Studios, and licensed by DC Entertainment';
$out->image = "http://ecx.images-amazon.com/images/I/41fR%2Bl-cb5L._SL500_AA300_.jpg";
$out->price = "$18.95";
$out->url = "http://www.amazon.com/DC-Direct-Batman-Arkham-Series/dp/B005UH6HOG";
$items->items[] = $out;
echo json_encode($items);
//exit;

break;
}

1. Initial setup

CleverReach will do a "POST" (no GET) (?get=filter[&password=password]) on the stored Product Search URL. This "HAS TO" return JSON encoded filters so CleverReach can setup a Form based on the following filters for user to search for data. CleverReach will create input fields based on the filters returned by you. The user then fill out the generated form and these values will be posted back to you script in order to filter the searchresults.

The following example will create a dropdown list names "Category" and a Input field named "Product".

Example of a response:

[
{
"name": "Category", //Displayed name of the to be searched for value
"description": "Place description here or leave emtpy", //[optional] detailed description of the field
"required": false, //is required (true|false)
"query_key": "category", //submited (POST) name of the field. DON'T use "get" and "password" here
"type": "dropdown", //input type (input | dropdown)
//if dropdown, set options here
"values": [
{ "text": "", "value": "" }, //text > displayed text, value > submited balue
{ "text": "cat 1", "value": 1 }, //...
{ "text": "cat 2", "value": 2 },
{ "text": "cat 3", "value": 3 },
{ "text": "&nbsp;&nbsp;&nbsp;subcat 1", "value": 4 }
]
},
// ... (add as many filters as you want)
{
"name": "Product",
"description": "Place description here or leave emtpy",
"required": false,
"query_key": "product",
"type": "input"
}
]

2. Search results

Once the user hits the search button, a POST is initiated. CleverReach will do a "POST" (no GET) (?get=search[&password=password]) on the stored Product Search URL. The response hast to include Settings and Items based on the following format.

The JSON Encoded response consists out of 2 Parts. The "settings", containing the result type and misc options and the "items", which contain the actual searchresults themselves.

Example of a response:

{
// define returned data types and misc options
"settings": {
"type": "product", // determines which type of layout users can
// choose after item is selected
// available types are: (rss | product | content)
// "rss" > TEXT layouts only
// "product" > PRODUCT layouts only
// "content" > Ignores layouts and uses item conten/description as content
// the following options will be displayed after the user has chosen a layout
"link_editable": false, // lets user change link (true|false)
"link_text_editable": false, // lets user edit link text (true|false)
"image_size_editable": false // lets user change image sizes (true|false)
},
// array of actual search results
"items": [
{
"title": "Test Product 1", // Title
"description": "Description text", // If RSS or PRODUCT > description text.
"content": "<b>custom HTML content</b>", // [optional] If type is "content", this becomes the HTML content
// if its not set, description will be used
"image": "http://server.com/image.jpg", // [optional] Image path
"url": "http://www.server.com", // [optional] Link
"price": "EUR 12,99", // [optional] (only for product types) Preformated Price
"display_info": "additional info text" // [optional] adds an additional info line to the search results
},
// ...
{
"title": "Arkham City Batman Action Figure",
"description": "Welcome to Arkham City, the new maximum security \"home\" for all of Gotham City’s thugs, gangsters, ...",
"image": "http://ecx.images-amazon.com/images/I/41fR%2Bl-cb5L._SL500_AA300*.jpg",
"price": "$ 12,99",
"url": "http://www.amazon.com/DC-Direct-Batman-Arkham-Series/dp/B005UH6HOG"
}
]
}