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:
- Matches for
quick brown
,fox
,"lazy
, anddog
(Use spaces to delimit the search) - Matches for
quick brown
,fox
,lazy
, anddog
(Ignore the odd double-quote) - Matches for
quick brown
,fox
, andlazy 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:
- Matches for
qu
,ick brown
,fox
,lazy
, anddog
? - (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:
- Matches for
quick brown
,fox
,la"zy
, anddog
(Use spaces to delimit the search) - Matches for
quick brown
,fox
,lazy
, anddog
(Ignore the odd double-quote) - Matches for
quick brown
,fox
,la
, andzy 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.