Taxonomy
Taxonomy
Taxonomy helps you categorize pieces of content within your stack to facilitate easy navigation and retrieval of information.
To access the taxonomy instance, use the code snippet provided below within the stack class:
Stack stack = Contentstack.stack("API_KEY", "DELIVERY_TOKEN", "ENVIRONMENT");
Taxonomy taxonomy = stack.taxonomy();in
The in method retrieves all entries for a specific taxonomy that satisfy the given conditions provided in the $in query.
| Name | Type | Description |
|---|---|---|
| taxonomy (required) | string | Enter the UID of the taxonomy |
| listOfItems | list<string> | Enter the list of taxonomy fields |
Example: If you want to retrieve entries with the color taxonomy applied and linked to the terms red and/or yellow.
Taxonomy taxonomy = stack.taxonomy();List listOfItems = new ArrayList<>();
listOfItems.add("red");
listOfItems.add("yellow");
taxonomy.in("taxonomies.color", listOfItems).find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
if (error!=null){
System.out.println("response :"+response);
}
}
});or
The or method retrieves all entries for a specific taxonomy that satisfy at least one of the given conditions provided in the $or query.
| Name | Type | Description |
|---|---|---|
| listOfItems | list<JSONObject> | Enter the list of taxonomy fields |
Example: If you want to retrieve entries with either the color or size taxonomy applied and linked to the terms yellow and small, respectively.
Taxonomy taxonomy = stack.taxonomy();
List<jsonobject>listOfItems = new ArrayList<>();
JSONObject item1 = new JSONObject();
item1.put("taxonomies.color", "yellow");
JSONObject item2 = new JSONObject();
item2.put("taxonomies.size", "small");
listOfItems.add(item1);
listOfItems.add(item2);
taxonomy.or(listOfItems);
taxonomy.find((response, error) -> {
if (error!=null){
System.out.println("response :"+response);
}
});and
The and method retrieves all entries for a specific taxonomy that satisfy all the conditions provided in the $and query.
| Name | Type | Description |
|---|---|---|
| listOfItems | list<JSONObject> | Enter the list of taxonomy fields |
Example: If you want to retrieve entries with the color and computers taxonomies applied and linked to the terms red and laptop, respectively.
Taxonomy taxonomy = stack.taxonomy();
List<jsonobject>listOfItems = new ArrayList<>();
JSONObject items1 = new JSONObject();
items1.put("taxonomies.color", "green");
JSONObject items2 = new JSONObject();
items2.put("taxonomies.computers", "laptop");
listOfItems.add(items1);
listOfItems.add(items2);
taxonomy.and(listOfItems);
taxonomy.find((response, error) -> {
if (error!=null){
System.out.println("response :"+response);
}
});exists
The exists method retrieves all entries for a specific taxonomy if the value of the field, mentioned in the condition, exists.
| Name | Type | Description |
|---|---|---|
| taxonomy (required) | string | Enter the UID of the taxonomy |
| value (required) | boolean | Enter true/false |
Example: If you want to retrieve entries with the color taxonomy applied.
Taxonomy taxonomy = stack.taxonomy().exists("taxonomies.color", true);
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
if (error!=null){
System.out.println("response :"+response);
}
}
});equalAndBelow
The equalAndBelow method retrieves all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term.
| Name | Type | Description |
|---|---|---|
| taxonomy (required) | string | Enter the UID of the taxonomy |
| termsUid (required) | string | Enter the UID of the term |
Example: If you want to retrieve all entries with terms nested under blue, such as navy blue and sky blue, while also matching entries with the target term blue.
Taxonomy taxonomy = stack.taxonomy().equalAndBelow("taxonomies.color", "blue");
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
if (error!=null){
System.out.println("response :"+response);
}
}
});equalAndBelowWithLevel
The equalAndBelowWithLevel method retrieves all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term and a specified level.
NoteIf you don't specify the level, the default behavior is to retrieve terms up to level 10.
| Name | Type | Description |
|---|---|---|
| taxonomy (required) | string | Enter the UID of the taxonomy |
| termsUid (required) | string | Enter the UID of the term |
| level | int | Enter the level |
Example: If you want to retrieve all entries until level 2 with terms nested under blue, such as navy blue and sky blue, while also matching entries with the target term blue.
Taxonomy taxonomy = stack.taxonomy().equalAndBelowWithLevel("taxonomies.color", "blue", 3);
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
if (error!=null){
System.out.println("response :"+response);
}
}
});below
The below method retrieves all entries for a specific taxonomy that match all of their descendant terms by specifying only the target term and a specific level.
NoteIf you don't specify the level, the default behavior is to retrieve terms up to level 10.
| Name | Type | Description |
|---|---|---|
| taxonomy (required) | string | Enter the UID of the taxonomy |
| termsUid (required) | string | Enter the UID of the term |
Example: If you want to retrieve all entries containing terms nested under blue, such as navy blue and sky blue, but exclude entries that solely have the target term blue.
Taxonomy taxonomy = stack.taxonomy().below("taxonomies.appliances", "led");
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
if (error!=null){
System.out.println("response :"+response);
}
}
});equalAbove
The equalAbove method retrieves all entries for a specific taxonomy that match a specific term and all its ancestor terms, requiring only the target term and a specified level.
NoteIf you don't specify the level, the default behavior is to retrieve terms up to level 10.
| Name | Type | Description |
|---|---|---|
| taxonomy (required) | string | Enter the UID of the taxonomy |
| termsUid (required) | string | Enter the UID of the term |
Example: If you want to obtain all entries that include the term LED and its parent term TV.
Taxonomy taxonomy = stack.taxonomy().equalAbove("taxonomies.appliances", "led");
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
if (error!=null){
System.out.println("response :"+response);
}
}
});above
The above method retrieves all entries for a specific taxonomy that match only the parent term(s) of a specified target term, excluding the target term itself and a specified level.
NoteIf you don't specify the level, the default behavior is to retrieve terms up to level 10.
| Name | Type | Description |
|---|---|---|
| taxonomy (required) | string | Enter the UID of the taxonomy |
| termsUid (required) | string | Enter the UID of the term |
Example: If you wish to match entries with the term tv but exclude the target term led.
Taxonomy taxonomy = stack.taxonomy().above("taxonomies.appliances", "led");
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
if (error!=null){
System.out.println("response :"+response);
}
}
});find
The find method is used to get the API response.
| Name | Type | Description |
|---|---|---|
| callback (required) | TaxonomyCallback | The callback class that contains the API response |
Example:
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
if (error!=null){
System.out.println("response :"+response);
}
}
});