Using double quotes for exact matching - how to handle edge cases? (Ex. Odd number of quotes.)

64 Views Asked by At

Summary

It's been requested that we add exact matching to the search form on our site.

Below are examples of how we expect the search to operate.

Example 1

No exact match has been indicated by the user

Input: quick brown fox lazy dog
Output: matches for quick, brown, fox, lazy, and dog

Example 2

"brown" is the exact match indicated by the user

Input: quick "brown" fox lazy dog
Output: matches for quick, brown, fox, lazy, and dog (Same as example 1.)

Example 3

"brown fox" is the exact match indicated by the user

Input: quick "brown fox" lazy dog
Output: matches for quick, brown fox, lazy and dog

Example 4

"quick brown" and "lazy dog" are the exact matches indicated by the user

Input: "quick brown" fox "lazy dog"
Output: matches for quick brown, fox, and lazy dog

Question

Now we're trying to determine how edge cases should be handled. Specifically, how should we handle an odd number of quotes (see example 5) and how should we handle double quotes that occur in the middle of words (see example 6 and 7)?

Example 5

Odd number of double-quotes

Input: "quick brown" fox "lazy dog

Possible Output:

  1. Matches for quick brown, fox, "lazy, and dog (Use spaces to delimit the search)
  2. Matches for quick brown, fox, lazy, and dog (Ignore the odd double-quote)
  3. Matches for quick brown, fox, and lazy dog (Add a closing double-quote after the last term)

Example 6

Even number of quotes, some of which interrupt a word

Input: qu"ick brown" fox lazy dog

Possible Output:

  1. Matches for qu, ick brown, fox, lazy, and dog ?
  2. (I couldn't think of another way to handle it, but I'm open to ideas.)

Example 7

Odd number of quotes, final quote interrupts a word

Input: "quick brown" fox la"zy dog

Possible Output:

  1. Matches for quick brown, fox, la"zy, and dog (Use spaces to delimit the search)
  2. Matches for quick brown, fox, lazy, and dog (Ignore the odd double-quote)
  3. Matches for quick brown, fox, la, and zy dog (Add a closing double-quote after the last term)

Resources

I tried to search for resources that suggest best practices or common practices for these edge cases, but I wasn't able to find anything.

If you know of any resources on this, please let me know.

0

There are 0 best solutions below