Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the UnifiedHighlighter's hasUnrecognizedQuery function processes FunctionQuery the same way as MatchAllDocsQuery and MatchNoDocsQuery queries for performance reasons. #13165

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

vletard
Copy link

@vletard vletard commented Mar 6, 2024

Description

This pull request is a follow up to #12938. I took on the task of complying with @romseygeek's comment on behalf of Lexum.
I also rebased to the latest commit of apache:main.

Let me know if any other adjustment is needed.

@vletard vletard force-pushed the functionquery-as-unrecognizedquery-in-unifiedhighlighter branch from 851b7d2 to 8801851 Compare March 6, 2024 21:55
@@ -1130,7 +1134,16 @@ public boolean acceptField(String field) {
@Override
public void visitLeaf(Query query) {
if (MultiTermHighlighting.canExtractAutomataFromLeafQuery(query) == false) {
if (!(query instanceof MatchAllDocsQuery || query instanceof MatchNoDocsQuery)) {
boolean no_effect_query = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be simpler as QUERIES_WITH_NO_HL_EFFECT.contains(query.getClass())

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you say that there is no need to capture hypothetical subclasses?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MatchAllDocsQuery is already final, but the other two aren't. Maybe this would be better done as a new protected method, isIgnorableQuery(Query q) with a default implementation of instanceof checks, and then if somebody has their own extension (or another query implementation that will do weird things here) they can override the method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just edited my branch with your suggestion.

Copy link

This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution!

@github-actions github-actions bot added the Stale label Mar 24, 2024
@github-actions github-actions bot removed the Stale label Mar 26, 2024
@@ -1130,7 +1137,7 @@ public boolean acceptField(String field) {
@Override
public void visitLeaf(Query query) {
if (MultiTermHighlighting.canExtractAutomataFromLeafQuery(query) == false) {
if (!(query instanceof MatchAllDocsQuery || query instanceof MatchNoDocsQuery)) {
if (!UnifiedHighlighter.this.isIgnorableQuery(query)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test to TestUnifiedHighlighterExtensibility that checks that overrides to isIgnorableQuery work here as well? I think it will, but to be perfectly honest I can never remember the inheritance rules around class-specific this calls...

@romseygeek
Copy link
Contributor

Thanks @vletard! This looks great, I'd just like to add one more test to ensure that inheritance works in the way we expect.

@vletard
Copy link
Author

vletard commented Mar 28, 2024

I added a test in TestUnifiedHighlighterExtensibility, probably too simple for what you asked though.
From my understanding, performing a more realistic test with adequate UH and query setup would require one of the following:

  • cross-package import some code from TestUnifiedHighlighter to TestUnifiedHighlighterExtensibility
  • copy this code instead of importing it (we probably want to avoid this as it would duplicate much of the randomized generation process)
  • create an extensibility test in the uhighlight package instead of uhighlight.visibility

Options 1 and 3 that I tend to prefer would require not-so-light edits, so I'd like your opinion.
What is the expected way to do this in Lucene unit testing?

Thanks!

@vletard vletard force-pushed the functionquery-as-unrecognizedquery-in-unifiedhighlighter branch from fcf3eb6 to 908ac35 Compare March 28, 2024 13:27
Copy link

This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution!

@github-actions github-actions bot added the Stale label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants