Search Coordination (SearchViewModel)
Relevant source files
The following files were used as context for generating this wiki page:
The SearchViewModel serves as the primary interface for user-driven text search within the SSA Consulta Rapida application. It encapsulates the state of the search query and provides a signaling mechanism to coordinate updates between the user interface and the broader application logic managed by the MainViewModel.
As a specialized component within the presentation layer, its main purpose is to capture input text, trigger search applications, and handle search clearing requests. It operates as a child of the MainViewModel, ensuring that textual search input is integrated into the unified query execution flow.
Sources: src/presentation/SearchViewModel.h:10-20, src/presentation/MainViewModel.cpp:32-33
Architecture and Interaction Flow
The SearchViewModel follows a reactive pattern using Qt's signal-slot mechanism. It maintains a single source of truth for the search text and notifies observers whenever this text changes or when specific actions (like applying or clearing) are requested.
Data Ownership and Parentage
The SearchViewModel is instantiated as a member of the MainViewModel. The MainViewModel establishes connections to the applyRequested and clearRequested signals to synchronize the search state with the data repository.
The diagram shows how user actions in the UI propagate through the SearchViewModel to trigger query execution in the MainViewModel.
Sources: src/presentation/MainViewModel.h:116, src/presentation/MainViewModel.cpp:32-34
Component Specification
Properties and State
The class manages a single Qt Property used for data binding in QML:
| Property | Type | Access | Description |
|---|---|---|---|
text | QString | READ/WRITE | The current raw text entered by the user. |
Sources: src/presentation/SearchViewModel.h:12
Key Functions and Slots
The following methods define the operational logic of the search component:
| Method | Role | Description |
|---|---|---|
setText(value) | Setter | Updates the internal text state and emits textChanged if the value is different. |
apply() | Slot | Emits the applyRequested signal to notify the parent to execute a search. |
clear() | Slot | Resets the text to an empty string and emits clearRequested. |
Sources: src/presentation/SearchViewModel.cpp:9-25
Coordination with MainViewModel
When a search is triggered, the MainViewModel retrieves the current text from SearchViewModel to construct a SsaPageRequest. This process involves the SearchParser and SqlQueryBuilder to convert the raw text into SQL-compatible filter terms.
Sequence of Search Application
The following sequence diagram illustrates the lifecycle of a search request initiated through the SearchViewModel.
Implementation Details
Signal Propagation
The SearchViewModel does not perform search logic itself. Instead, it acts as a signal dispatcher. In MainViewModel.cpp, these signals are wired to the application's central query logic:
// MainViewModel.cpp lines 32-33
connect(&search_, &SearchViewModel::applyRequested, this, &MainViewModel::apply);
connect(&search_, &SearchViewModel::clearRequested, this, &MainViewModel::clearSearch);
Sources: src/presentation/MainViewModel.cpp:32-33
Search Parsing Integration
While SearchViewModel holds the raw string, the SearchParser (used by the query service invoked by MainViewModel) processes it for advanced syntax such as:
- Negation: Using
!or-prefixes. - Match Modes: Support for StartsWith (
^), EndsWith ($), and Regex (~). - Logical AND: Splitting terms by commas.
Sources: src/query/SearchParser.cpp:25-45, src/query/SqlQueryBuilder.cpp:32-55
Summary
The SearchCoordination (SearchViewModel) is a lean, signal-oriented component that bridges user input with the application's search engine. By delegating actual query construction and execution to the MainViewModel and underlying domain services, it maintains a clean separation of concerns within the presentation layer.
Sources: src/presentation/SearchViewModel.cpp:5-27, src/presentation/MainViewModel.h:35-37