apache / apache/lucene

Support for a "SpanAndQuery" / "SpanAllNearQuery" [LUCENE-3371]

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

Description

I would like to parse queries like this:

```
a WITHIN 5 WORDS OF (b AND c)
```

This would match cases where both a b span and a c span are within 5 of the same a span.

The existing span query classes do not appear to be capable of doing this no matter how they are combined, although replacing the AND with "WITHIN 10 OF" (general rule is to double the first number) at least ensures that no hits are lost (it just returns too many.)

I'm not sure how the class would work, but it might be like this:

```Java
Query q = new SpanAllNearQuery(a, new SpanQuery[] { b, c }, 5, false);
```

The difference from SpanNearQuery is that SpanNearQuery considers the entire collection of terms as a single set to be found near each other, whereas this query would consider each of the terms in the array relative to the first.

---
Migrated from [LUCENE-3371](https://issues.apache.org/jira/browse/LUCENE-3371) by Trejkaz, updated Sep 07 2016

Contributor guide

Open the contributing guide

Research direction

Start by reading SpanNearQuery and the existing span query classes to determine how span relationships are represented. Define how SpanAllNearQuery should evaluate each term relative to the first span, then verify that the example query matches the described cases without the false positives introduced by doubling the distance.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.