Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Indexing Process

When Lucene process a REST payload, Lucene will convert the REST payload into Document object. A single Document object will have one or more Field element. Each Field element will have name, value and some configuration for it. Search on Lucene are done by matching the search term and the value of a field.

In the Search API world, the definition on what gets turned into field, the name of the field and how to pull the field value are defined in the field.searchable part of the configuration. Each element of it is a key pair value where the key will be the name of the field and the value is theJsonPath (another reference for JsonPath from jayway) expression into a value in the REST payload. The node.root element will define where the evaluation of the JsonPath should be started when given a REST payload ($ is the root, $['results'] is the first 'results' child).

 

Technology Stack

For example: The following configuration:

 

Code Block
languagexml
themeEmacs
linenumberstrue
{
	"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:

Code Block
themeEmacs
linenumberstrue
{
	"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: abcxyz
  • 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 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:

Code Block
themeEmacs
class: com.muzima.api.model.Cohort AND uuid: xyz

In the mUzima API, the above query will be hidden behind the getCohortByUuid method.