Boolean

Table of contents

Summarise with:

The Boolean operators or search operators are words or symbols used in programming to combine or modify logical conditions, They are present in almost all the countries where the programming languages. They are named after George Boole, a 19th century British mathematician who developed Boolean algebra, a branch of mathematics that deals with truth values and logical operations.

Main types of Boolean operators

There are three elementary types of Boolean operators: AND, OR and NOT. All three are very easy to understand, since they perfectly mimic the human soul and represent a programming logic elementary. We explain this triad in detail:

AND

This operator combines two conditions and returns true if both conditions are true. Thus, AND narrows the search range by telling the database that it wants to find items that meet a concatenation of specific characteristics.

Example: Suppose we want to search for documents containing the words cats and dogs. We would use a boolean query like cats AND dogs. This ensures that only results that contain both words are returned.

OR

The operator combines two conditions and returns true if at least one of the conditions is true. Conversely, the OR operator broadens the search range by telling the database that a number of terms are equally valid to display broader search results.

Example: If we want to search for documents containing the word cats or the word dogs, we would use a boolean query such as cats OR dogs. This would return results that contain at least one of these words.

NOT

The NOT operator negates a condition and returns true if the condition is false and, conversely, returns false if the condition is true. NOT narrows the search range in the opposite way to AND: by discarding search results based on exclusive characteristics.

Example: If we want to search for documents that contain the word cats but not the word dogs, we would use a boolean query such as cats NOT dogs. This ensures that results are returned that contain cats, but exclude those that also contain dogs.

Other types of Boolean operators

In addition to the basic Boolean operators (AND, OR, NOT), there are other less frequent operators that can be used to manipulate and compare Boolean values in different contexts.

XOR

The XOR operator returns true when exactly one of the two conditions is true, but not both. If both conditions are true or both are false, it returns false.

That is, it returns:

  • True if one condition is true and the other is false.
  • False if both conditions are true or both are false.

ExampleIf you want to find articles that mention either dogs or cats, but not both at the same time, you would use XOR. This will give you results that contain only dogs or only cats, but not those that mention both.

NAND

The NAND operator returns true when at least one of the conditions is false. It returns false only when both conditions are true. It is the result of applying a negation to the AND operator.

That is, it returns:

  • True if at least one condition is false.
  • False if both conditions are true.

ExampleIf you want to search for articles that do not mention both dogs and cats together, you would use NAND. This will return results that mention only dogs, only cats or neither, but not those that mention both.

NOR

The NOR operator returns true only when both conditions are false. If at least one of the conditions is true, it returns false. This is the result of applying a negation to the OR operator.

ExampleIf you are looking for articles that do not mention dogs or cats, you would use NOR. This will filter out all articles that mention at least one of these animals and only show you those that don't mention them at all.

==

This operator compares two values and returns true if both are equal. If the values are different, it returns false.

ExampleIf you want to check if an article contains exactly the word dogs, you would use the equality operator. This is useful for finding articles where the mention of dogs exactly matches the search term.

!=

This operator compares two values and returns true if they are different. If the values are the same, it returns false.

ExampleIf you want to search for articles that mention any animal except cats, you would use the inequality operator. This will allow you to find texts that talk about other animals, but specifically exclude cats.

Share in:

Related articles

Command line interface

Command Line Interface (CLI) is a type of user interface that allows users to interact with a computer program or operating system by entering text commands on a command line. The command line

Malware

Although in popular parlance viruses is the umbrella term for any type of cybernetic software that threatens the security of a computer system, the reality is that the correct term is malware. A malware is a programme or application that is

Defragmentation

Defragmentation is a fundamental process for the maintenance and optimisation of hard disks, particularly mechanical hard disks (HDD). This process organises and gathers fragments of files scattered in different sectors of the disk, allowing files to be stored in a more efficient way.

Moore's Law

Moore's Law, enunciated by Gordon Moore in 1965, observes that the number of transistors that can be placed on an integrated circuit doubles approximately every two years. This translates into an exponential increase in processing power.

Scroll to Top