vismaytiwari commented on PR #16382:
URL: https://github.com/apache/lucene/pull/16382#issuecomment-4946509281

   I like that direction — if it also collapses `.*.*` in regex it stops being 
a wildcard-only thing and becomes a general optimization, which is a better 
story anyway.
   
   Two things I hit when I looked at doing it down in the automaton layer, 
though:
   
   It's only safe for the total automaton — `Σ*·Σ* = Σ*` is really the only 
reason we can drop one, since `A·A ≠ A` for anything else. So it can't be a 
generic "skip a repeated operand" in `concatenate`; it has to specifically know 
the operand is total.
   
   And detecting that cheaply is the catch. `makeAnyString()` returns a fresh 
automaton on each call, so there's no identity check to lean on, and regex `.*` 
is `repeat(makeAnyChar())` — a different shape again. `Operations.isTotal` 
exists, but it expects a minimized automaton, so running it on the raw 
sub-automata mid-`concatenate` is both unreliable (the regex `.*` isn't 
minimized at that point) and adds an O(states) scan to a very hot path just to 
catch degenerate input.
   
   So what I'd suggest instead is keeping it intent-driven rather than 
inspecting the automaton after the fact: the builders already know when they're 
emitting an anyString — wildcard does, and regex's repeat-of-`.` does too — so 
a small shared helper that skips appending an anyString when the previous 
segment was already one gives the same generalization (`.*.*` included), drops 
the boolean-everywhere bit you mentioned, and stays zero-cost for ordinary 
patterns since there's no isTotal on the common path.
   
   Happy to prototype that and confirm `**` and `.*.*` both collapse and stay 
language-equal with sameLanguage. Would you want it on this PR, or kept 
separate so this one can land as-is?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to