CSSearchMultiple includes three properties you can use to create facets that will be returned with search results. The returned facet object includes a list of facet properties and a count of the results that match each one.
You can limit the number of facets returned using MaxFacets, and use any combination of facets together.
There's full API documentation for CSSearchMultiple in the API Reference (opens new window) section for your release of iCM.
Date Faceting
FacetDates returns an array of date properties in a DateFacets object. The various search collections index different dates you might like to facet on. The article and media collections index values for creationdate, displayenddate, displaystartdate and modificationdate. The user collection indexes values for creationdate and modificationdate. These names are case sensitive so must be used in lowercase.
FacetDates is used with FacetDateStart and FacetDateEnd to set the range between which facets will be created. FacetDateGap sets the interval of those facets (eg a facet for every day, month or year) using DateMathParser (opens new window) syntax.
Field Faceting
FacetFields lets you create facets based on any indexed field in the search collection. Facets are returned in a FieldFacets object. You can limit the facets returned to those that start with a particular string using FacetFieldPrefix.
There's a full list of all of the fields indexed by the search collections in the Search Indexing article for your release of iCM. Field names are case sensitive so must be used in lowercase.
Facet Queries
FacetQueries passes an array of facets directly to SOLR.
Example
This example uses all three facet properties. It queries the Article collection and returns article headings as a set of field facets, the last modified dates as monthly facets, and uses FacetQueries to facet the articles by ID (in a real world example you might use this to group by a value stored in the article extras - you could have articles describing locations with their address data in article extras for example).
client.invoke("icmapi", "CSSearchMultiple_get", {
"set": {
"CollectionNameList": "Article",
"LuceneRepositoryPath": "http://localhost:5506/solrsite",
"Keywords": searchTerm,
"FacetFields": ["OBJECT_RAWC__title"],
"FacetDates": ["modificationdate"],
"FacetDateStart": "2017-01-01T00:00:00Z",
"FacetDateEnd": "NOW/DAY",
"FacetDateGap": "+1MONTH",
"FacetQueries": ["keyid:[1 TO 10]", "keyid:[11 TO 20]", "keyid:[21 TO 30]", "keyid:[31 TO 40]"],
},
"get": "FieldFacets,DateFacets,QueryFacets"
});
And it returns something like:
"result": {
"data": {
"multipleItemData": [{
"_ItemClass": "CSSearchItem"
}, {
"_ItemClass": "CSSearchItem"
}, {
"_ItemClass": "CSSearchItem"
}, {
"_ItemClass": "CSSearchItem"
}, {
"_ItemClass": "CSSearchItem"
}, {
"_ItemClass": "CSSearchItem"
}, {
"_ItemClass": "CSSearchItem"
}],
"itemData": {
"_ItemClass": "CSSearchMultiple",
"FieldFacets": {
"OBJECT_RAWC__title": {
"latest news": 1,
"child default article": 1,
"html ajax template example": 1,
"api test": 1,
"date input": 1,
"testing": 4
}
},
"QueryFacets": {
"keyid:[1 TO 10]": 0,
"keyid:[11 TO 20]": 4,
"keyid:[21 TO 30]": 1,
"keyid:[31 TO 40]": 1
},
"DateFacets": {
"modificationdate": {
"2017-05-01T00:00:00Z": 1,
"2017-10-01T00:00:00Z": 1,
"2018-02-01T00:00:00Z": 4,
"2017-03-01T00:00:00Z": 2,
"2017-11-01T00:00:00Z": 11
}
}
}
},
"success": true
}
The response has been chopped about to take up less space on the page (if you are wondering why the numbers don't add up). As explained in the API documentation, if you want to return the data in each CSSearchItem you need to make a get request for "*".
Applying Facets
Now that you have some facets, your users will want to be able to apply them to the search results. Perform the search again and pass the selected facet as a Filter Query.
Expanding on the example above, if someone selected the 2017-03-01T00:00:00Z facet, the follow-up search, after manipulating the date into a range covering the whole month, would look something like:
client.invoke("icmapi", "CSSearchMultiple_get", {
"set": {
"CollectionNameList": "Article",
"LuceneRepositoryPath": "http://localhost:5506/solrsite",
"Keywords": searchTerm,
"FacetDates": ["modificationdate"],
"FacetDateStart": "2017-01-01T00:00:00Z",
"FacetDateEnd": "NOW/DAY",
"FacetDateGap": "+1MONTH",
"FilterQueries": ["modificationdate:[2017-03-01T00:00:00Z TO 2017-03-31T23:59:59Z]"],
},
"get": "*"
});
With the response now limited to those two results:
"result": {
"data": {
"multipleItemData": [{
"ParentData": ",31,3,1,0",
"CreationDate": "2017-03-24T14:21:56Z",
"_ItemClass": "CSSearchItem",
"GroupKey": "Article31",
"Title": "latest news",
"Url": "",
"Custom3": "1",
"Score": 75.416824,
"Type": "Article",
"Custom2": "",
"Custom1": ",31,3,1,0",
"ModificationDate": "2017-03-24T14:21:56Z",
"MetaData": "",
"DynamicFields": {
"OBJECT_C__title": "latest news"
},
"Summary": "...",
"Key": "31"
}, {
"ParentData": ",24,9,1,0",
"CreationDate": "2017-03-22T11:13:55Z",
"_ItemClass": "CSSearchItem",
"GroupKey": "Article24",
"Title": "API Test",
"Url": "",
"Custom3": "5",
"Score": 47.135513,
"Type": "Article",
"Custom2": "",
"Custom1": ",24,9,1,0",
"ModificationDate": "2017-03-22T11:13:55Z",
"MetaData": "",
"DynamicFields": {
"OBJECT_I_ITEMSPERPAGE": 100,
"OBJECT_C__title": "API Test",
"OBJECT_C_ORDERING": "NATURAL",
"OBJECT_C_INCLUDERELATEDFEATURES": "true",
"OBJECT_C_INCLUDECHILDARTICLES": "true"
},
"Summary": "...",
"Key": "24"
}],
"itemData": {...}
},
"success": true
}