I have a basic search in my webpage. When I designed it, I chose to combine the search box inputs with OR. For example: A search for foo bar will be translated to foo OR bar, so every entry which includes foo or bar will be shown.

I did this because I thought that a search should return as much as possible and leave it to the user to search with AND (a search for foo and bar will return only the entries that contain both).

When the customer tested it, he tried a lot to search for 'foo bar' and wasn't able to find the right entry because the search returned to much. It seems confusing to him that a search for foo bar could return entries where one of the search inputs is included and not both.

What is the best way to combine search words (when the user doesn't provide any combining info)? Should I use foo AND bar or foo OR bar?

  • 2
    It still depends on your user. Even if he didn't explicitly give any info, he preferred the AND-ing of the search terms, so that's his info for you. – ACEG Aug 30 '13 at 7:25

This is a usability question (for UX.SE). Ideally, you would

  • first produce the most relevant results (the ones with the exact phrase entered),
  • then the results with search keywords (and their inflections) adjacent to each other,
  • then the results for the AND operation on search by individual keywords/their inflections (i.e. anywhere in the document),
  • and lastly, results with OR (sorted in descending order by any kind of relevance score on a search by individual keywords, their inflections and, possibly, synonyms).

I wouldn't go too far though: catching mistyped search terms may be added much later as I'm not entirely convinced of its utility. Parsing for extended Boolean logic formulas

LIKE "keyword*" AND ("text" ADJ "inflection")

is for advanced users.

You can also separate the parts visually.

Note: update based on Marjan Venema's helpful comment.

| improve this answer | |
  • 1
    +1 That's the way to do it If you want it to be even more useful you could also add results for word variations (plural/singular; verb conjugation; etc.) to all levels except the "exact phrase" one. – Marjan Venema Aug 30 '13 at 12:10
  • I understand this is the way popular search engines work, so you should probably go with this answer. But the last bullet always annoyed me; when I search for "obscure thing about driver coding in relation to the Nintendo 3DS", I get nothing but results for where to buy a 3DS, no mention of my important keywords. I'd even be fine with receiving ZERO results if 'AND' finds nothing, just to be clear. – Katana314 Aug 30 '13 at 13:20
  • @Katana314 - please re-read. Popular search engines add a lot of advertising-related junk into the results, and the algorithms are correspondngly biased. Yet, getting no results can be disheartening. If we can save the user another round of typing/clicking, it is a better solution. – Deer Hunter Aug 30 '13 at 13:32
  • @DeerHunter I understand the post. I guess it very much depends on the type of search you're doing, and what data is stored under the search. You're right that for some wordy people, reducing their search words just to get a result might be annoying; but for me, having to wade through several pages to figure out that the search engine threw out the most important 5 out of my 6 words is frustrating. – Katana314 Aug 30 '13 at 13:38
  • @Katana314 - agreed, that's where the "visual separators" come into play. – Deer Hunter Aug 30 '13 at 13:39

This totally depends on the use case of course there may be many applications where OR would be the right thing to do.

In general I think most users (especially if not very experienced) will understand the AND variant better. That way (as your customer says) you can reduce the amount of results very easily.

But there are cases for OR too of course. Especially when there may be information in the text search where several variations to write something may exist and the user can't know which one was chosen.

As a conclusion: I would start with the AND as the basic assumption (unless there is a strong indication that this is wrong for your specific kind of data). But I would also try to provide some simple syntax that would allow the experienced user to fallback to use OR (and maybe more options). Maybe a search string like this: test [maybe1 OR maybe2 OR maybe3] which would look for a text that contains 'test' and at least one of the other options.

Depending on your search engine you can get around this problem somehow if you can sort by relevance. In this case for some use cases the amount of results may be less relevant because those with most keyword hits would be sorted on top.

| improve this answer | |

I know this doesn't give you the solution, but have you considered looking into the subject of information retrieval? I've done this at university, and based on what I can remember, it works in the following way:

  • You have documents
  • You have a search term
  • You can then use probability to scan your document using the search terms
  • You would then end up with vectors representing your results. There will also be a vector for your search term. The angle between the vectors will show close your term is in relation to the document. Smallest angle between vectors will represent best match, when biggest angle will represent worst match.

Hopefully image below will help you understand the idea.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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