For example: The following configuration:
{ "resource.name": "Search Cohort Resource", "node.root": "$['results']", "resource.object": "com.muzima.api.model.Cohort", "algorithm.class": "com.muzima.api.model.algorithm.CohortAlgorithm", "resolver.class": "com.muzima.api.model.resolver.SearchCohortResolver", "field.unique": "uuid", "field.searchable": { "uuid": "$['uuid']", "name": "$['name']" } }
When given the following REST payload:
{ "results": [ { "uuid": "xyz", "name": "Example of Cohort" } ] }
The above config will turned a REST payload into a Document with the following Field:
- name: uuid, value: xyz
- name: name, value: Example of Cohort
In addition, the Search API also adds some default fields:
- name: json, value: the full JSON payload (this one will be used by the algorithm to return the correct object).
- name: class, value: the name of the class to which the JSON can be converted into.
- name: resource, value: the resource descriptor's name.
The above "class" field can be used to query the Lucene to get all object for a particular type. The class field query combined with other field query will allow you to query for an object with certain value in one of the field. For example, if we want to get the above object, we would send the following query:
class: com.muzima.api.model.Cohort AND uuid: xyz
In the mUzima API, the above query will be hidden behind the getCohortByUuid
method.