**Instructions for Processing Search Queries** When constructing search queries, it's important to follow certain guidelines to ensure your queries are processed correctly and yield the desired results. Below are the detailed instructions on how to build and format your queries: --- 1. **Single Terms Remain Unchanged** - **What to do**: If your query is a single word or term, it remains as is. - **Example**: - Input: `hello` - Processed Output: `hello` 2. **Multiple Terms Without Operators Are Treated as Exact Phrases** - **What to do**: When you have multiple words without any operators (`AND`, `OR`), group them into an exact phrase by enclosing them in double quotes. - **Example**: - Input: `hello world` - Processed Output: `"hello world"` 3. **Avoid Explicit `AND` Operators** - **What to do**: Do not use the `AND` operator explicitly. Instead, simply list the terms separated by spaces. The `AND` is implied between them. - **Correct**: - Input: `apple banana` - Processed Output: `apple banana` - **Incorrect**: - Input: `apple AND banana` - Issue: The explicit `AND` should be omitted. 4. **Use Parentheses with `OR` Operators** - **What to do**: When using the `OR` operator, enclose the entire `OR` expression within parentheses. - **Examples**: - Input: `apple OR banana` - Processed Output: `(apple OR banana)` - Input: `apple OR banana OR cherry` - Processed Output: `(apple OR banana OR cherry)` - **Note**: If your query contains only a single `OR`, it should still be enclosed in parentheses. 5. **Combine Terms with Implicit `AND`** - **What to do**: When combining terms or phrases that should all be included (logical `AND`), simply list them separated by spaces. - **Example**: - Input: `apple banana cherry` - Processed Output: `apple banana cherry` 6. **Handling Combined `AND` and `OR` Operators** - **What to do**: When your query includes both `AND` (implicit) and `OR` operators, use parentheses to group `OR` expressions and list `AND` terms outside. - **Example**: - Input: `apple OR banana AND cherry` - Processing Steps: 1. Remove explicit `AND`: `apple OR banana cherry` 2. Insert implicit `AND`: `apple OR banana AND cherry` 3. Enclose `OR` expression in parentheses: `(apple OR banana) cherry` - Processed Output: `(apple OR banana) cherry` 7. **Avoid Parentheses That Do Not Contain `OR` Operators** - **What to do**: Do not use parentheses to group terms unless they contain `OR` operators. - **Incorrect**: - Input: `(apple banana)` - Issue: Parentheses are unnecessary here. - **Correct**: - Input: `apple banana` - Processed Output: `apple banana` 8. **Use Double Quotes for Exact Phrases** - **What to do**: Enclose exact phrases in double quotes to search for the exact sequence of words. - **Examples**: - Input: `"cherry pie"` - Processed Output: `"cherry pie"` - Input: `apple "banana split" cherry` - Processed Output: `apple "banana split" cherry` - **Note**: Do not use quotes for single words. 9. **Simplify Nested Parentheses** - **What to do**: If your query has unnecessary nested parentheses, simplify them. - **Example**: - Input: `((apple))` - Processed Output: `apple` 10. **Avoid Unsupported Structures** - **What to do**: Do not create queries with nested `OR` statements joined by implied `AND` operators at the same nesting level. - **Unsupported**: - Input: `(apple OR banana) (cherry OR date)` - Issue: This structure implies an `AND` between two `OR` expressions without proper grouping. - **Supported Alternative**: - Input: `(apple OR banana) AND (cherry OR date)` - Processed Output: `(apple OR banana) (cherry OR date)` 11. **Ensure Balanced Parentheses** - **What to do**: Make sure all opening parentheses `(` have corresponding closing parentheses `)`. - **Error Cases**: - Input: `(apple OR banana` - Issue: Unmatched opening parenthesis. - Input: `apple OR banana)` - Issue: Unmatched closing parenthesis. 12. **Error Handling for Invalid Queries** - **Query Cannot Be Only an Operator** - Input: `AND` - Output: `Error: Query cannot be only an operator.` - **Empty Query** - Input: ` ` - Output: `Error: Query became empty or invalid.` 13. **Processing Steps to Standardize Queries** - **Start by Removing Explicit `AND`s** - Replace all instances of `AND` with spaces. - **Trim Extra Spaces** - Remove any extra spaces to avoid unintended errors. - **Insert Implicit `AND`s Where Necessary** - Implicit `AND`s are understood between adjacent terms not separated by `OR`. - **Enclose `OR` Expressions in Parentheses** - Group all `OR` expressions within parentheses. - **Group Adjacent Terms into Phrases** - Adjacent terms without operators are combined into phrases. - Use double quotes for exact phrases containing multiple words. - **Simplify Parentheses** - Remove unnecessary or redundant parentheses. 14. **Examples to Illustrate the Guidelines** - **Example 1: Simple `OR` Operator** - Input: `apple OR banana` - Processing: - Enclose `OR` expression in parentheses: `(apple OR banana)` - Output: `(apple OR banana)` - **Example 2: Multiple `OR` Operators** - Input: `apple OR banana OR cherry` - Processing: - Enclose `OR` expression in parentheses: `(apple OR banana OR cherry)` - Output: `(apple OR banana OR cherry)` - **Example 3: Combining Terms with Implicit `AND`** - Input: `apple banana cherry` - Processing: - Simply list terms separated by spaces. - Output: `apple banana cherry` - **Example 4: Mixed `AND` and `OR` Operators** - Input: `apple OR banana AND cherry` - Processing: 1. Remove explicit `AND`: `apple OR banana cherry` 2. Insert implicit `AND`: `apple OR banana cherry` 3. Enclose `OR` expression: `(apple OR banana) cherry` - Output: `(apple OR banana) cherry` - **Example 5: Exact Phrase with `OR` Operator** - Input: `"apple pie" OR banana` - Processing: - Recognize exact phrase in quotes. - Enclose `OR` expression in parentheses: `("apple pie" OR banana)` - Output: `("apple pie" OR banana)` - **Example 6: Simplifying Parentheses** - Input: `((apple))` - Processing: - Remove unnecessary parentheses. - Output: `apple` --- **Additional Notes:** - **Implicit `AND` Between Terms**: - When two terms are adjacent without an operator, an implicit `AND` is assumed. - Example: - Input: `apple banana` - Processed as: `apple AND banana` (but you should not write `AND` explicitly) - **Operators are Case-Insensitive**: - The keywords `AND` and `OR` are not case-sensitive. - Example: - Input: `apple or banana` - Equivalent to: `apple OR banana` - **Avoid Misuse of Quotes**: - Do not enclose single words in quotes unless they are part of an exact phrase. - Incorrect: `"apple"` - Correct: `apple` - **Parentheses Usage**: - Only use parentheses when grouping terms with `OR`. - Do not use parentheses to group terms with implicit `AND`. - **Complex Queries**: - For queries involving multiple `OR` expressions combined with implicit `AND`s, ensure each `OR` group is properly enclosed in parentheses. - Example: - Input: `apple OR banana apple OR cherry` - Corrected Input: `(apple OR banana) (apple OR cherry)` - Processed Output: `(apple OR banana) (apple OR cherry)` --- By following these instructions, your search queries will be properly formatted, ensuring accurate and expected search results. Remember: - **Simplify Your Queries**: Remove unnecessary operators and punctuation. - **Group with Parentheses**: Use parentheses to group `OR` conditions. - **Use Quotes for Exact Phrases**: Enclose multi-word exact phrases in double quotes. - **Implicit `AND`**: Simply list terms separated by spaces to imply `AND`. These guidelines help standardize your queries and make them easier to process and understand. Highlight keyword match in article boxes