Search - e-ucm/ead GitHub Wiki

Use

Type words into the search field to find all objects that match. Prefix matches are all included: given a query such as a b, the query will match all objects that have fields that contain words that start with a and with b.

Certain characters are replaced by spaces: everything that is not a letter or a number will be replaced by a space. This is also done during indexing. Therefore, if you index or search for "images/logo.png", you will actually be indexing the string "images logo png" (or searching for "images* logo* png*", where the * refers to prefix search)

Programmatic use

To search for a given set of terms, use

model.getIndex().search("list of terms");

This returns a SearchResult, which contains a sorted list of Matches, one per document. Matches can carry additional information, such as which fields matched.

Indexed fields

Search is implemented by keeping an up-to-date index of the current model. Not all the model is indexed - only fields that are mentioned in an indexed schema-attribute are included.

For example, since notes have their text included within an indexed property, all text that is found in notes will be included in indices.

That is, given an element such as

{
  "additionalProperties": false,
  "javaType": "es.eucm.ead.schema.editor.components.Note",
  "properties": {
    "title": {
      "type": "string",
      "description": "A title"
    },
    "description": {
        "type": "string",
        "description": "A description"
    }
  },
  "type": "object",
  "description": "A simple note for annotating stuff on editor schema."
}

You can include the field text in the index by adding an indexed property that mentions it

{
  "additionalProperties": false,
  "javaType": "es.eucm.ead.schema.editor.components.Note",
  "properties": {
    "title": {
      "type": "string",
      "description": "A title"
    },
    "description": {
        "type": "string",
        "description": "A description"
    },
    "indexed": {
        "type": "string",
        "description": "Comma-separated list of indexed properties (available for full-text search in editor)",
        "default": "title, description"
    },    
  },
  "type": "object",
  "description": "A simple note for annotating stuff on editor schema."
}

NOTE: We would have liked to use a static string or an annotation to avoid the overhead of having per-object copies of the indexable properties, but this is currently not possible with our libraries.