apache / apache/lucene

escape whole word operators (OR, AND, NOT) [LUCENE-6221]

Open
#7,283 0 comments 0 reactions 0 assignees View on GitHub
legacy-jira-priority:Major module:core/queryparser type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

The current QueryParser escape method does not escape whole word operators (OR, AND, NOT):

```Java
public static String escape(String s) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
// These characters are part of the query syntax and must be escaped
if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
|| c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '\~'
|| c == '*' || c == '?' || c == '|' || c == '&' || c == '/') {
sb.append('\\');
}
sb.append(c);
}
return sb.toString();
}
```

It would be better if these words were escaped too.

---
Migrated from [LUCENE-6221](https://issues.apache.org/jira/browse/LUCENE-6221) by Shaun A Elliott

Contributor guide

Open the contributing guide

Research direction

The reported entry point is QueryParser.escape(String); locate its Java source and inspect how whole-word operators are parsed. Confirm the expected escaped representation for OR, AND, and NOT, then verify the change with the relevant existing QueryParser tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.