apache / lucene

Apache Lucene open-source search software
https://lucene.apache.org/
Apache License 2.0
2.45k stars 973 forks source link

Add method to `Intervals#noIntervals(String reason)` to `Intervals` class #13388

Closed uschindler closed 1 month ago

uschindler commented 1 month ago

Description

Followup of #13385:

While reviewing #13385 I stumbled on the same issue I had several times while building a intervals query parser for patent search (a Solr plugin for a customer). There is no way to get an IntervalsSource that matches no intervals, so it will make one clause of a complex IntervalQuery consisting of serveral clauses be a non-match. One example where I hit this: We expand wildcards and filter some terms from expanding (like adding a limit on number of terms or similar), but when trying to build an empty clause it's impossible.

The easy "workaround" in Lucene/Solr 9.x is to use this class, which is unfortunately pkg private: https://github.com/apache/lucene/blob/1ee4f8a1115d1de623f242014681032d87ed2c1e/lucene/queries/src/java/org/apache/lucene/queries/intervals/NoMatchIntervalsSource.java

To get an instance there's a workaround, but its undocumented: public static IntervalsSource Intervals#atLeast(int minShouldMatch, IntervalsSource... sources). You can misuse it by passing 1 and an empty array: Intervals.atLeast(1)

I wonder how this differs from IntervalBuilder#NO_INTERVALS, which was made public in #13385. The implementations of both classes differ: one returns an iterator, which is empty, the other one returns null.

I'd suggest to merge those implementations and instead of exposing a constant to end user add another static method like Intervals#noIntervals("reason").

We should revert #13385 and prefer a method instead of a constant.

romseygeek commented 1 month ago

I opened #13389