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

Query Refactoring: Moving parser NAME constant to corresponding query builder #11178

Conversation

cbuescher
Copy link
Member

As part of the query refactoring, this PR moves the NAME field that currently identifies each query parser to the corresponding query builder. The reason for this, as discussed in #11121 (comment), is that we need still need to be able to link parser and builder implementations, but that the query builder is independent of the parser (queries don't necessarily need to be coverted to XContent any more). Builders don't need to know about their parsers, but parsers need to be linked to their respective builders.

This change does the following:

  • move the NAME constants from the parsers to the builders, making sure they are unique
  • rename the existing getParserName() in the Builder classes to queryId(), returning the unique NAME constant. This is now public so we can retrieve query name when coding against the QueryBuilder abstract class
  • modify the names() method in the parsers so it contains at least one member that is the query id

@cbuescher
Copy link
Member Author

As a further explanation: there were two cases where the 1:1 mapping from parsers to builders was not completely clear:

  • FQueryFilterParser didn't have a corresponding Builder class, instead queries with the "fquery" id were build in the (already deprecated) QueryFilterBuilder. To make this link clearer I introduced a new FQueryFilterParser that extends QueryFilterBuilder but otherwise shares the existing code there, just carries the moved NAME constant
  • TermsLookupQueryBuilder was a builder without a correspondingly named parser. It used the TermsQueryParser and so also its NAME. To have a unique id for each builder I introduced the new name "terms_lookup"` here and added this to the names() array in the TermsQueryParser. Because all these names are used to register the parsers this will link the builder to that parser now.

protected String parserName() {
return BoolQueryParser.NAME;
public String queryId() {
return BoolQueryBuilder.NAME;
Copy link
Member

Choose a reason for hiding this comment

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

in all the builders, you can remove the class name, just return NAME is enough.

@javanna
Copy link
Member

javanna commented May 15, 2015

good change! left a few comments

@cbuescher cbuescher force-pushed the feature/query-refactoring-movename branch from 127195f to 59305dc Compare May 21, 2015 16:30
@cbuescher
Copy link
Member Author

I rebased this PR after recent changes on feature branch and addressed the two comments above. The two main changes here:

  • TermsQueryBuilder covers all of former TermsLookupBuilder functionality, leaving deprecated Stub class, leading to a 1:1 relation between Builder and Parser here.
  • FQueryFilterBuilder directly extends QueryBuilder, moved cases where queryName is set out of QueryFilterBuilder.

builder.field("_name", queryName);
}
builder.endObject();
}
Copy link
Member

Choose a reason for hiding this comment

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

I thought we discussed (missing bits in the review comments) to leave this as-is and to not introduce FQueryFilterBuilder as it is not needed. This change breaks bw compatibility as you pointed out, thus we should keep this class as-is, and if we do that it makes little sense to introduce a deprecated additional FQueryFilterBuilder. The idea is that two parsers sharing the same builder should not be a problem....unless I am missing something.

Copy link
Member Author

Choose a reason for hiding this comment

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

All right, will remove FQueryFilterBuilder then, put the NAME of the extra FQueryFilterParser somewhere else in the QueryFilterBuilder then.

@javanna
Copy link
Member

javanna commented May 21, 2015

I did another review round, thanks @cbuescher

@cbuescher
Copy link
Member Author

@javanna I had another round, mostly reverting some of the changes in my prevoius commits.

if (queryName != null) {
builder.field("_name", queryName);
builder.field("_name", queryName);
Copy link
Member

Choose a reason for hiding this comment

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

too many tabs?

@javanna
Copy link
Member

javanna commented May 22, 2015

left a super minor comment on indentation, LGTM besides that

… builder

As part of the query refactoring, this PR moves the NAME field that currently identifies each query parser to the
corresponding query builder. The reason for this, as discussed in elastic#11121 (comment), is that we need still need to
be able to link parser and builder implementations, but that the query builder is independent of the parser (queries
don't necessarily need to be coverted to XContent any more). Builders don't need to know about their parsers, but
parsers need to be linked to their respective builders.

Closes elastic#11178
@cbuescher cbuescher force-pushed the feature/query-refactoring-movename branch from f5a4e74 to 283fe90 Compare May 22, 2015 12:07
cbuescher added a commit that referenced this pull request May 22, 2015
…vename

Query Refactoring: Moving parser NAME constant to corresponding query builder
@cbuescher cbuescher merged commit 1c60436 into elastic:feature/query-refactoring May 22, 2015
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
… builder

As part of the query refactoring, this PR moves the NAME field that currently identifies each query parser to the
corresponding query builder. The reason for this, as discussed in elastic#11121 (comment), is that we need still need to
be able to link parser and builder implementations, but that the query builder is independent of the parser (queries
don't necessarily need to be coverted to XContent any more). Builders don't need to know about their parsers, but
parsers need to be linked to their respective builders.

Closes elastic#11178
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
…ring-movename

Query Refactoring: Moving parser NAME constant to corresponding query builder
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query Refactoring labels Feb 14, 2018
@cbuescher cbuescher deleted the feature/query-refactoring-movename branch March 20, 2024 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants