Implement a result list
Implement a result list
A search interface almost always displays a list of results which the user can use to interact with query result items. This article provides guidelines for implementing a result list on your own, assuming that you can’t use the Coveo Atomic or Headless libraries in your custom search integration with the Coveo Platform.
|
|
Note
As a reference, you may want to look at the source code of the |
Standard result list actions
The following table lists some actions that you may want to make available in a result list implementation.
Each entry indicates the specific Coveo Analytics event category, actionCause or eventValue, eventType, and customData that must be logged when the action is performed, as well as a link to the corresponding implementation guidelines.
| Result list action | events | actionCause |
eventType |
eventValue |
customData |
Implementation guidelines |
|---|---|---|---|---|---|---|
Click a result |
Click |
|
N/A |
N/A |
|
|
Click a recommendation |
Click |
|
N/A |
N/A |
|
|
Preview a result |
Click |
|
N/A |
N/A |
|
|
Select a page of results |
Custom |
N/A |
|
|
|
|
Select the next page of results |
Custom |
N/A |
|
|
|
|
Select the previous page of results |
Custom |
N/A |
|
|
|
|
Scroll to get more results in infinite scroll mode |
Custom |
N/A |
|
|
|
|
Resize the number of results per page |
Custom |
N/A |
|
|
|
|
Sort results |
Search |
|
N/A |
N/A |
|
|
Change the result layout |
Custom |
N/A |
|
|
|
|
Export to Excel |
Custom |
N/A |
|
|
N/A |
|
Search |
|
N/A |
N/A |
|
|
|
Note
It’s important to use the proper
|
Render query results
You typically want to update the result list whenever a search request to the Search API returns.
The results array of a query response contains the list of query result items which you typically rely on to render or update the result list.
By default, the results array is sorted by relevance (that is, by descending index ranking score value), but you can modify this behavior using the sortCriteria search request parameter.
|
|
Note
In a search interface with many similar results, you may want use the Duplicate filtering and result folding are mutually exclusive. |
-
Descriptions:
-
title: The title of the item. Use this to render the item in the result list. This property should be saved, as its value will be required when logging a UA click event for the item. -
excerpt: Text segments from the item, generated using query keywords. You can set the maximum length (in number of characters,200by default) using theexcerptLengthparameter in the search request. -
firstSentences: The first sentences of the item. This property won’t be populated unless theretrieveFirstSentencesparameter is set totruein the search request. You can set the maximum length (in number of characters,200by default) using theexcerptLengthparameter in the search request. -
summary: A description of the item, generated independently of query keywords. You can set the maximum length (in number of characters,0by default) using thesummaryLengthparameter in the search request. -
printableUri: A human-readable version of the item URI to be displayed.
-
-
Highlights:
All of the preceding properties have a
<propertyName>Highlightscounterpart which contains an array of{length, offset}elements. Each of these elements indicates a keyword to highlight (for example, using bold or italic text) when rendering the corresponding value.-
titleHighlights -
excerptHighlights -
firstSentencesHighlights -
summaryHighlights -
printableUriHighlights
-
-
Link:
-
The
rawproperty of a query result item contains key-value pairs, each corresponding to the name of a field along with its value for that specific item. The following fields are particularly important, and they should be included ascustomData(if available) when logging UA click events for that item:Notes-
By default, values in multi-value fields are separated by semicolon characters. For example, an item that corresponds to the coauthored book The Talisman may have the following key-value pair:
"authors":"Stephen King;Peter Straub". -
When performing queries, you can take advantage of the
fieldsToIncludeorfieldsToExcludesearch request parameters to only request the fields which are required by your search interface. By default, all fields are requested, which is typically non-optimal.
-
-
Miscellaneous:
-
uri: The URI of the item. Although you won’t typically use this to render the item in the result list, this property should be saved, as its value will be required when logging a UA click event for the item. -
isRecommendation: Whether the query result item was recommended by a Coveo ML Automatic Relevance Tuning (ART) model. You may want to use this property to render Coveo ML recommendations in a distinctive fashion in the result list.
-
|
|
Leading practice
For legacy reasons, several of the preceding properties are duplicated in PascalCase.
For example, each item in the results array has both the |
Example of rendering query results
Executing a search query:
POST https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer **********-****-****-****-************
Payload (excerpt)
{
...
"excerptlength": 200,
"q": "karamazov",
"retrieveFirstSentences": true,
...
}
200 OK response body (excerpt)
{
...
"results": [
{
...
"clickUri": "https://example.com/books/the-brothers-karamazov",
"excerpt": "The Brothers Karamazov is a passionate philosophical novel set in 19th-century Russia ... one of the supreme achievements in world literature.",
"excerptHighlights": [
{
"length": 9,
"offset": 13
}
],
"firstSentences": "The Brothers Karamazov is a passionate philosophical novel set in 19th-century Russia, that enters deeply into the ethical debates of God, free will, and morality. It's a spiritual drama of moral ...",
"firstSentencesHighlights": [
{
"length": 9,
"offset": 13
}
],
"isRecommendation": true,
"printableUri": "https://example.com/books/the-brothers-karamazov",
"printableUriHighlights": [
{
"length": 9,
"offset": 39
}
],
"raw": {
...
"author": "Fyodor Dostoyevsky",
"permanentid": "648a63d6a19545297692b4ae41a7d5e947c711be5f3c23dff69af3106960",
...
},
"summary": null,
"summaryHighlights": [],
"title": "The Brothers Karamazov",
"titleHighlights": [
{
"length": 9,
"offset": 13
}
],
"uri": "https://example.com/books/the-brothers-karamazov",
...
},
...next results...
],
...
}
Open query results
When the user opens a query result in a result list, such as by clicking a link which targets the corresponding item:
-
Call the Usage Analytics Write API to log the corresponding click event. In the request body:
-
Set the
actionCauseproperty to:-
documentOpenif the result item was opened in a standard search interface. -
recommendationOpenif the result item was opened in a Content Recommendation (CR) search interface.
-
-
Include the following key-value pairs (if available) in the
customDataproperty:-
"author": <author> -
"documentTitle": <documentTitle> -
"documentUrl": <documentUrl> -
"contentIdKey": <contentIdKey> -
"contentIdValue": <contentIdValue>
where:
-
<author>(string) is theraw.authorvalue of the clicked query result item. This can be an empty string. -
<documentTitle>(string) is thetitlevalue of the clicked query result item. -
<documentUrl>(string) is theurivalue of the clicked query result item. -
<contentIdKey>(string) is the name of a field which uniquely and permanently identifies the clicked item.Leading practiceUse
"permanentid". -
<contentIdValue>(string) is the value of the field whose name was specified in<contentIdKey>.
-
-
Set other required or optional properties as needed, such as
language,originLevel1, ororiginLevel2.
-
-
When the Usage Analytics Write API returns, redirect the client as appropriate, using the
clickableUrivalue of the clicked query result item.
Examples of opening query results
-
Logging a
documentOpenclick event:POST https://myorganizationid9sd8df7s.analytics.org.coveo.com/rest/ua/v15/analytics/click?visitor=28s6g49d-f81s-1435-2r5x153dle72 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "anonymous": false, "actionCause": "documentOpen", "customData":{ "contentIdKey": "permanentid", "contentIdValue": "648a63d6a19545297692b4ae41a7d5e947c711be5f3c23dff69af3106960", "author": "Fyodor Dostoyevsky", "documentTitle": "The Brothers Karamazov", "documentURL": "https://example.com/books/the-brothers-karamazov" }, "documentPosition": 1, "documentTitle": "The Brothers Karamazov", "documentUrl": "https://example.com/books/the-brothers-karamazov", "language": "en", "originLevel1": "BookstoreSearch", "originLevel2": "All", "searchQueryUid": "7bfc652a-9dea-4811-b3f9-6d24345c37ce", "sourceName": "example.com", ... } -
Logging a
recommendationOpenclick event:POST https://myorganizationid9sd8df7s.analytics.org.coveo.com/rest/ua/v15/analytics/click?visitor=28s6g49d-f81s-1435-2r5x153dle72 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "anonymous": false, "actionCause": "recommendationOpen", "customData":{ "contentIdKey": "permanentid", "contentIdValue": "8asd8f7a9sfd8asfdasf78afsdh8h87h878g37g872gf8g83gf78g2f387g2", "author": "Ivan Turgenev", "documentTitle": "Fathers and Sons", "documentURL": "https://example.com/books/fathers-and-sons" }, "documentPosition": 2, "documentTitle": "Fathers and Sons", "documentUrl": "https://example.com/books/fathers-and-sons", "language": "en", "originLevel1": "BookstoreRecommendation", "originLevel2": "", "searchQueryUid": "b2d60d3f-b2cf-4018-bfd2-8094d24fa8e9", "sourceName": "example.com", ... }
Preview a result
|
|
Notes
|
-
Prepare a GET request to
https://<orgId>.org.coveo.com/rest/search/v2/html?uniqueId=<uniqueId>, where<orgId>is the unique identifier of your organization. In the query string, set<uniqueId>to theraw.uniqueIdvalue of the query result item to preview.Leading practiceAlthough only the
uniqueIdparameter is required when requesting an HTML document from the Search API, you should send all the parameters that were originally included in the search request that returned the item to preview. This allows the Search API to highlight relevant terms in the HTML response. -
Call the Search API to execute the query prepared in step 1. When the Search API returns:
-
Call the Usage Analytics Write API to log the corresponding click event. In the request body:
-
Set the
actionCauseproperty todocumentQuickview. -
Include the following key-value pairs (if available) in the
customDataproperty:-
"author": <author> -
"contentIdKey": <contentIdKey> -
"contentIdValue": <contentIdValue> -
"documentTitle": <documentTitle> -
"documentUrl": <documentUrl>
where:
-
<author>(string) is theraw.authorvalue of the clicked query result item. This can be an empty string. -
<contentIdKey>(string) is the name of a field which uniquely and permanently identifies the clicked item.Leading practiceUse
"permanentid". -
<contentIdValue>(string) is the value of the field whose name was specified in<contentIdKey>. -
<documentTitle>(string) is thetitlevalue of the clicked query result item. -
<documentUrl>(string) is theurivalue of the clicked query result item.
-
-
Set other required or optional properties as needed, such as
language,originLevel1, ororiginLevel2.
-
-
Render the HTML document.
-
Examples of previewing a result
-
Requesting a
Preview:GET https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2/html?uniqueId=The_Brothers_Karamazov_Unique_Id&locale=en-US&q=karamazov&searchHub=BookstoreSearch&tab=All HTTP/1.1 Authorization: Bearer **********-****-****-****-************200 OK response (excerpt)
<meta http-equiv='Content-Type' content='text/html; charset=CP1252'> <base target="_blank" href="https://example.com/books/the-brothers-karamazov"> <html lang="en"><head> ... <p>The Brothers <span id='CoveoHighlight:1.2.1' style='background-color:#B0FFFF'>Karamazov</span> is a passionate philosophical novel set in 19-th century Russia, that enters ... </p> ... </body></html> -
Logging a
documentQuickviewclick event:POST https://myorganizationid9sd8df7s.analytics.org.coveo.com/rest/ua/v15/analytics/click?visitor=28s6g49d-f81s-1435-2r5x153dle72 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "anonymous": false, "actionCause": "documentQuickview", "customData":{ "contentIdKey": "permanentid", "contentIdValue": "648a63d6a19545297692b4ae41a7d5e947c711be5f3c23dff69af3106960", "author": "Fyodor Dostoyevsky", "documentTitle": "The Brothers Karamazov", "documentURL": "https://example.com/books/the-brothers-karamazov" }, "documentPosition": 1, "documentTitle": "The Brothers Karamazov", "documentUrl": "https://example.com/books/the-brothers-karamazov", "language": "en", "originLevel1": "BookstoreSearch", "originLevel2": "All", "searchQueryUid": "7bfc652a-9dea-4811-b3f9-6d24345c37ce", "sourceName": "example.com", ... }
Page query results
|
|
Note
As a reference, you may want to look at the source code of the |
By default, the results array of a query response contains the first ten items that match the query, according to the specified sort criteria.
However, you may want to allow users to navigate to a specific page of query results or modify the default page size in your result list implementation.
Paging query results involves the following search request parameters:
-
firstResult(unsigned integer) -
numberOfResults(unsigned integer)
The Search API will return numberOfResults (for example, 50) items, starting from the 0-based index position of the specified firstResult (for example, 10).
When the user changes the page number of the result list, such as by clicking a different page number, an arrow, or a button to modify the number of results per page:
-
Prepare a new query. Ensure that the
firstResultand/ornumberOfResultssearch request parameters are set to the desired values. -
Call the Search API to execute the query prepared in step 1. When the Search API returns:
-
Call the Usage Analytics Write API to log the corresponding custom event. In the request body:
-
Set the
eventTypeproperty togetMoreResults. -
Set the
eventValueproperty to:-
pagerNumberif the user has selected a specific page. -
pagerNextif the user has selected the next page. -
pagerPreviousif the user has selected the previous page. -
pagerScrollingif the user has scrolled down to the bottom of the result list (for example, in infinite scroll mode) and an additional "page" of query results needs to be loaded. -
pagerResizeif the user has selected a different number of results to display per page.
-
-
Include one of the following key-value pairs in the
customDataproperty, depending on the specifiedeventValue:-
"pagerNumber": <pagerNumber>ifeventValueis set topagernext,pagerPrevious, orpagerNumber. -
"currentResultsPerPage": <currentResultsPerPage>ifeventValueis set topagerResize.
where:
-
<pagerNumber>(unsigned integer) is the new page number (for example,2). -
<currentResultsPerPage>(unsigned integer) is the new number of results per page (for example,50).
NoteNo
customDatais required ifeventValueis set topagerScrolling. -
-
Set other required or optional properties as needed, such as
language,originLevel1, ororiginLevel2.
-
-
Examples of paging query results
-
Executing a search query when the user, who is currently on page
1, which contains10results, selects page3:POST https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "firstResult": 20, "locale": "en-US", "searchHub": "BookstoreSearch", "tab": "All", ... }200 OK response body (excerpt)
{ ... "results": [ ...data to render the result list... ], "totalCount": 36, ... } -
Logging a
pagerNumbercustom event for the previous action:POST https://myorganizationid9sd8df7s.analytics.org.coveo.com/rest/ua/v15/analytics/custom?visitor=28s6g49d-f81s-1435-2r5x153dle72 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "anonymous": false, "customData": { "pagerNumber": "3" }, "eventType": "getMoreResults", "eventValue": "pagerNumber", "language": "en", "originLevel1": "BookstoreSearch", "originLevel2": "All", ... }
Sort query results
|
|
Note
As a reference, you may want to look at the source code of the |
The Search API sortCriteria query parameter specifies how results are sorted.
This parameter has five possible values which you may want to offer as options to your users:
-
relevancy: Use index ranking factors or weights as well as specified query ranking expressions (QREs) and query ranking functions (QRFs) to compute a rankingscorefor each item, and sort the results in descending order. -
date ascending/date descending: Use the@datefield to sort the results in the specified order. This field typically contains the last modification date of each item in the index. -
qre: Use only QREs and QRFs to compute a rankingscorefor each item, and sort the results in descending order. This is similar torelevancy, except that index ranking factors and weights aren’t computed. -
nosort: Don’t sort the results. The index will return the results in an indeterminate order. -
@<field> ascending/@<field> descending: Use the value of a custom, sortable field to sort the results in the specified order.<field>represents a result item field name.Notes-
When
@<field> ascending/@<field> descendingis used, the<field>it’s based on must have itssortoption set totrue. -
It’s possible to combine zero or one date criterion with one or more field sort criteria by separating them with commas (for example,
date ascending,@views descending,@likes descending).
-
By default, sortCriteria is set to relevancy, meaning that query result items are sorted by their ranking score values, which are computed by the index.
These score values are based on several ranking factors and weights, such as the proximity of query terms to one another or the term frequency-inverse document frequency.
They can also be influenced by other means such as QREs and QRFs, Coveo ML ART and CR models, and certain types of query pipeline statements.
When the user chooses a different sortCriteria or sort order for the query results, such as by selecting a value in a Sort By widget:
-
Prepare a new query. Ensure that the
sortCriteriasearch request parameter is set to the desired value. -
Call the Search API to execute the query prepared in step 1. When the Search API returns:
-
Call the Usage Analytics Write API to log the corresponding search event. In the request body:
-
Set the
actionCauseproperty toresultsSort. -
Include the following key-value pair in the
customDataproperty:-
"resultsSortBy": <resultsSortBy>
where:
-
<resultsSortBy>(string) is the newsortCriteriaor sort order, in lowercase and without spaces. For example,dateascending,@sizeascendinginstead ofdate ascending,@size ascending.
-
-
Set other required or optional properties as needed, such as
language,originLevel1, ororiginLevel2.
-
-
Example of sorting query results
-
Executing a search query when the user selects
Date Descending:POST https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "locale": "en-US", "q": "tolstoy", "searchHub": "BookstoreSearch", "sortCriteria": "Date Descending", "tab": "All", ... }200 OK response body (excerpt)
{ ... "duration": 105, "searchUid": "7bfc652a-9dea-4811-b3f9-6d24345c37ce", "results": [ { ... "title":"The 19th Century", "raw": { ... "date":1375187019000, ... }, ... }, { ... "title":"War and Peace", "raw": { ... "date":1375189132000, ... }, ... }, { ... "title":"Russian literature for Dummies", "raw": { ... "date":1384880103000, ... }, ... }, ... ], "totalCount": 403, ... } -
Logging a
resultsSortsearch event for the previous action:POST https://myorganizationid9sd8df7s.analytics.org.coveo.com/rest/ua/v15/analytics/search HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "actionCause": "resultsSort", "anonymous": false, "customData": { "resultsSortBy": "dateascending" }, "language": "en", "originLevel1": "BookstoreSearch", "originLevel2": "All", "queryText": "tolstoy", "responseTime": 105, "searchQueryUid": "7bfc652a-9dea-4811-b3f9-6d24345c37ce", ... }
Switch result list layouts
|
|
Note
As a reference, you may want to look at the source code of the |
When the user chooses a different result list layout, such as by making a selection in a Layout widget:
-
Call the Usage Analytics Write API to log the corresponding custom event. In the request body:
-
Set the
eventTypeproperty toresultsLayout. -
Set the
eventValueproperty tochangeResultsLayout. -
Include the following key-value pair in the
customDataproperty:-
"resultsLayoutChangeTo": <resultsLayoutChangeTo>
where:
-
<resultsLayoutChangeTo>(string) is the identifier of the newly selected result list layout. The Coveo JavaScript Search Framework uses thelist,card, andtablevalues.
-
-
-
Render the result list with the new layout.
|
|
Note
In the Coveo JavaScript Search Framework, query results are rendered using a different set of result templates for each result list layout (list, card, and table). |
Example of switching result list layouts
Logging a changeResultsLayout custom event when the user selects the list display:
POST https://myorganizationid9sd8df7s.analytics.org.coveo.com/rest/ua/v15/analytics/custom?visitor=28s6g49d-f81s-1435-2r5x153dle72 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer **********-****-****-****-************
Payload (excerpt)
{
...
"anonymous": false,
"customData": {
"resultsLayoutChangeTo": "list"
},
"eventType": "resultsLayout",
"eventValue": "changeResultsLayout",
"language": "en",
"originLevel1": "BookstoreSearch",
"originLevel2": "All",
...
}
Handle folded results
|
|
Note
As a reference, you may want to look at the source code of the |
A search interface sometimes supports the folding of related query result items. There are two possible folding actions, the first of which groups items together. The second action, which builds upon the first, orders the grouped items in logical parent-child relationships.
Implementing the first action requires setting the filterField Search API parameter to @<filterField>, where <filterField> is the name of the field to use for grouping.
Upon receiving this request, the Search API sends back a list of result items, where each item contains a childResults array of results which have the same <filterField> value.
The childResults arrays are sorted using the sortCriteria, and their maximum length is filterFieldRange (the default value is 5).
To implement the second action, provide additional parentField and childField parameters in your Search API request, where the parentField value must uniquely identify each item and the childField value is the value of the parent parentField.
When the Search API sends back a list of result items, the items in the childResults arrays will also have a parentResult field, which can be used to resolve parent-child relationships within each folded query result.
|
|
Notes
|
When a new query is made in a search interface that supports folding:
-
Prepare a new query. Ensure that
filterField, and potentiallyparentField,childField, andfilterFieldRange, are set to the desired values. -
Call the Search API to execute the query prepared in step 1. When the Search API returns:
-
Call the Usage Analytics Write API to log the corresponding search event.
-
Render the folded result list. In addition to the standard properties to use when rendering query result items, the search interface needs to use the
childResultsfield to display items which belong to the same group and, if necessary, theparentResultfield to resolve parent-child relationships.
-
Examples of handling folded results
-
A bookstore search interface implements the first folding action to group books by series. indexed items contain a
bookseriesidfield that identifies the series to which each item belongs.When the user queries
"solzhenitsyn", the search interface sends the following request to the Search API:POST https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "locale": "en-US", "q": "solzhenitsyn", "filterField":"@bookseriesid", "searchHub": "BookstoreSearch", "tab": "All", ... }200 OK response body (excerpt)
{ ... "results": [ { ... "title": "The Gulag Archipelago, Vol. 2", "raw": { ... "bookseriesid":"GulagArchipelagoHarperClassics", ... }, ... "childResults": [ { "title": "The Gulag Archipelago, Vol. 1", "raw": { ... "bookseriesid":"GulagArchipelagoHarperClassics", ... }, ... }, { "title": "The Gulag Archipelago, Vol. 3", "raw": { ... "bookseriesid":"GulagArchipelagoHarperClassics", ... }, ... }, ], ... }, { ... "title": "One Day in the Life of Ivan Denisovich", "raw": { ... "bookseriesid":"OneDayLifeIvanDenisovichSignetClassics", ... }, ... "childResults": [], ... }, ... ], ... } -
A bookstore search interface implements both folding actions to group books by series as well as order them in logical parent-child relationships. indexed items contain a
bookseriesidfield that identifies the series to which each item belongs. They also contain abookidfield that uniquely identifies each book within its series, if applicable, and aparentbookidthat indicates thebookidof the parent book, if applicable.When the user queries
"solzhenitsyn", the search interface sends the following request to the Search API:POST https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "locale": "en-US", "q": "solzhenitsyn", "filterField":"@bookseriesid", "parentField":"@bookid", "childField":"@parentbookid", "searchHub": "BookstoreSearch", "sortCriteria": "Date Descending", "tab": "All", ... }200 OK response body (excerpt)
{ ... "results": [ { ... "title": "The Gulag Archipelago, Vol. 2", "raw": { ... "bookseriesid":"GulagArchipelagoHarperClassics", "bookid":"GulagArchipelagoHarperClassics2", "parentbookid":"GulagArchipelagoHarperClassics1", ... }, ... "childResults": [ { "title": "The Gulag Archipelago, Vol. 1", "raw": { ... "bookseriesid":"GulagArchipelagoHarperClassics", "bookid":"GulagArchipelagoHarperClassics1", "parentbookid":"GulagArchipelagoHarperClassics1", ... }, ... }, { "title": "The Gulag Archipelago, Vol. 3", "raw": { ... "bookseriesid":"GulagArchipelagoHarperClassics", "bookid":"GulagArchipelagoHarperClassics3", "parentbookid":"GulagArchipelagoHarperClassics1", ... }, ... }, ], ... }, { ... "title": "One Day in the Life of Ivan Denisovich", "raw": { ... "bookseriesid":"OneDayLifeIvanDenisovichSignetClassics", ... }, ... "childResults": [], ... }, ... ], ... }As you can see in the preceding query response, the Search API returns a list of items grouped by
bookseriesid. The results are sorted by relevance (this applies to both theresultsandchildResultsarrays), and thebookidandparentbookidfields are required to resolve the logical ordering. Also, when a book series only contains one item, itschildResultsarray is empty and itsparentFieldandchildFieldfields don’t need to be populated.
Export results
|
|
Note
As a reference, you may want to look at the source code of the |
A search interface sometimes offers the possibility to export the result list in Excel or OpenSearch format.
When the user chooses to export the result list, such as by clicking Export to Excel:
-
Prepare a new query. Ensure that the
formatproperty is set to:-
opensearch-atomoropensearch-rssif the user selected an OpenSearch format. -
xlsxif the user selected the Excel format.
-
-
Call the Search API to execute the query prepared in step 1. When the Search API returns:
-
If
formatis set toxlsx, call the Usage Analytics Write API to log the corresponding custom event. In the request body:-
Set the
eventTypeproperty tomisc. -
Set the
eventValueproperty toexportToExcel.
NoteThe Coveo JavaScript Search Framework doesn’t currently support exporting in XML format. As a result, if the user chooses to export to XML, there are currently no precise guidelines to follow when logging the corresponding event.
-
-
Generate a download link for the user.
-
Examples of exporting results
-
Executing a search query when the user clicks Export to Excel:
POST https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2 HTTP/1.1 Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "format": "xlsx", ... } -
Logging an
exportToExcelcustom event for the previous action:POST https://myorganizationid9sd8df7s.analytics.org.coveo.com/rest/ua/v15/analytics/custom?visitor=28s6g49d-f81s-1435-2r5x153dle72 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "anonymous": false, "eventType": "misc", "eventValue": "exportToExcel", "language": "en", "originLevel1": "BookstoreSearch", "originLevel2": "All", ... }
Toggle a facet value from a result list item
In some result lists, query result items contain clickable fields which the user can toggle to filter the entire result list (that is, to select or deselect a facet value).
-
Prepare a new query. This is the same as the query that’s sent when selecting or deselecting the associated facet value (see Toggle facet values).
-
Call the Search API to execute the query prepared in step 1. When the Search API returns:
-
Call the Usage Analytics Write API to log the corresponding search event. In the request body:
-
Set the
actionCauseproperty todocumentField. -
Include the following key-value pairs in the
customDataproperty:-
"facetField": <facetField> -
"facetId": <facetId> -
"facetValue": <facetValue>
where:
-
<facetField>(string) is the@-prefixed name of the field on which the toggled facet is based (for example,@tags). -
<facetId>(string) is the unique identifier of the toggled facet. Typically, this is the name of the field that this facet is based on (for example,@tags). -
<facetValue>(string) is the value of the field selected by the user (for example,salesforce).
-
-
Set other required or optional properties as needed, such as
language,originLevel1, ororiginLevel2.
-
-
Update the facet instance.
-
Examples of toggling a facet value from a result list item
-
Executing a search query when the user selects the
salesforceitem field:POST https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "aq": "(@tags==("salesforce"))", "locale": "en-US", "q": "coveo", "searchHub": "ExternalSearch", "tab": "All", ... }200 OK response body (excerpt)
{ ... "duration": 247, "searchUid": "de6cb58a-2abb-4718-a874-cc2162691cd9", "results": [ ...data to render the result list... ], "totalCount": 272, ... } -
Logging a
documentFieldsearch event for the previous action:POST https://myorganizationid9sd8df7s.analytics.org.coveo.com/rest/ua/v15/analytics/search HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer **********-****-****-****-************Payload (excerpt)
{ ... "actionCause": "documentField", "anonymous": false, "customData": { "facetField": "@tags", "facetId": "@tags", "facetValue": "salesforce" }, "language": "en", "originLevel1": "ExternalSearch", "originLevel2": "All", "queryText": "coveo", "responseTime": 247, "searchQueryUid": "de6cb58a-2abb-4718-a874-cc2162691cd9", ... }