You can create aggregated record queries with URL query parameters or with Presentation API methods.
An aggregated record request is similar to an ordinary record request with these exceptions:
If you are using URL query parameters, the
A
parameter is specified (instead ofR
). The value of theA
parameter is the record specifier of the aggregated record.If you are using the API, use the
ENEQuery.setAggrERecSpec()
method (Java) or theENEQuery.AggrERecSpec
property (.NET) to specify the aggregated record to be queried for.The element returned is an aggregated record (not a record).
You can use the
As
parameter to specify a sort that determines the order
of the representative records.
You can specify one or more sort keys with the
As
parameter. A sort key is a dimension or property name
enabled for sorting on the data set. Optionally, each sort key can specify a
sort order of 0 (ascending sort, the default) or 1 (descending sort). The
As
parameter is especially useful if you want to use the
record boost and bury feature with aggregated records.
Similar to an ordinary record,
An
(instead of
N
) is the user’s navigation state. Only records that
satisfy this navigation state are included in the aggregated record. In
addition, the
Au
parameter must be used to specify the aggregated
record rollup key.
The following are two examples of queries using the
An
parameter:
An=0&A=32905&Au=Winery&As=Score A=7&An=123&Au=ssn
For the API, the examples below show how the
UrlGen
class constructs the URL query string. Note the
following in the examples:
The
ENEQuery.setAggrERecSpec()
method (Java) and theENEQuery.AggrERecSpec
property (.NET) provide the aggregated record specifier to theA
parameter.The
ENEQuery.getNavDescriptors()
method (Java) and theENEQuery.NavDescriptors
property (.NET) get the navigation values for theAn
parameter.The
ENEQuery.getNavRollupKey()
method (Java) and theENEQuery.NavRollupKey
property (.NET) get the name of the rollup key for theAu
parameter.
Example 16. Java example
// Create aggregated record request (start from empty request) UrlGen urlg = new UrlGen("", "UTF-8"); urlg.addParam("A",aggrec.getSpec()); urlg.addParam("An",usq.getNavDescriptors().toString()); urlg.addParam("Au",usq.getNavRollupKey()); urlg.addParam("eneHost",(String)request.getAttribute("eneHost")); urlg.addParam("enePort",(String)request.getAttribute("enePort")); urlg.addParam("displayKey",String)request.getParameter("displayKey")); urlg.addParam("sid",(String)request.getAttribute("sid")); String url = CONTROLLER+"?"+urlg; %><a href="<%= url %>">%>
Example 17. .NET example
// Create aggregated record request (start from empty request) urlg = new UrlGen("", "UTF-8"); urlg.AddParam("A", aggrec.Spec); urlg.AddParam("An",usq.NavDescriptors.ToString()); urlg.AddParam("Au",usq.NavRollupKey); urlg.AddParam("eneHost",(String)Request.QueryString["eneHost"]); urlg.AddParam("enePort",(String)Request.QueryString["enePort"]); urlg.AddParam("displayKey",(String)Request.QueryString["displayKey"]); urlg.RemoveParam("sid"); urlg.AddParam("sid",(String)Request.QueryString["sid"]); url = (String) Application["CONTROLLER"] + "?" + urlg.ToString(); %><a href="<%= url %>">%>
The ENEQueryResults
class has methods to retrieve aggregated record objects.
On an aggregated record request, the aggregated record is returned as an AggrERec
object in the ENEQueryResults
object. Use these calls:
The
ENEQueryResults.containsAggrERec()
method (Java) and theENEQueryResults.ContainsAggrERec()
method (.NET) returntrue
if theENEQueryResults
object contains an aggregated record.The
ENEQueryResults.getAggrERec()
method (Java) and theENEQueryResults.AggrERec
property (.NET) retrieve theAggrERec
object from theENEQueryResults
object.
Example 18. Java example
// Make MDEX Engine request ENEQueryResults qr = nec.query(usq); // Check for an AggrERec object in ENEQueryResults if (qr.containsAggrERec()) { AggrERec aggRec = (AggrERec)qr.getAggrERec(); ... }
Example 19. .NET example
// Make MDEX Engine request ENEQueryResults qr = nec.Query(usq); // Check for an AggrERec object in ENEQueryResults if (qr.ContainsAggrERec()) { AggrERec aggRec = (AggrERec)qr.AggrERec; ... }
The Navigation
class calls can retrieve aggregated records.
On an aggregated record navigation query, a list of aggregated records (an AggrERecList
object) is returned in the Navigation
object.
To retrieve a list of aggregated records returned by the navigation query, as an AggrERecList
object, use:
To get the number of aggregated records that matched the navigation query, use:
Note that by default, the MDEX Engine returns a maximum of 10 aggregated records. To change this number, use:
The AggrERec
class calls can retrieve attributes of aggregated records.
After you retrieve an aggregated record, you can use the following AggrERec
class calls:
The
getERecs()
method (Java) andERecs
property (.NET) gets the Oracle Commerce records (ERec
objects) that are in this aggregated record.The
getProperties()
method (Java) andProperties
property (.NET) return the properties (as aPropertyMap
object) of the aggregated record.The
getRepresentative()
method (Java) andRepresentative
property (.NET) get the Oracle Commerce record (ERec
object) that is the representative record of this aggregated record.The
getSpec()
method (Java) andSpec
property (.NET) get the specifier of the aggregated record to be queried for.The
getTotalNumERecs()
method (Java) andTotalNumERecs
property (.NET) return the number of Oracle Commerce records (ERec
objects) that are in this aggregated record.
The following code snippets illustrate these calls.
Example 20. Java example
Navigation nav = qr.getNavigation(); // Get total number of aggregated records that matched the query long nAggrRecs = nav.getTotalNumAggrERecs(); // Get the aggregated records from the Navigation object AggrERecList aggrecs = nav.getAggrERecs(); // Loop over the aggregated record list for (int i=0; i<aggrecs.size(); i++) { // Get individual aggregate record AggrERec aggrec = (AggrERec)aggrecs.get(i); // Get number of records in this aggregated record long recCount = aggrec.getTotalNumERecs(); // Get the aggregated record's attributes String aggrSpec = aggrec.getSpec(); PropertyMap propMap = aggrec.getProperties(); ERecList recs = aggrec.getERecs(); ERec repRec = aggrec.getRepresentative(); }
Example 21. .NET example
Navigation nav = qr.Navigation; // Get total number of aggregated records that matched the query long nAggrRecs = nav.TotalNumAggrERecs; // Get the aggregated records from the Navigation object AggrERecList aggrecs = nav.AggrERecs; // Loop over the aggregated record list for (int i=0; i<aggrecs.Count; i++) { // Get individual aggregate record AggrERec aggrec = (AggrERec)aggrecs[i]; // Get number of records in this aggregated record long recCount = aggrec.TotalNumERecs; // Get the aggregated record's attributes String aggrSpec = aggrec.Spec; PropertyMap propMap = aggrec.Properties; ERecList recs = aggRec.ERecs; ERec repRec = aggrec.Representative; }
The
dgraph.AggrBins
property contains aggregated record
statistics.
To enable dynamic statistics (aggregated record counts beneath a given
refinement), use the
--stat-abins
flag with the dgraph.
Statistics on aggregated records are returned as a property on each
dimension value. For aggregated records, this property is
DGraph.AggrBins
. In other words, to retrieve the
aggregated record counts beneath a given refinement, use the
DGraph.AggrBins
property.
The following code examples show how to retrieve the dynamic statistics for aggregated records.
Example 22. Java example
DimValList dvl = dimension.getRefinements(); for (int i=0; i < dvl.size(); i++) { DimVal ref = dvl.getDimValue(i); PropertyMap pmap = ref.getProperties(); // Get dynamic stats String dstats = ""; if (pmap.get("DGraph.AggrBins") != null) { dstats = " ("+pmap.get("DGraph.AggrBins")+")"; } }
Example 23. .NET example
DimValList dvl = dimension.Refinements; for (int i=0; i < dvl.Count; i++) { DimVal ref1 = (DimVal)dvl[i]; PropertyMap pmap = ref.Properties; // Get dynamic stats String dstats = ""; if (pmap["DGraph.AggrBins"] != null) { dstats = " ("+pmap["DGraph.AggrBins"]+")"; } }
A record in an aggregated record can be displayed like any other Oracle Commerce record.
You display the Oracle Commerce records (ERec
objects) in an aggregated record with the same procedures described in Chapter 5 ("Working with Oracle Commerce Records").
In the following examples, a list of aggregated records is retrieved from the Navigation
object and the properties of each representative record are displayed.
Example 24. Java example
Get aggregated record list from the Navigation object AggrERecList aggrecs = nav.getAggrERecs(); // Loop over aggregated record list for (int i=0; i<aggrecs.size(); i++) { // Get an individual aggregated record AggrERec aggrec = (AggrERec)aggrecs.get(i); // Get representative record of this aggregated record ERec repRec = aggrec.getRepresentative(); // Get property map for representative record PropertyMap repPropsMap = repRec.getProperties(); // Get property iterator to loop over the property map Iterator repProps = repPropsMap.entrySet().iterator(); // Display representative record properties while (repProps.hasNext()) { // Get a property Property prop = (Property)repProps.next(); // Display name and value of the property %> <tr> <td>Property name: <%= prop.getKey() %></td> <td>Property value: <%= prop.getValue() %> </tr> <% } }
Example 25. .NET example
/ Get aggregated record list from the Navigation object AggrERecList aggrecs = nav.AggrERecs; // Loop over aggregated record list for (int i=0; i<aggrecs.Count; i++) { // Get an individual aggregated record AggrERec aggrec = (AggrERec)aggrecs[i]; // Get representative record of this aggregated record ERec repRec = aggrec.Representative; // Get property map for representative record PropertyMap repPropsMap = repRec.Properties; // Get property list for representative record System.Collections.Ilist repPropsList = repPropsMap.EntrySet; // Display representative record properties foreach (Property repProp in repPropsList) { %> <tr> <td>Property name: <%= repProp.Key %></td> <td>Property value: <%= repProp.Value %> </tr> <% } }