Boolean Search: Library and Computer Science Style

One common set of tools of the librarian trade are the databases that are purchased and taught to researchers in the community they serve.  The most powerful searches are performed based on the boolean logic of AND, OR, and NOT. The figure below is an example of one of those search interfaces:

Academic Search Premier Search box

Each row can be set to focus on a particular field and mixed together with the Boolean operators in the drop-down menus on the left. This week’s course showed what the code looks like underneath the graphic display.

Computer code uses the same basic operators but represents them in the following ways:

    • AND = &&
    • OR = ||
    • NOT = !

It also uses commands that direct the computer to look for certain things in fields within a table of data. For instance, if we were looking at a table with fields full of data about the authors, titles, publication dates and we were looking for that children’s book author whose name starts with “C”.

One line might look like this:

if (row.getField(“author”).startsWith(“C”)) { print(row) }

Before this line there would be a code that would repeat this step, called a for loop and it would retrieve any names that begin with C in the table and print that row. We could then add another line with a boolean operator to get more sophisticated results. The results bring up a list of too many to choose from.

Let’s say that we remember that she wrote a book about a mouse.

if (row.getField(“author”).startsWith(“C”) &&

row.getField(“title”).startsWith(“Mouse”)) { print(row)}

It is really the search, C* in the author field AND Mouse in the title but shows us how it is translated into computer speak through the nice interfaces we use. We might now get the result of Beverly Cleary’s Mouse and the Motorcycle.

This entry was posted in Information Retrieval, Programming and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s