Custom Search

Context

You have a complex domain model consisting of various kinds of entities related to each other.

Problem

How can you effectively navigate between domain entities by name, content or other criteria?

Forces

— It can be hard to anticipate which domain entities you will need to navigate to.

— Designing a good query interface can be a difficult task.

Solution

Add a custom search for every kind of domain entity you want to navigate to.

Steps

Simply search by substring against various attributes of the domain objects. Add a separate search for each attribute type or domain object.

Examples

Below we can see custom searches for people and addresses within an address book. (Click on the magnifying glass to enter search text.) As with other custom tools, one way to implement a custom search is as a method of the domain object from which the search is initiated, with a dedicated annotation. In GT, custom searches are annotated with <gtSearch>, and triggered within multiple moldable tools, such as the inspector, the code editor, and also the notebook.

Consequences

You need a Moldable Tool into which you can dynamically plug custom searches. The same search interface can accommodate multiple custom searches to query different attributes of multiple domain entities.

Known Uses

A form of custom searches are supported by the JetBrains IDE to support configurable help services. Within GT, each knowledge base of notebook pages supports custom searches by title or contents. Within the moldable inspector, any object can define multiple custom searches over related collections of objects, for example, a movie database could search for matching titles, directors, or countries of origin.

Related patterns

You need a Moldable Tool to automatically plug in a custom search. In order for the result of a search to also be a Moldable Object, you should consider wrapping it as a Moldable Collection Wrapper.

GT implementation notes

Add a custom search for every kind of domain entity you want to navigate to. Simply search by substring against various attributes of the domain objects. Add a separate search for each attribute type or domain object.

In the example below we can see several custom searches for page names, page content and link names within a website, by entering an arbitrary search string into the Spotter (magnifying glass icon).

As with other custom tools, one way to implement a custom search is as a method of the domain object from which the search is initiated, with a dedicated annotation.

In GT, custom searches are annotated with <gtSearch>, and triggered within multiple moldable tools, such as the inspector, the code editor, and also the notebook.

For example this search for pages is implemented in AWebsite>>#gtSpotterForPageNames: gtSpotterForPageNames: aSearch <gtSearch> ^ aSearch list title: 'Page names'; priority: 10; items: [ self pages items ]; itemsLimit: Float infinity; itemName: #path; sendCategory: [ :aCategory :aStep :thisSearch | self webPageGroupClass withAll: aCategory items contents ]; filterBySubstring