Optimized content search exploiting tags

Optimized content search exploiting tags

The following cases describe the most common methods to perform optimized content search exploiting tags. Each case will be provided with examples and, where possible, with a JSON code; such piece of code can be included in the body of the findByProperties web service, which is included within the contents package of xcontents. Remember to fill the JSON with required parameters.

 

1) Search content with a specific tag

You will have to use the itagOp parameter to provide the desired tag.

{
    "client": {
        "clientId": ""
    },
    "criteria": {
        "linkedCategories": [
            "!__TRASH_"
        ],
        "itagOp": {
            "itags": [{
                "id": "",
                "classificationId": ""
            }]
        }
    }
}
  • By adding the linkedCategories criteria as shown above you can improve the response timing avoiding search on deleted content.
  • classificationId can be retrieved with a list request while the tag id can be retrieved with a listget request, providing the classificationId.
  • You can use both the id and the prettyId of the tag; please be aware that if you use the prettyId it is case sensitive.
  • This request will return content tagged with the specific tag or with any of its child tags.

 

E.g.: Let's suppose to have the following tag tree (pretty ids are shown):

If you perform the search for the tag "Boots", it will return all content tagged "Boots" or "Ankle" or "Knee-High".

 

2) Search content with a specific set of tags (AND criteria adopted)

You will have to use the itagOp parameter to provide the desired set of tags.

{
    "client": {
        "clientId": ""
    },
    "criteria": {
        "linkedCategories": [
            "!__TRASH_"
        ],
        "itagOp": {
            "itags": [{
                "id": "",
                "classificationId": ""
            }, {
                "id": "",
                "classificationId": ""
            }],
            "operation": "AND"
        }
    }
}
  • In order to provide the specific set of tags you will have to fill an array of itags, providing both the id (or prettyId) of the itag and its classificationId.
  • Provided itags can belong to different classes
  • Provided tags can belong to the same tree or to different trees; however, child tags can be omitted if you are searching by their parent tags.
  • You can use both the id and the prettyId of the tag. Please be aware that prettyIds are case sensitive.
  • This request will return content tagged with all the specific tags within the set or with any of their child tags.

 

E.g.: Let's suppose you have the following tag trees (pretty ids are shown):

If you perform the search for the tags “Boots” AND “Synthetic”, it will return all the content tagged both “Boots” (or any of its child tags) and “Synthetic” (or any of its child tags).

 

3) Search content with at least one tag of a specific set (OR criteria adopted)

You will have to use the itagOp parameter to provide the desired set of tags.

{
    "client": {
        "clientId": ""
    },
    "criteria": {
        "linkedCategories": [
            "!__TRASH_"
        ],
        "itagOp": {
            "itags": [{
                "id": "",
                "classificationId": ""
            }, {
                "id": "",
                "classificationId": ""
            }],
            "operation": "OR"
        }
    }
}
  • In order to provide the specific set of tags you will have to fill an array of itags, providing both the id (or prettyId) of the itag and its classificationId.
  • Provided itags can belong to different classes
  • Provided tags can belong to the same tree or to different trees; however, child tags can be omitted if you are searching by their parent tags.
  • You can use both the id and the prettyId of the tag. Please be aware that if you use the prettyId it is case sensitive.
  • This request will return content tagged with at least one tag of the provided set or with any of their child tags.

 

E.g.: Let's suppose to have the following tag trees (pretty ids are shown):

If you perform the search for the tags “Boots” OR “Synthetic” it will return all the content tagged “Boots” (or any of its child tags), all the content tagged “Synthetic” (or any of its child tags), and all the content tagged both “Boots” and “Synthetic” (or any of their child tags).

 

4) Search content combining tag criteria AND a textsearch on the basic content’s information (title, description)

You will have to use the textSearch parmeter to provide the keyword to be searched, while the itagOp parameter will be used to provide the desired tag/set of tags.

{
    "client": {
        "clientId": ""
    },
    "criteria": {
        "locale": "",
        "textSearch": {
            "searchKey": "",
            "searchKeyOption": "BY_TOKEN",
            "searchOnFields": [
                "NAME",
                "DESCRIPTION"
            ]
        },
        "linkedCategories": [
            "!__TRASH_"
        ],
        "itagOp": {
            "itags": [
                {
                    "id": "",
                    "classificationId": ""
                }
            ]
        }
    }
}
  • You can search both on a specific tag and on a set of tags, using “AND” or “OR” criteria, according to the above descriptions.
  • Provided tags can belong to different classes.
  • Provided tags can belong to the same tree or to different trees; however, child tags can be omitted if you are searching by their parent tags.
  • The searchKey can operate on basic information such as NAME, DESCRIPTION, AUTHOR.
  • All the “criteria” operate with the “AND” search method between them, while the arrays of their single objects (e.g.: searchOnFields) operate with the “OR” search method among their elements.
  • If you wish, you can use more than one searchKey: the search will operate returning at least one of them, unless you set the “searchKeyOption” to “EXACT_MATCH”, in this case it will return all the results containing the exact provided string (words in the same order). E.g: If you search by

 

E.g.: Let's suppose to have the following tag trees and the following content:

              

                                                                        

 

If you perform the search for the keyword “Boots” it will return all the content tagged “Boots” (or any of its child tags) and the content with the word “Boots” among its basic information, hence both content shown above will be returned.

Another way to obtain the same result of the aforementioned case is to provide the keyword in the textSearch parameter and include the "ITAGS" in the "searchOnFields" parameter:

{
    "client": {
        "clientId": ""
    },
    "criteria": {
        "locale": "",
        "textSearch": {
            "searchKey": "",
            "searchKeyOption": "BY_TOKEN",
            "searchOnFields": [
                "NAME",
                "DESCRIPTION",
                "ITAGS"
            ]
        },
        "linkedCategories": [
            "!__TRASH_"
        ]
    }
}

This search will retrieve all the content with the keyword among its basic information AND all the content with the keyword among its itags.

If you perform a search using the "EXACT_MATCH" searching on itags tooplease be aware that you will be retrieve all the content tagged with tags containing the provided keyword. This happens because the text search is built to perform on texts, where typically you don't know a priori what you are going to obtain. If you wish to perform such search to retrieve all content tagged with a specific tag (excluding its child-tags) we suggest you to read this article.

Was this article helpful?
4 out of 4 found this helpful

Have more questions?

SUBMIT A REQUEST

Hai altre domande?

INOLTRA UNA RICHIESTA

Comments