Taxonomy
Taxonomy
Taxonomy helps you categorize pieces of content within your stack to facilitate easy navigation and retrieval of information.
Example:import com.contentstack.sdk.*; Stack stack = Contentstack.stack(apiKey, deliveryToken, 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) (required) | string | Enter the UID of the taxonomy |
| listOfItems | list<string> | Enter the list of taxonomy fields |
Example:
Taxonomy taxonomy = stack.taxonomy();
List<string> listOfItems = new ArrayList<>();
listOfItems.add("maroon");
listOfItems.add("red");
taxonomy.in(taxonomy,listOfItems).find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("RESULT:",response.toString());
}
});or
The or method retrieves all entries for a specific taxonomy that satisfy at lease one of the given conditions provided in the $or query.
| Name | Type | Description |
|---|---|---|
| listOfItems | list<JSONObject> | Enter the list of taxonomy fields |
Example:
Taxonomy taxonomy = stack.taxonomy();
List<jsonobject> listOfItems = new ArrayList<>();
JSONObject item1 = new JSONObject();
item1.put("taxonomies.color", "orange");
JSONObject item2 = new JSONObject();
item2.put("taxonomies.country", "zambia");
listOfItems.add(item1);
listOfItems.add(item2);
taxonomy.or(listOfItems).find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("RESULT:",response.toString());
}
});and
The and method retrieves all entries for a specific taxonomy that satisfy all the given conditions provided in the $and query.
| Name | Type | Description |
|---|---|---|
| listOfItems | list<JSONObject> | Enter the list of taxonomy fields |
Example:
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.country", "india");
listOfItems.add(items1);
listOfItems.add(items2);
taxonomy.and(listOfItems).find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("RESULT:",response.toString());
}
});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 | boolean | Enter true/false |
Example:
Taxonomy taxonomy = stack.taxonomy().exists(taxonomy, Value);
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("RESULT:",response.toString());
}
});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 | string | Enter the UID of the term |
Example:
Taxonomy taxonomy = stack.taxonomy().equalAndBelow(taxonomy, termsUid);
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("RESULT:",response.toString());
}
});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.
Note If 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 | string | Enter the UID of the term |
Example:
Taxonomy taxonomy = stack.taxonomy().below(taxonomy, termsUid);
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("RESULT:",response.toString());
}
});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.
Note If 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 | string | Enter the UID of the term |
Example:
Taxonomy taxonomy = stack.taxonomy().equalAbove(taxonomy, termsUid);
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("RESULT:",response.toString());
}
});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.
Note If 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 | string | Enter the UID of the term |
Example:
Taxonomy taxonomy = stack.taxonomy().above(taxonomy, termsUid);
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("RESULT:",response.toString());
}
});find
The find method is used to get API response.
| Name | Type | Description |
|---|---|---|
| callback | TaxonomyCallback | The callback class that contains the API response |
Example:
taxonomy.find(new TaxonomyCallback() {
@Override
public void onResponse(JSONObject response, Error error) {
Log.d("Result:",response.toString());
}
});