|
by Jason Levitt 2006-08-08 Searching with Browse Nodes Browse node searches are very powerful because they let you refine your search to a sspecific product category beneath a search index. For example, if you are only interested in books about the Holocaust, you would likely want to search in browse node ID 4994 (Books > Subjects > History > Jewish > Holocaust) in the Books search index. A common search strategy is to use the BrowseNode parameter to narrow searches down to a specific browse node, then add the Keywords and Title parameters to furtherfocus the search. The goal is to try to get Amazon ECS to return item listings that closely match what we’re looking for. To see what Amazon ECS returns for a search within browse node ID 4994, you can put this request in your web browser: http://webservices.amazon.com/onca/xml?Service=AWSECommerceService& AssociateTag=ws&SubscriptionId=1A7XKHR5BYD0WPJVQEG2&Operation=ItemSearch& BrowseNode=4994&SearchIndex=Books&Version=2006-06-28 This search will return books from the Holocaust browse node using the default sort order of bestselling and the default response groups of Small and Request. If you wanted to narrow down the search to books that mention Auschwitz in various product fields, such as the product title and description, you can add the Keywords parameter and set it to the word “Auschwitz”. You can look at the results of this request by putting this URL in your browser: http://webservices.amazon.com/onca/xml?Service=AWSECommerceService& AssociateTag=ws&SubscriptionId=1A7XKHR5BYD0WPJVQEG2& Operation=ItemSearch&BrowseNode=4994&SearchIndex=Books& Keywords=Auschwitz&Version=2006-06-28 This search will return only books from browse node 4994 that have the word Auschwitz in the product title or description. If there was a browse node for Holocaust books about Auschwitz, you could use that, but there isn’t one. Note: Such a book would likely be in the category: Books > Subjects > History > Jewish > Holocaust > Auschwitz Finding Usable Browse NodesThe question that may come to mind right now is: How do I find the Holocaust browse node ID? Amazon ECS has two helpful mechanisms for finding browse nodes: - The BrowseNodeLookup operation returns a list of child browse nodes for a given browse node ID.
- The BrowseNode response group can be used with the ItemSearch operation to return a list of browse nodes for each item in the response.
The BrowseNodeLookup operation is very useful for creating search trees that you can use to help users browse Amazon’s product categories, but it doesn’t directly help us find usable browse node IDs. Note: There's a list of popular browse nodes in the Developer Guide under Browse Node Values. The BrowseNode response group, however, will return a list of browse node IDs that match each item returned in ItemSearch and ItemLookup requests. So, to findusable browse nodes for a certain class of product, we can use the ItemLookup operation with the BrowseNodes response group and analyze the browse node IDs returned in the response. First, we go to Amazon.com and find some ASINs that are typical of the products we want. We can then write a simple PHP script that runs an item lookup on the items and lists the browse nodes they appear under. Taking the intersection of those browse nodes is a good basis for searching. In this example, we’re looking for sushi preparation knives. I found two of them on Amazon.com by searching for “sushi knives”. I can use their ASINs to find what browse nodes they’re listed under. Here's a program to list product browse nodes: <?php // Note: The tools.inc.php file is attached to this article require_once('tools.inc.php');
// List of ASINs (up to 10) to find browse nodes for $asins='B000288KD4,B0000CE0IA';
// Our Amazon request. Note use of BrowseNodes Response Group $request='http://webservices.amazon.com/onca/xml?' . 'Service=AWSECommerceService&AssociateTag=ws&SubscriptionId=1A7XKHR5BYD0WPJVQEG2&' . 'Operation=ItemLookup&MerchantId=All&ItemId=' .$asins. '&ResponseGroup=BrowseNodes&Version=2005-03-23';
// Fetch and process the request $xml = GetData($request, 10); $Result = xmlparser($xml);
// Go through each item listing foreach ($Result['ItemLookupResponse']['Items'][0]['Item'] as $item) {
// The ASINs should always be returned, but you check anyway $asin= (isset($item['ASIN'][0])) ? $item['ASIN'][0] : ' No ASIN!??'; echo '<br />ASIN = '.$asin.'<br />';
// Loop through the browsenodes of each item foreach ($item['BrowseNodes'][0]['BrowseNode'] as $bnode) {
// Check for browse node name $name=(isset($bnode['Name']))?$bnode['Name']:'No browse node name'; echo 'Browse Node = '.$bnode['BrowseNodeId'].'<br />'; echo 'Browse Name = '.$name .'<br />'; echo '<br />'; } } ?> The ItemLookup method can accept a comma-separated list of up to 10 ASINs. So, you could look at the browse nodes for up to ten products in a single request. The browse nodes associated with an item changes over time, so here's a sample of what you might see: ASIN = B000288KD4 Browse Node = 289852 Browse Name = Asian Knives
Browse Node = 289854 Browse Name = Boning & Fillet Knives
Browse Node = 1063512 Browse Name = Great Gadgets
Browse Node = 3000591 Browse Name = Under $25
Browse Node = 3375131 Browse Name = Travel
Browse Node = 3737371 Browse Name = All Knives
Browse Node = 13466181 Browse Name = Komachi
Browse Node = 13875901 Browse Name = All Specialty Knives
Browse Node = 13875931 Browse Name = Seafood Knives
ASIN = B0000CE0IA Browse Node = 289852 Browse Name = Asian Knives
Browse Node = 712216 Browse Name = Bunmei
Browse Node = 3737371 Browse Name = All Knives The first knife appears in nine browse nodes, while the second one appears in three browse nodes. The two browse nodes they share in common, 3737371 and 289852 are the likely the best ones to use for searching for sushi preparation knifes. The Asian Knives browse node seems like a more specific choice than the All Knives browse node, but only testing them in actual item searches will prove which one works better. If we added more ASINs to our example, manually determining the browse nodes they have in common would be tedious. Fortunately, we can change our PHP code around a bit to return only the browse nodes that both products appear under. Here's a program to find the intersection of product browse nodes among several products: <?php // Note: The tools.inc.php file is attached to this article require_once('tools.inc.php');
// List of ASINs (up to 10) to find browse nodes for $asins='B000288KD4,B0000CE0IA';
// Our Amazon request. Note use of BrowseNodes Response Group $request='http://webservices.amazon.com/onca/xml?' . 'Service=AWSECommerceService&AssociateTag=ws&SubscriptionId=1A7XKHR5BYD0WPJVQEG2&' . 'Operation=ItemLookup&MerchantId=All&ItemId='.$asins. '&ResponseGroup=BrowseNodes&Version=2006-06-28';
// Fetch and preocess the request $xml = GetData($request, 10); $Result = xmlparser($xml);
// Index to keep track of number of items $i=0;
// Array of browse nodes in each item $allnodes=array();
// Loop through items foreach ($Result['ItemLookupResponse']['Items'][0]['Item'] as $item) {
// Loop through browse nodes for each item foreach ($item['BrowseNodes'][0]['BrowseNode'] as $bnode) {
// Store browse nodes for each item in the allnodes array $allnodes[$i][]=trim($bnode['BrowseNodeId']); }
// Increment index for the next item $i++; }
// Find intersection of browse nodes for all items $i=0; $arr1=$allnodes[$i]; $arr2=$allnodes[$i+1];
// Use array_intersect on each set of browse nodes While (true) { $arr2=array_intersect($arr1, $arr2); $i++; if (!isset($allnodes[$i+1])) break; $arr1=$allnodes[$i+1]; } echo 'Intersection of browse nodes: '; print_r($arr2); ?> Running it yields: Intersection of browse nodes: Array ( [1] => 3737371 [5] => 14309821 ) We can test how well the browse nodes work using the ItemSearch operation. The ItemSearch operation only lets us search in one browse node at a time, but you can do a batch search to do two item searches at once. This batch request returns productsin the two browse nodes 289852 and 3737371. http://webservices.amazon.com/onca/xml?Service=AWSECommerceService& SubscriptionId=1A7XKHR5BYD0WPJVQEG2&AssociateTag=ws&Operation=ItemSearch& ItemSearch.1.BrowseNode=289852&ItemSearch.2.BrowseNode=3737371& ItemSearch.Shared.ResponseGroup=Medium&ItemSearch.Shared.SearchIndex=Kitchen& Version=2006-06-28 We can do four ItemSearch operations at once by combining two batch searches in a multi-operation request. This specifies two ItemSearch operations. The ItemSearch operations just return products from the four browse nodes: 289852, 3737371, 289854, and 289862. http://webservices.amazon.com/onca/xml?Service=AWSECommerceService& SubscriptionId=1A7XKHR5BYD0WPJVQEG2&AssociateTag=ws& Version=2006-06-28&Operation=ItemSearch,ItemSearch& ItemSearch.1.BrowseNode=289852&ItemSearch.2.BrowseNode=3737371& ItemSearch.3.BrowseNode=289854&ItemSearch.4.BrowseNode=289862& ItemSearch.Shared.ResponseGroup=Medium&ItemSearch.Shared.SearchIndex=Kitchen Since the “All Knives”, “Specialty Knives”, and “Boning and Filet Knives” categories are rather broad, we’ll narrow them down by adding a Keywords parameter to each of those categories. Here, I added the search keyword “sushi” to those requestparameters. http://webservices.amazon.com/onca/xml?Service=AWSECommerceService& SubscriptionId=1A7XKHR5BYD0WPJVQEG2&AssociateTag=ws& Operation=ItemSearch,ItemSearch&ItemSearch.1.BrowseNode=289852& ItemSearch.2.BrowseNode=3737371&ItemSearch.3.BrowseNode=289854& ItemSearch.4.BrowseNode=289862&ItemSearch.Shared.ResponseGroup=Medium& ItemSearch.Shared.SearchIndex=Kitchen&ItemSearch.2.Keywords=sushi& ItemSearch.3.Keywords=sushi&ItemSearch.4.Keywords=sushi&Version=2006-06-28 As a general rule of thumb, if the browse node is exactly the type of product you want, you can just use it as is, but if the browse nodes category is too broad or not specific, you can add the Keywords parameter to focus the search.
|