1

I have web application that shows lists of various data types ... employees, customers, inventory items, orders, and so on.

There's one simple search field for doing a "global" search (we may add a new advanced "field by field" search later).

Question is, when a user enters multi-word text in the field should the default search behaviour be (1) this OR that or (2) this AND that?

What default behaviour do you think average users would expect?

Example:

Customer records:

ID  | FIRSTNAME | LASTNAME
------------------------------
001 | John      | Smith
002 | John      | Jones
003 | Michael   | Smith
003 | Betty     | Taylor-Smith

Two search behaviours:

(1) search John Smith means John OR Smith so it will return all four records.

(2) search John Smiths means John AND Smith so it will return only record 001.

  • Thanks, it actually does ... very similar problem. – moseisley.2015 May 5 at 13:23
3

AND.

As a user, the more I type in, the more specific I'm expecting the results to get, and this is what happens with AND. With OR, your results would explode!

If my search for popular Google Doodle games gave me everything that was popular, everything Google, everything Doodle and every game out there, I'd be lost!

If you're expecting your user to fetch all matching either John or Smith results, consider supporting syntax like John|Smith (where | is the logical symbol for OR) and placing a hint ? icon next to the search box to showcase the various supported syntaxes. You could also consider quotes in the search syntax for exact matches, where "Smith" wouldn't match Taylor-Smith, but Smith would.

"John"|"Smith" would then match all John and all Smith but not Betty Taylor-Smith.

Instance examples:

Search: John Smith

ID  | FIRSTNAME | LASTNAME
------------------------------
001 | John      | Smith

Search: "John Smith"

ID  | FIRSTNAME | LASTNAME
------------------------------

* no results since no exact match in any column

Search: John|Smith

ID  | FIRSTNAME | LASTNAME
------------------------------
001 | John      | Smith
002 | John      | Jones
003 | Michael   | Smith
004 | Betty     | Taylor-Smith

* all records match fully or partially

Search: "John"|"Smith"

ID  | FIRSTNAME | LASTNAME
------------------------------
001 | John      | Smith
002 | John      | Jones
003 | Michael   | Smith

* matches exactly "John" or "Smith"
| improve this answer | |
  • Very useful answer. I was originally thinking OR was better, but after playing with it I realize, like you said, the more I type, the more specific I'm trying to be so AND might be better. – moseisley.2015 May 5 at 0:27
  • Thanks for the help ... now I'm stuck on how to write the SQL ... if you have a moment, please check out my SQL question here: stackoverflow.com/questions/61614142/… – moseisley.2015 May 5 at 13:22
0

To add to SNag's answer, yes AND is the expected behavior. The best example is Google: when people type in whole sentences, they don't expect the words to exclude each other.

I don't think all users know this, but a big part does know that they can exclude terms with a - character as a prefix.

I actually do wonder when a user would really expect an OR to happen or which character to use to indicate that. Here my first thought would be | as well, but only because I have somewhat of a programming background. I think more "casual" users need a very explicit cue that their current search functions on OR basis rather than AND.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.