apache / apache/lucene

Surround Query Parser NOT operator is binary [LUCENE-9008]

Open
#10,051 0 comments 0 reactions 0 assignees View on GitHub
affects-version:8.3 legacy-jira-label:documentation legacy-jira-priority:Major module:core/queryparser type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

The following query works in the surround query parser (tested via solr):

```java
foo NOT bar
```

However despite the Solr ref guide specifically noting that "NOT" is unary, the following throw parsing exceptions (also tested in solr):

```java
foo AND NOT bar
```

```java
NOT bar AND foo
```

additionally the right hand side of NOT requires parenthesis for fielded terms...

```java
fizz NOT game:buzz 
```

throws an exception whereas

```java
fizz NOT (game:buzz) 
```

keeps the parser happy.

The binary syntax may be intentional and certainly has a nice readability. The parenthesis around fielded stuff seems arbitrary and just irritating. However, this parser has been around for a long time so we probably won't want to go changing it fundamentally.

I suggest that this ticket should provide some docs clarifying at least this surprising syntax in the lucene package javadoc, the solr parser factory class javadocs and the solr ref guide docs () should be corrected and expanded to at least clarify this surprising and quirky binary NOT syntax.

---
Migrated from [LUCENE-9008](https://issues.apache.org/jira/browse/LUCENE-9008) by Gus Heck (@gus-asf)

Contributor guide

Open the contributing guide

Research direction

Review the Surround query parser examples in the issue, then locate the Lucene package javadocs, the Solr parser factory class javadocs, and the Solr reference guide section linked in the report. Clarify the binary NOT syntax, the unary-looking forms that fail, and the parenthesis requirement for fielded terms; done means all three documentation locations consistently explain the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation, search
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.