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
- Create a page provider in Nuxeo Studio Modeler.
In this page provider, create a new predicate:
- In the field property, add any value, like
dc:creator
. - Choose any suitable operator (
=
in this tutorial). - 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 bedc:creator,dc:contributors
- Leave the hint analyzer field empty because those fields are not analyzed at index time.
- Choose the relevant hint operator. For example, you can use the
match
operator, or thesimple_query_string
if you need to use wildcard characters for your searches.
- In the field property, add any value, like
Create a Search Form and Result Layout
- Click on the Configure layouts in Designer shortcut.
- Generate the form and result layouts by clicking on the Configure button.
- Bind a Drawer Item Search to the search elements.
Hot Reload and Results
Here are the documents created by User1
:
Here are the documents created by User2
. You can note that some of them have User1
as last contributor:
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: