AND and OR operators
Search all features and relations in your system. Perform complex operations using AND and OR. The censhare Expert search is a tool for experienced users to search for assets.
Purpose
Search within all asset properties and asset relations.
Use AND and OR for complex searches.
Introduction
The Expert search is a powerful tool that allows you to define complex search queries in censhare. There are different operators that you can combine to search for asset properties and relations. This article shows how to build more complex search queries with these combined operators:
The logical operator AND
The logical operator OR
It requires the following knowledge of the Expert search:
Search for any asset property in your system.
Combine search terms for asset properties with AND respective OR.
Use the RELATION operator to search for assets that have a certain relation.
Besides that, you can:
Use the RELATION and NOT operators in several ways to define complex searches.
Combine AND and OR conditions on one query
One of the advantages of the Expert search is that you can build more complex searches using the logical operators AND and OR combined in one query. For example, you search for assets that have been edited by person A or person B. The MIME type of the assets should be JPEG or TIFF:
((Modified by = Person A) OR (Modified by = Person B)) AND ((Mime type = TIFF image) OR (Mime type = JPEG image))
In the Expert search you can create a lot of different combinations with AND and OR. Below, we present the combinations in different scenarios:
If you combine AND and OR, the search terms must be nested. This determines the logical order how they are combined. The basic rule is that search terms with an AND, are executed first, followed by terms with an OR. If this is not the order you want, you must set brackets like in the example above.
Brackets are necessary for nested search queries to define their own hierarchical logic. Removing the brackets in the example above, results in a different query:
(Modified by = Person A) OR (Modified by = PersonB) AND (Mime type = TIFF image) OR (Mime type = JPEG image)
This query searches for assets that meet one of the following conditions:
Modified by person A
Modified by person B and the "TIFF image" MIME type
With the "JPEG image" MIME type
The way you set the brackets also determines the way how to setup the different search terms in the Expert search.
Scenario 1: A and (B or C)
In this scenario, the search query combines three parameters: Condition A and one of the conditions B or C must be true.
For example, you search for assets that are assigned to either Person 1 or Person 2, and that are of the type Layout:
AND (
(Type = Layout)
OR (
(Workflow target = Person 1)
(Workflow target = Person 2)
)
)
To build the search query:
Click "+" icon and enter the search term for the Layout type.
Click "+" icon below for the operators and select OR.
Click "+" icon below the OR and enter the search terms for the "Person 1" and "Person 2" as Workflow targets.
Tip: The reason why to use the OR condition here is to make sure that one of the two Workflow targets is set in the layout.
Scenario 2: A and B and (C or D)
This is an extension of scenario 1, where one condition is added. Assume that you search for images that are in the domain "Magazine 1" that are either royalty-free or with royalties:
AND (
(Type = Image)
(Domain = Magazine 1)
OR (
(License = Free)
(License = Fees apply)
)
)
To build the search query:
Click "+" icon and enter the search term for the Image type.
Click "+" icon behind the first search term and enter the search term for the "Magazine 1" domain.
Click "+" icon for operators below and select OR.
Click "+" icon below and enter the search terms for the royalty-free and with-royalties licenses.
Tip: The reason why to use the OR condition here is to make sure that one of the two license types is set in the image and exclude images that have no license information at all. Alternatively, you can use the condition that there is no license instead: "License NOT NULL".
The search: (Type = Image) AND (Domain = Magazine 1) AND ((License = Free) OR (License = Fees apply)).
The search possesses two parameters (6) and one OR condition (5) that are connected with an AND. The theoretical line (4) shows that an OR connects both parameters on the right. Use the "+" icon(1) to add an AND condition. Use the "+" icon (2) to expand the OR condition. Use the "Operator" icon (3) to expand an OR condition that is connected to all the other specifications with an AND.
Scenario 3: (A and B) or (C and D)
In this scenario, the top-level condition is an OR with several AND query blocks nested inside. Assume that you search for Events in the domain "Magazine 1" or Advertisements in the domain "Magazine 2":
OR (
AND (
(Type = Event)
(Domain = Magazine 1)
)
AND (
(Type = Ad)
(Domain = Magazine 2)
)
)
To build the search query:
Click "+" icon at the bottom left (operator button) and select OR.
Click the second "+" icon below the OR query block (aligned with the OR) and select AND.
Click the right-indented "+" icon below the AND query block and enter the search term "Type = Event".
Click the "+" icon next to the search term to add a new line and enter the search term "Domain = Magazine 1".
Click the second, left-indented "+" icon for operators below the search term and select AND.
Repeat the steps 3 and 4 to add the search terms "Type= Ad" and "Domain = Magazine 2".
Tip: To build this type of query - (A and B) or (C andD) - you must start with an initial OR condition. However, the top-most cannot be changed or deleted in the dialog. Start with an OR query block and do not enter an initial search term. Inside this block, add the AND query blocks and inside these blocks, enter the search terms as described below.
The search: (Type = Event) AND (Domain = Magazine 1)) OR ((Type = Advertisement) AND (Domain = Magazine 2)).
Scenario 4: (A or B) and (C or D)
This is the opposite of scenario 3, where the operators AND and OR are exchanged. Assume that you search for assets that have as Workflow target either "Person 1" or "Person 2". The assets must also have the "JPEG image" or the "PNG image" MIME type:
AND (
OR (
(Workflow target = Person 1)
(Workflow target = Person 2)
)
OR (
(MIMEtype = JPEG image)
(MIMEtype = PNG image)
)
)
To create a search query that matches several OR conditions, add an OR query block for each parameter and create the respective search terms in each block:
Click "+" icon for operators at the bottom left and select OR.
Add the search term for one parameter.
To add a new search term, click the "+" icon next to the search term.
Create the search term for the following parameter.
Repeat the steps for each parameter.
To add a new query block, click "+" icon for operators at the bottom and select OR.
Repeat the previous steps and create the search terms in the new block.
The search: ((Workflow target = Person 1) OR (Workflow target = Person 2)) AND ((MIME-Type = JPEG Image) OR (MIME-Type = PNG Image)).
Two OR searches (1) and (2) linked by an AND condition (6). The theoretical line (5) and (3) shows that the parameters are each linked with an OR. The theoretical line (4) shows that an AND connects the OR conditions.
AND and OR: Use brackets
In the formal notation, query blocks are represented by a leading logical operator and brackets. The brackets show the hierarchy and sequence of the nested query blocks. Like in a mathematical term, brackets avoid ambiguous expressions. For example, the search query "Show assets that are A and B or C" is ambiguous. With brackets, you can disambiguate the expression to "Show assets that are (A and B) or C", or "Show assets that are A and (B or C)".
If you do not use brackets correctly, the search results are different to the intended search, since the sequence of the logic is different from the originally intended one.
In the Expert search dialog of censhare Web, brackets are not displayed. Instead, each query block is represented by the leading logical operator and a line separator. The logical operator of a search query block (a set of search terms) is displayed above a horizontal line. This operator applies to all search terms directly below the line.
Nested search query blocks are displayed indented. Search query blocks at the same hierarchical level are shown vertically aligned. The logical operator applies to the nested group as a whole.
The following example shows how the results change depending on where you put the brackets. Assume you want to search for assets of the MIME type GIF or PNG in the domain Magazine 1 or in domain Magazine 2. This query allows different readings and hence shows different results.
The following notation represents a search for all GIF or PNG images that are either in the domain Magazine 1 or in the domain Magazine 2:
AND (
OR (
(MIME-Type = GIF)
(MIME-Type = PNG)
)
OR (
(Domain = Magazine 1)
(Domain = Magazine 2)
)
)
Now, see the same term with brackets to show the logic. They are not needed because AND has priority before OR:
OR (
(MIME-Type = GIF)
(Domain = Magazine 2)
AND (
(MIME-Type = PNG)
(Domain = Magazine 1)
)
)
Result
You have learned to use the logical operator AND and OR in different scenarios.