1

When a user enters a search term in quotes, should the search engine search what is within the quotes exactly, or should it perform some analysis on the query like a query without quotes?

For example, should the query "U.S. of America" match US of America? Similarly, should the query "foo-bar" match foo bar? When these queries are not in quotes, I would assume the answer is yes, they should match. However, when placed in quotes, the user is suggesting that they are looking for an exact match. The question is just how exact.

I understand that this is more of a design choice than a programming choice, but how would I even answer this question? If asked, my users probably wouldn't know what I'm talking about. Is there an easy answer here?

speedplane
  • 15,673
  • 16
  • 86
  • 138

1 Answers1

0

For an out of the box solution check simple-query-string-query. You'll notice it takes qoutes into account.

Related to 'foo-bar' vs 'foo bar' and 'U.S.' vs 'US'. That is determenied by the analyzer and tokenizer on index. Those define how strings are split into tokens and how the tokens are modified or even ignored. Unless you specify something custom the standard analyzer with the standard tokenizer are used. Check the links how your cases would be treated.

To understand how token positions are taken into account when doing phrase matches see this post.

Andreyy
  • 511
  • 2
  • 11
  • I think what you're saying is that quotes should not affect analysis or tokenization. So in that case `"foo-bar"` would match `foo bar`, but only if the query without quotes did as well, right? – speedplane Nov 06 '16 at 17:43
  • 1
    _Quotes should not affect analysis or tokenization._ Correct. _So in that case "foo-bar" would match foo bar, but only if the query without quotes did as well, right?_ Correct. The query with quotes is more complex and looks at token positions. Here's more info. https://www.elastic.co/guide/en/elasticsearch/guide/current/phrase-matching.html – Andreyy Nov 08 '16 at 13:33