# Configuring a Combined Search

Warning

The Combined Search will probably be rebuilt in version 3.1. The aim of the modifications is to make it easier to use combined searches.

The components.layout.search.search-actor offers the possibility to merge the search filters for a search from more than one source.

The method useInCombinedSearch can be used for this. The method is passed the source and a boolean. Each source returns the search filters for the search. The boolean controls whether the search filters of the sources should be included in the search if the search is triggered by another source.

The source that should deliver search filters must implement the 'getFilter' method. This method returns an array of SearchPropertyFilter<ce-search-property-filter>.

The 'Combined Search' is currently only supported by selected Components and Actors.

# Supporting Components and Actors

    • components.layout.search-result-controller

        • components.layout.subpanel-result-controller

          • components.layout.add-permission-result-controller
  • components.layout.reference-find-actor

  • components.layout.search-renderer-panel

  • components.lists.selection-search-actor

# Example

The following example shows a component that registers itself as combined at its specified SearchActor if the attribute useInCombinedSearch is set to true. (Line 28)

The component triggers a search in the SearchActor when the 'ENTER' key is pressed in the text field. (Lines 5-7) The component passes itself as source. (Line 6)

The SearchActor then calls the method getFilter (line 10). This returns the search filters for the search. If any other component or other actor is registered as combined with the SearchActor, the method getFilter is also called for this one. The returned search filters of all combined sources are linked with 'AND'.

Assuming that two instances of the SearchComponent from the example register as cobined, this would result in a search that searches for BaseBeans containing both the text from one and the other text field in friendlyname.

class SearchComponent extends Component {

    afterTemplate() {
        super.afterTemplate();
        KeyboardManager.on('keydown', [KeyboardManager.KC_ENTER], this.$.textfield, () => {
            this.searchActor.search(this);
        });
    }

    getFilter() {
        let searchFilter = new SearchPropertyFilter();
        searchFilter[SearchPropertyFilter.GROUP] = 'someSearchFilterGroup';
        searchFilter[SearchPropertyFilter.OPERATOR] = LogicalOperator.AND;
        searchFilter[SearchPropertyFilter.COMPARATOR] = ComparisonOperator.LIKE;
        searchFilter[SearchPropertyFilter.FIELD] = 'friendlyname';
        searchFilter[SearchPropertyFilter.VALUE] = this._getSearchValue();
        return [searchFilter];
    }

    _getSearchValue() {
        return this.$.textfield.value;
    }

    _combine() {
        if(!this.searchActor) {
            return;
        }
        this.searchActor.useInCombinedSearch(this, !!this.useInCombinedSearch);
    }

    addActor(name, actor) {
        switch(name) {
            case 'searchActor':
                this.searchActor = actor;
                break;
        }
    }

    setParameter(name, param) {
        switch(name) {
            case 'useInCombinedSearch':
                this.useInCombinedSearch = param;
                break;
        }
    }

    set searchActor(actor) {
        Assert.isInstance(actor, SearchActor, 'searchActor');
        if(this.searchActor !== actor) {
            this._searchActor = actor;
            this._combine();
        }
    }

    get searchActor() {
        return this._searchActor;
    }

    set useInCombinedSearch(val) {
        this._useInCombinedSearch = val;
        this._combine();
    }

    get useInCombinedSearch() {
        return this._useInCombinedSearch;
    }

}
Request missing documentation