On my website I have a search bar. It's powered by Lucene.net. I have a requirement to make search be a substring case insensitive search, with direct hits appearing before substrings. What I don't know, however, is when a user searches for a multi-word item--say "Chocolate Milk"--should that be treated under the hood as an AND or OR search?

As an example:

*chocolate* AND *milk*


*chocolate* OR *milk*

The requirement right now is to treat this as an AND, but I'm not sure if that's the right way to go about it. What would be the best in terms of UX?

I would think the best thing to do would be an OR search, with items containing both keywords appearing before items containing only one of the keywords. Thoughts?

EDIT: The types of items being searched are medical supplies, with very cryptic names.

  • 1
    Its "to infinity and beyond" not "to infinity or beyond"! Apr 28, 2014 at 21:07

5 Answers 5


An AND search gives fewer results than an OR search, and that seems the more natural behavior. If I get too many hits on "milk" I'll try "chocolate milk" and "instant chocolate milk," getting fewer, more relevant, hits each time.

  • This makes the most sense to me.
    – jdylanmc
    Apr 30, 2014 at 14:59

Without context, this is my ranking, from best match to worst:

  1. "The children drink chocolate milk." (exact match)
  2. "The children eat milk chocolate." (AND, short distance)
  3. "The children eat chocolate and drink milk" (AND, longer distance).
  4. "The children eat chocolate. (OR)
  5. "The children eat chocolat". (approximate match)
  6. "The children eat bananas." (no match)

It is hard to give a definite answer without context though. What kind of items are they searching? How many results does each of the alternatives give? In case the AND interpretation rarely gives results, it might be a better idea to treat every query as OR, to prevent frustration from empty result sets.

If you have the chance, try to test this with real users. Have them enter some queries, and ask them what they mean and how they would like the results to be listed.

  • Medical supplies, with very cryptic names.
    – jdylanmc
    Apr 29, 2014 at 15:21

I think that the best UX would be to sort the results by relevance, where results with all conditions appear first, results with n-1 out of n next and so on. This can even be extended to sort results with similar conditions

E.g. relevance of chocolate AND milk > cocoa AND milk > milk > butter.

The default for web searches is usually OR with some kind of sort by relevance.

I personally, add AND, NOT (or -), (+) and "+" to my searches if I am looking for something specific, otherwise I rely of the defaults.

For chocolate milk I would search for chocolate milk and if the first results weren't good enough replace that with "chocolate milk" which searches for the entire express (with the words in that order with no words in between).

  • Isn't AND the default? As you add more keywords you get fewer hits, right? Apr 29, 2014 at 12:33
  • 1
    @KenMohnkern Most search engines are massively more complex that AND/OR Apr 29, 2014 at 16:40
  • 1
    @KenMohnkern No. The default is a more of a fuzzy logic related ordering with some fuzzy score cut-off threshold. Apr 29, 2014 at 18:53

I would say look at what major ecommerce sites are doing... like amazon and zappos. They've done tons of A/B testing to determine this ages back.

FYI: They use AND and not OR

My reasoning for this pattern: Users tend to be lazy in that they type the least amount of words as possible to find what they need. If they deliberately type in both words... it's probably because they are looking for that thing specifically. In other words, typing only one word didn't provide me with what I wanted... so I'll narrow my search by adding a second word

If possible, consider adding faceted search filtering if your database has lots of items. Most users including medical professionals aren't as search savvy as us who work in tech. It'll make their lives much easier if they can search and filter to find what they need.


I always felt that AND would be the best answer, and that the default "OR" in search engines is to artificially pump up the number of results and "look better".

Especially with Google and commercial search engines, bringing back more results has a definite business advantage, but for a corporate search engine the rationale is weaker.

Have you tried doing some testing using the search logs and see if the most clicked links would be shown closer to the top with either option?

That might give you some clues on how appropriate would be one or the other solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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