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: ConstantScoreQueryBuilder and Parser #11629

Conversation

cbuescher
Copy link
Member

Moving the query building functionality from the parser to the builders
new toQuery() method analogous to other recent query refactorings.

PR goes agains query-refactoring feature branch.


public static final String NAME = "constant_score";

private final QueryBuilder filterBuilder;
private final QueryBuilder queryBuilder;
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure we want to rename this to queryBuilder. I do see that it is a query and not a filter anymore, but the query is used as a filter, which might be why we left it this way when we removed filters? @jpountz thoughts?

@javanna
Copy link
Member

javanna commented Jun 15, 2015

left a couple of comments, looks good though!

@cbuescher
Copy link
Member Author

Adressed the last two comments, not sure about the queryBuilder/filterBuilder naming thing. Happy to change that back since it's a filter as you said.


@Override
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
Query innerFilter = queryBuilder.toQuery(parseContext);
Copy link
Member

Choose a reason for hiding this comment

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

now you rely on validation right given that queryBuilder can potentially be null but not after we called validate?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I think the null-check for queryBuilder can be dropped because we should catch it eventually with the validation.


@Override
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
Query innerFilter = filterBuilder.toQuery(parseContext);
Copy link
Member

Choose a reason for hiding this comment

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

I have second thoughts about removing the null checks here.... sorry! let's say a java api user creates a new query without a filter, then calls manually toQuery which makes no sense but it is a public method... what do we do? this case won't be covered by our validation framework. Shall we let it throw NPE or handle it gracefully?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I re-added this. Also, since things like `{"constant_score" : { "filer" : {} }}" are currently valid in the DSL, I removed the vaidation check for filterBuilder == null.

@cbuescher
Copy link
Member Author

Revisited null-checks for inner query builder again. It seems that current DSL allows inner empty queries like { "constant_score" : { "filter" : { } } at the moment, so we need to gracefully handle this on all levels. That's why I removed the null-check for inner query builder from validation since it is legal coming from the DSL. We return null from toQuery() in this cases which is consistent with the current behaviour in the old parse() method.

* Test empty "filter" element.
* Current DSL allows inner filter element to be empty, returning a `null` inner filter builder
*/
public void testEmptyFilterElement() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

missing @test just for consistency with existing tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure.

@javanna
Copy link
Member

javanna commented Jun 15, 2015

LGTM

Moving the query building functionality from the parser to the builders
new toQuery() method analogous to other recent query refactorings.

Relates to elastic#10217
Closes elastic#11629
@cbuescher cbuescher force-pushed the feature/query-refactoring-constantscore branch from ddbabdf to 1c0b7b3 Compare June 15, 2015 16:42
@cbuescher
Copy link
Member Author

Final squash and rebase, will merge this then as soon as I ran the tests again another time.

cbuescher added a commit that referenced this pull request Jun 16, 2015
…nstantscore

Query refactoring: ConstantScoreQueryBuilder and Parser
@cbuescher cbuescher merged commit d25acdf into elastic:feature/query-refactoring Jun 16, 2015
@kevinkluge kevinkluge removed the review label Jun 16, 2015
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
Moving the query building functionality from the parser to the builders
new toQuery() method analogous to other recent query refactorings.

Relates to elastic#10217
Closes elastic#11629
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
…ring-constantscore

Query refactoring: ConstantScoreQueryBuilder and Parser
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query Refactoring labels Feb 14, 2018
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