How to Build a Query Using Boolean Operators
Video Tutorial Creating a Boolean OR query in the Query Tool
The examples shown are based on the sample project Children & Happiness. You can download and import it, if you want to follow along.
Example 1
Open the Query Tool: Select Analysis > Query Tool. When the query tool opens, the first code from your code list is selected.
Question
The aim is to find all statements where people wrote about the two positive effects of parenting: 'fulfillment' and 'life is richer'.
Change the operator in the first line to any.
In the second line, change the code to 'effects pos: fulfillment'.
Click on plus at the end of the second line to add a second code to the query. Select 'effects pos: life is richer'.
A second way to enter a Boolean query is as follows:
Leave the first line as is: Contains quotations which must match all of the following rules.
In the second line, click on the first field and select the OR operator. As the OR operator always requires two arguments, two lines are added where you can enter codes or code groups.
Change the code in the third line to 'effects pos: fulfillment', and the code in the fourth line to 'effects pos: life is richer'.
If you want to select a code group instead of a code, click on the Code field and select Code Group from the drop-down menu.
Reading the Results of a Query
- The resulting number of quotations are shown on the right-hand side
- The results of the query are shown in the Quotation Reader below the query. The full functionality of the quotation reader is also available here.
Removing or Modifying a Query
If you want to add a new query, change the operator and select different codes or code groups. Instead of selecting a different operator, another option is to select undefined (Empty). Then you can build a query from scratch.
If a query gets more complex and there are multiple lines, you see a minus button. If you click on it, this part of the query is removed.
Example 2
In this example, we show how to build a query with two Boolean operators.
Question
The aim is to find all statements where people wrote that children either make them more happy, or they experience equal level of happiness, plus they mentioned a source of happiness captured by codes of the code group 'sources of happiness'.
This is a bit more complex, as we need to embed an OR query within an AND query. We first need to find all statements where people express equal level of happiness or more happiness. This is the OR part of the query. The AND part of the query is to find only those quotations that are also coded with any of the codes from the code group 'sources of happiness'.
This query yields 1 quotation as result.
We need to start with the AND operator, so we can embed the OR query within in: Select the operator AND. Next, you can either click on the button Embed rule on the right-hand side and select the OR operator, or change the field "is coded with" in the third line to the OR operator.
Add the two codes 'children: = equal level of happiness' and 'children: > happiness' into the fourth and fifth line.
In the sixth line change the field 'code' to code group and as code group select 'sources of happiness'. See image below.