🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators Search
This page was created by Charles on 2024-09-21. Last edited by Wikiadmin on 2026-07-29.

You use the Search OCL/EAL operator in a ViewModel to run its search expressions against the database and populate vSeekerResult; it is for ViewModel designers who need to present database search results.

What Search does

Search triggers the search functionality configured on a ViewModel. The search criteria are written as search expressions in OCLps, the OCL subset that MDriven can translate to SQL and execute in the database.

The search runs in the database rather than requiring the matching objects to be instantiated in the prototyper. This makes the search mechanism suitable for databases of any size.

When Search runs, it populates vSeekerResult. Use vSeekerResult in the ViewModel to display the objects returned by the search expression.

Add search expressions to a ViewModel

  1. Create or open the ViewModel that will contain the search.
  2. Right-click the ViewModel.
  3. Select Add Nested ViewModel class.
  4. Choose Add Search Expressions.
  5. Define the search criteria in the added search-expression area.
  6. Add the Search operator where the ViewModel should perform the search.
  7. Present vSeekerResult in the ViewModel as the search-result content.

Use search parameters

vSeekParam is a variable that you can use in a search expression. It lets the ViewModel accept a value from the user or another part of the ViewModel and use that value as search criteria.

For example, the following expression finds people whose Name contains the value in vSeekParam, without requiring the text case to match:

Person.allinstances->select(a|a.Name.sqlLikeCaseInsensitive('%'+vSeekParam+'%'))

In this example:

  • vSeekParam is the search value.
  • '%' before and after the value means that the value can occur anywhere in the name.
  • The selected people become available through vSeekerResult after Search runs.

You can create multiple variables and multiple search criteria when the ViewModel requires more than one input.

Choose text matching deliberately

Use sqlLikeCaseInsensitive when text matching must ignore case. The behavior of sqlLike can depend on the database server and its settings; for example, the Turnkey built-in SQL Server Compact database does not ignore case for sqlLike.

Search results

vSeekerResult is the ViewModel result used to display the objects found by the search expression. Keep the search criteria and the result presentation separate: the expression decides which objects are returned, while vSeekerResult supplies those returned objects to the ViewModel.

For the complete description of Seeker, OCLps, search expressions, and search-result pages, see Documentation:Searching.

See also