apache / apache/lucene

Discrepancy in Search Results with spanNearQuery

Open
#14,056 2 comments 0 reactions 0 assignees View on GitHub
type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

### Description

Hello,
I'm contacting you to confirm a discrepancy I've found while using SpanNearQuery.

1. When searching for "applepie bananapie", it doesn't find results in files indexed as "apple pie banana pie"
2. When analyzing "applepie bananapie":
apple:PositionIncrementAttribute.setPositionIncrement(1)
pie:PositionIncrementAttribute.setPositionIncrement(0)
banana:PositionIncrementAttribute.setPositionIncrement(1)
pie:PositionIncrementAttribute.setPositionIncrement(0)
Then searching with inorder spanNear(apple, pie, banana, pie)
3. Expected normal search results for all values below the default of 21
4. No results output
5. Debugging results show:

```
@Override public int endPosition() {
return (position == -1) ? -1 : (position != NO_MORE_POSITIONS) ? position + 1 : NO_MORE_POSITIONS;
}
```
The search stops due to position + 1, resulting in no search results

I'm wondering if there's a special reason for including position + 1. If not, it seems it would be better to remove the "+1" part.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported SpanNearQuery search for "applepie bananapie" against indexed text "apple pie banana pie" and inspect the shown endPosition() implementation. Determine whether position + 1 causes the missing matches, then add regression coverage demonstrating the expected results for the reported span query.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.