The search results from Loop54 are returned in two lists; DirectResults and RecommendedResults. Products in DirectResults contain the actual query in the metadata while RecommendedResults is what we consider to be contextually similar to the query.
The different results are to be presented in two different blocks on the site. We have chosen to place the recommended results to the right because it works great when showing our features in the demo but on a live site we suggest you put them under the direct results. On the response object you'll find DirectResults_TotalItems which states how many direct hits you have, it is good practice to present it to the user as shown below.
If the search query is wide (many hits in different contexts) we might not return any recommended results.
Whenever a user searches for a query that does not match any product in your catalogue we'll do a "fuzzy" search and try to guess what the user is after. These "fuzzy" results will be delivered in the DirectResults collection.
//if the result does not make sense, show error message
//(note that there may still be results!)
if (!$response->getValue("MakesSense"))
echo "We did not understand your query.";
//render spelling suggestions
if($response->hasData("SpellingSuggestions"))
{
$suggestions = $response->getCollection("SpellingSuggestions");
if(count($suggestions)>0)
echo "Did you mean: ";
foreach($suggestions as $suggestionItem)
{
echo $suggestionItem->key . " ";
}
}
Display 20-30 direct hits on the landing page, with the option to continue to page 2, 3 etc.
Make sure the user does not have to scroll to reach the actual product results. At least 1, but preferably 2, rows of results should be visible above the fold after a search.
Keep the search query in the search field, even after the user has performed the search. This serves as a form of breadcrumb and makes it far easier for the user to refine their query.
//initialize "Search" request
$request = new Loop54_Request("Search");
//set search query
$request->setValue("QueryString",$_GET{"query"});
//specify number of response items
$request->setValue("DirectResults_FromIndex",0);
$request->setValue("DirectResults_ToIndex",9);
$request->setValue("RecommendedResults_FromIndex",0);
$request->setValue("RecommendedResults_ToIndex",9);
//fetch response from engine
$response = Loop54_RequestHandling::getResponse("http://helloworld.54proxy.com", $request);
//successful response
if ($response->success)
{
//if the result does not make sense, show error message
//(note that there may still be results!)
if (!$response->getValue("MakesSense"))
echo "We did not understand your query.";
//render spelling suggestions
if($response->hasData("SpellingSuggestions"))
{
$suggestions = $response->getCollection("SpellingSuggestions");
if(count($suggestions)>0)
echo "Did you mean: ";
foreach($suggestions as $suggestionItem)
{
echo $suggestionItem->key . " ";
}
}
//render direct results
if($response->hasData("DirectResults"))
{
$results = $response->getCollection("DirectResults");
if(count($results)==0)
echo "There were no items matching your search.";
foreach($results as $resultItem)
{
$productId = $resultItem->key->externalId;
$productTitle = $resultItem->key->getStringAttribute("Title");
echo $productId . " " . $productTitle; //render a product on the search results page
}
}
//render recommended results
if($response->hasData("RecommendedResults"))
{
$results = $response->getCollection("RecommendedResults");
if(count($results)>0)
echo "Maybe you also want these?";
foreach($results as $resultItem)
{
$productId = $resultItem->key->externalId;
$productTitle = $resultItem->key->getStringAttribute("Title");
echo $productId . " " . $productTitle; //render a product on the search results page
}
}
}
else
{
echo $response->requestId; //log this
}
//if the result does not make sense, show error message
POST to http://helloworld.54proxy.com/search
{
"UserId" : "helloworlduser",
"IP" : "127.0.0.1",
"QueryString" : "bananasss",
"DirectResults_FromIndex" : 0,
"DirectResults_ToIndex" : 9
}
Response: 200 OK
{
"Success" : true,
"HeroId" : "The Queen of the Brown Mills",
"Data" : {
"MakesSense": false,
"DirectResults_TotalItems": 1,
"SpellingSuggestions": [
{
"Key": "banana",
"Value": 1694
}
]
}
}
Display 20-30 direct hits on the landing page, with the option to continue to page 2, 3 etc.
Make sure the user does not have to scroll to reach the actual product results. At least 1, but preferably 2, rows of results should be visible above the fold after a search.
Keep the search query in the search field, even after the user has performed the search. This serves as a form of breadcrumb and makes it far easier for the user to refine their query.
POST to http://helloworld.54proxy.com/search
{
"UserId" : "helloworlduser",
"IP" : "127.0.0.1",
"QueryString" : "banana",
"DirectResults_FromIndex" : 0,
"DirectResults_ToIndex" : 9,
"RecommendedResults_FromIndex" : 0,
"RecommendedResults_ToIndex" : 9
}
Response: 200 OK
{
"Success" : true,
"HeroId" : "The Queen of the Brown Mills",
"Data" : {
"MakesSense" : true,
"DirectResults_TotalItems" : 2,
"RecommendedResults_TotalItems" : 1,
"RelatedQueries" : [],
"DirectResults" : [{
"Key" : {
"ExternalId" : "1",
"EntityType" : "Product",
"Attributes" : {
"Manufacturer" : [
"The banana company"
],
"Category" : [
"Fruit"
],
"Title" : [
"Banana"
]
}
},
"Value" : 467.5
}, {
"Key" : {
"ExternalId" : "7",
"EntityType" : "Product",
"Attributes" : {
"Manufacturer" : [
"The banana company"
],
"Category" : [
"Fruits"
],
"Title" : [
"Organic Apple"
]
}
},
"Value" : 100
}
],
"RecommendedResults" : [{
"Key" : {
"ExternalId" : "3",
"EntityType" : "Product",
"Attributes" : {
"Manufacturer" : [
"Fruits n Veggies"
],
"Category" : [
"Fruits"
],
"Title" : [
"Apple"
]
}
},
"Value" : 0.171984790212361
}
]
}
}
The API V2X-based Java Connector is no longer supported.
You can view code examples for the V3-based Connector at
https://github.com/LoopFiftyFour/Java-Connector
Display 20-30 direct hits on the landing page, with the option to continue to page 2, 3 etc.
Make sure the user does not have to scroll to reach the actual product results. At least 1, but preferably 2, rows of results should be visible above the fold after a search.
Keep the search query in the search field, even after the user has performed the search. This serves as a form of breadcrumb and makes it far easier for the user to refine their query.
The API V2X-based Java Connector is no longer supported.
You can view code examples for the V3-based Connector at
https://github.com/LoopFiftyFour/Java-Connector
The API V2X-based .NET Connector is no longer supported.
You can view code examples for the V3-based Connector at
https://github.com/LoopFiftyFour/.NET-Connector
Display 20-30 direct hits on the landing page, with the option to continue to page 2, 3 etc.
Make sure the user does not have to scroll to reach the actual product results. At least 1, but preferably 2, rows of results should be visible above the fold after a search.
Keep the search query in the search field, even after the user has performed the search. This serves as a form of breadcrumb and makes it far easier for the user to refine their query.
The API V2X-based .NET Connector is no longer supported.
You can view code examples for the V3-based Connector at
https://github.com/LoopFiftyFour/.NET-Connector
Product overview
Technology