Search help is ready when its examples produce the documented interpretation in the product’s supported search surface. Familiar punctuation is not enough. A space may mean AND, OR or part of a literal phrase; a field name may work in one search box and be ordinary text in another.
Identify the exact search surface and authorized audience before explaining syntax. This guide supplies a small fictional grammar and complete local fixture. It is not an Elasticsearch implementation, a relevance benchmark or evidence of any real product’s behavior.
The search-failure triage guide decides whether a failed search needs content, vocabulary or retrieval work. This acceptance method asks an earlier question: does the public help accurately describe the language being parsed?
Freeze defaults and error behavior
Elastic’s simple query string documentation provides a useful example of parser-specific behavior. It documents configurable operators and a default operator; it also says that this query type ignores invalid parts rather than returning syntax errors. Do not transfer those rules to another parser merely because both call their input a query.
For the teaching grammar below, unquoted text searches case-insensitive title substrings. Double quotes keep a phrase together; they do not support embedded quote escaping. Explicit uppercase AND binds more tightly than OR. Parentheses change grouping. tag: matches an exact tag, and status: accepts only published or draft. There is no implicit operator between adjacent terms.
An unknown tag is a valid query with no matches. An unsupported status value, an unclosed phrase or the unsupported NOT operator produces a query error. These are invented rules chosen to expose meaningful differences, not recommendations that all search products adopt them.
Use a complete permitted corpus
Assume the fictional test reader is authorized to search all six records, including D4. This is a local fixture, not an instruction to expose private drafts in a public index.
| ID | Title | Tag | State |
|---|---|---|---|
| D1 | Approval setup guide | setup | published |
| D2 | Approval troubleshooting | support | published |
| D3 | Invoice import guide | data | published |
| D4 | Draft approval experiments | setup | draft |
| D5 | Webhook setup guide | setup | published |
| D6 | Invoice export reference | data | published |
Keep permission filtering outside any claim about this fixture. A real authorized corpus may differ by reader. A correct syntax explanation cannot establish whether an inaccessible document should be returned. Preserve the product’s access policy rather than weakening it to make an example match.
Publish the expected results with the grammar
| Query | Declared outcome |
|---|---|
| approval | D1, D2, D4 |
| "setup guide" | D1, D5 |
| tag:setup AND status:published | D1, D5 |
| approval OR invoice | D1, D2, D3, D4, D6 |
| approval AND tag:setup | D1, D4 |
| (approval OR invoice) AND status:published | D1, D2, D3, D6 |
| tag:data AND export | D6 |
| approval AND (tag:setup OR tag:support) | D1, D2, D4 |
| tag:unknown | Valid query; zero matches |
| status:archived | Unsupported value error |
| approval NOT invoice | Unsupported or misplaced operator error |
| "unclosed | Unclosed phrase error |
The table is an acceptance oracle for these exact inputs. It does not specify ranking among returned records. Do not describe a set-membership check as proof that the first result is the most useful answer. Case-sensitive operators, field values and literal text also need their own accurately stated rules.
Replay the documented examples locally
This complete standard-library Python program implements only the declared teaching grammar. It requires no packages, account or network. Its assertions compare parsed results with the independent table above and keep invalid input distinct from an empty result.
import re
rows = [
("D1", "Approval setup guide", "setup", "published"),
("D2", "Approval troubleshooting", "support", "published"),
("D3", "Invoice import guide", "data", "published"),
("D4", "Draft approval experiments", "setup", "draft"),
("D5", "Webhook setup guide", "setup", "published"),
("D6", "Invoice export reference", "data", "published"),
]
def find(query):
if query.count('"') % 2:
raise ValueError("unclosed phrase")
tokens = re.findall(r'"[^"]*"|[()]|[^()\s]+', query)
position = 0
def atom():
nonlocal position
if position >= len(tokens):
raise ValueError("missing term")
token = tokens[position]
position += 1
if token == "(":
result = either()
if position >= len(tokens) or tokens[position] != ")":
raise ValueError("unclosed group")
position += 1
return result
if token in {"AND", "OR", "NOT", ")"}:
raise ValueError("unsupported or misplaced operator")
if ":" in token:
field, value = token.split(":", 1)
if field == "tag" and value:
return {r[0] for r in rows if r[2] == value}
if field == "status" and value in {"published", "draft"}:
return {r[0] for r in rows if r[3] == value}
raise ValueError("unsupported field or value")
term = token.strip('"').casefold()
if not term:
raise ValueError("empty term")
return {r[0] for r in rows if term in r[1].casefold()}
def both():
nonlocal position
result = atom()
while position < len(tokens) and tokens[position] == "AND":
position += 1
result &= atom()
return result
def either():
nonlocal position
result = both()
while position < len(tokens) and tokens[position] == "OR":
position += 1
result |= both()
return result
result = either()
if position != len(tokens):
raise ValueError("unexpected adjacent terms")
return sorted(result)
cases = [
("approval", ["D1", "D2", "D4"]),
('"setup guide"', ["D1", "D5"]),
("tag:setup AND status:published", ["D1", "D5"]),
("approval OR invoice", ["D1", "D2", "D3", "D4", "D6"]),
("approval AND tag:setup", ["D1", "D4"]),
("(approval OR invoice) AND status:published", ["D1", "D2", "D3", "D6"]),
("tag:data AND export", ["D6"]),
("approval AND (tag:setup OR tag:support)", ["D1", "D2", "D4"]),
("tag:unknown", []),
]
for query, expected in cases:
assert find(query) == expected, query
for bad in ["status:archived", "approval NOT invoice", '"unclosed']:
try:
find(bad)
except ValueError:
pass
else:
raise AssertionError("invalid query accepted")
print("9 result cases and 3 invalid-input cases passed; local grammar only")The nine result cases and three invalid-input cases pass for this code. That proves the named fixture agreement, not the behavior of an untested production search service. It deliberately leaves out escaping, fuzzy matching, tokenization languages, authorization and ranking.
Check the final help where the reader uses it
For a real product, obtain the parser configuration and supported interface from its owner. Retain the exact version, enabled fields, defaults, normalization rules and error treatment. Ask a reviewer to run the documented positive and negative examples in the authorized test context and compare actual results.
The documentation defect packet can preserve a mismatch between the help and the search service. Use the product glossary for consistent vocabulary, without assuming a glossary synonym changes the parser’s grammar.
Recheck after parser, index-schema or help-interface changes. Publish when a reader can predict what the supported query means, distinguish no matches from rejected syntax and locate the next useful action. That is a clearer acceptance standard than listing familiar operators and hoping the search box interprets them the same way.
