Toggle menu

Search Groups

Groups are similar in concept to facets, but rather than a list of facets followed by a count of matching articles, the results themselves are grouped.

In the response each group is made up of an array of CSSearchItems (the details of the articles, media items etc) and a single CSSearchGroup, which includes the group value and count of items in the group.

In this example, article results are grouped by a metadata value related to them. The metadata property has been created with a search field, called COLOUR, which means it will be indexed as a dynamic field in SOLR. There's more information about the search field in the Understanding Metadata Properties and Values article.

Request

result = this.callWorkerMethod("icmapi", "CSSearchMultiple_get", {
    "set": {
        "CollectionNameList": "Article",
        "LuceneRepositoryPath": "http://localhost:5506/solrsite",
        "Keywords": "test",
        "GroupField": "OBJECT_SF_COLOUR"
    },
    "get": "*"
});

Response

The example has been chopped around so it better fits the page. Normally each CSSearchItem would return every field.

{
    "result": [{
        "multipleItemData": [{
            "_ItemClass": "CSSearchItem",
            "DynamicFields": {
                "OBJECT_C__title": "Tomatoes",
                "OBJECT_SF_COLOUR": "Red"
            },
            "Key": "31"
        }, {
            "_ItemClass": "CSSearchItem",
            "DynamicFields": {
                "OBJECT_C__title": "Letter Boxes",
                "OBJECT_SF_COLOUR": "Red"
            },
            "Key": "67"
        }, {
            "_ItemClass": "CSSearchItem",
            "DynamicFields": {
                "OBJECT_C__title": "Flags",
                "OBJECT_SF_COLOUR": "Red"
            },
            "Key": "47"
        }],
        "itemData": {
            "_ItemClass": "CSSearchGroup",
            "GroupValue": "Red",
            "NumFound": 3
        }
    }, {
        "multipleItemData": [{
            "_ItemClass": "CSSearchItem",
            "DynamicFields": {
                "OBJECT_C__title": "Grass",
                "OBJECT_SF_COLOUR": "Frogs"
            },
            "Key": "9"
        }, {
            "_ItemClass": "CSSearchItem",
            "DynamicFields": {
                "OBJECT_C__title": "Limes",
                "OBJECT_SF_COLOUR": "Green"
            },
            "Key": "50"
        }],
        "itemData": {
            "_ItemClass": "CSSearchGroup",
            "GroupValue": "Green",
            "NumFound": 2
        }
    }],
    "success": true
}

Example Form

This form uses a server-side HTML template to call an end point. The end point searches for articles in a test area of this site. Each article has been tagged with some "colour" metadata.

This is the request:

function(params, credentials) {
    let result = this.callWorkerMethod("icmapi", "CSSearchMultiple_get", {
        "set": {
            "CollectionNameList": "Article",
            "LuceneRepositoryPath": "http://localhost:5506/solricm",
            "Keywords": "*",
            "BoostSearch": false,
            "ArticleMetaDataOptionalIDs": "13328,13329,13330",
            "RootArticleIDs": "4487",
            "GroupField": "OBJECT_SF_COLOURS"
        },
        "get": "*"
    });
    return result;
}

The handlebars template used to display the results looks like this:

{{#each this}}
    {{#if itemData.GroupValue}}
        <strong>{{itemData.GroupValue}} Things!</strong>
        <ol>
            {{#each multipleItemData}}
                <li><a href="./article/{{Key}}">{{Title}}</a></li>
            {{/each}}
        </ol>
        <br />
    {{/if}}
{{/each}}

(Take a look at the page source if you think this is just text added to the article)

Share this page

Facebook icon Twitter icon email icon

Print

print icon