Web UI

HOWTO: Create Searches With OR Operator

Updated: October 1, 2024

This tutorial explains how to implement an OR operator within a custom search, using page provider predicates and Elasticsearch hints.

The goal of this page is to find all document in which the selected user is either the creator or one of the contributors.

Prerequisites

You need a document type with at least two properties where you need to check if the value exists in one of the fields.

Create a Page Provider

  1. Create a page provider in Nuxeo Studio Modeler.
  2. In this page provider, create a new predicate:

    1. In the field property, add any value, like dc:creator.
    2. Choose any suitable operator (= in this tutorial).
    3. In hint index, put the list of the fields on which the OR operator should be executed, separated by a comma.
      In our case, it should be dc:creator,dc:contributors
    4. Leave the hint analyzer field empty because those fields are not analyzed at index time.
    5. Choose the relevant hint operator. For example, you can use the match operator, or the simple_query_string if you need to use wildcard characters for your searches.

    predicate_editor.png
    predicate_editor.png

Create a Search Form and Result Layout

  1. Click on the Configure layouts in Designer shortcut.
  2. Generate the form and result layouts by clicking on the Configure button.
  3. Bind a Drawer Item Search to the search elements.

studio_config.png
studio_config.png

Hot Reload and Results

Here are the documents created by User1:

doc_user1.png
doc_user1.png

Here are the documents created by User2. You can note that some of them have User1 as last contributor:

doc_user2.png
doc_user2.png

If you execute the search with User1, you find all the documents from the first screenshot, and the 2 documents edited in the second screenshot:

search_user1.png
search_user1.png