Skip to main content
Engineering LibreTexts

16.3: Boolean search

  • Page ID
    12829
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Most search engines can perform “boolean searches”, which means you can combine the results from multiple search terms using boolean logic. For example:

    • The search “java AND programming” might return only pages that contain both search terms: “java” and “programming”.
    • “java OR programming” might return pages that contain either term but not necessarily both.
    • “java -indonesia” might return pages that contain “java” and do not contain “indonesia”.
    • Expressions like these that contain search terms and operators are called “queries”.

    When applied to search results, the boolean operators AND, OR, and - correspond to the set operations intersection, union, and difference. For example, suppose

    • s1 is the set of pages containing “java”,
    • s2 is the set of pages containing “programming”, and
    • s3 is the set of pages containing “indonesia”.

    In that case:

    • The intersection of s1 and s2 is the set of pages containing “java” AND “programming”.
    • The union of s1 and s2 is the set of pages containing “java” OR “pro- gramming”.
    • The difference of s1 and s2 is the set of pages containing “java” and not “indonesia”.

    In the next section you will write a method to implement these operations.


    This page titled 16.3: Boolean search is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Allen B. Downey (Green Tea Press) .

    • Was this article helpful?