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: SpanMultiTermQueryBuilder and Parser #12182

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.

Relates to #10217

protected Query doToQuery(QueryParseContext parseContext) throws IOException {
Query subQuery = multiTermQueryBuilder.toQuery(parseContext);
if (subQuery instanceof DateFieldMapper.DateFieldType.LateParsingQuery) {
subQuery = ((DateFieldMapper.DateFieldType.LateParsingQuery) subQuery).rewrite(null);
Copy link
Member

Choose a reason for hiding this comment

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

add a simple comment, just so we know why we do this and why we live with that although it sucks? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I was going to say in #12123 that this workaround means SpanMultiTermQuery with this particular type of inner query will not work with now then, but I added it here to make our tests work for now. We can track that particular issue in #12123. Wonder if we should add this early rewrite on master as well as I already brought it up there? Need to ask Martjin about it, I guess.

Copy link
Member

Choose a reason for hiding this comment

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

not sure what we should do in master, seems like things are broken either way. This is fine in our branch cause that's how we move forward for now, till we have found a better solution.

@javanna
Copy link
Member

javanna commented Jul 10, 2015

left a minor comment, LGTM though

@cbuescher
Copy link
Member Author

Thanks, I still wonder if it makes sense at all to allow Date/Numeric range queries inside a SpanMultiTerm query or if we should simply not allow this case (see #12123 (comment)). In this case I would rather change the test slightly here than have this rewrite.

@cbuescher
Copy link
Member Author

@javanna removed the check for the LateParsingQuery case, Date Ranges will (and should) not work inside this type of query, so cast will not work in this case. Only problem now is we don't detect this until we generate the lucene query, since we need to check the field mapping if it is a Range query (possibly also for other nested MultiTermQueries like Fuzzy/Regex/... where field doesn't have positions). I don't know if we can do this already in the parser (coordinating node) later, for now I changed the test setup so it only uses String ranges for the nested queries.

@cbuescher cbuescher force-pushed the feature/query-refactoring-spanmultiterm branch 2 times, most recently from 43f30a5 to 6c62d18 Compare July 10, 2015 15:39
@cbuescher
Copy link
Member Author

Added type check for inner query and test that we throw UnsupportedOperationException instead of ClassCastException when trying to use nested query that doesn't resolve to MultiTermQuery.

@cbuescher cbuescher force-pushed the feature/query-refactoring-spanmultiterm branch from 6c62d18 to bfcba0e Compare July 20, 2015 13:21
@cbuescher
Copy link
Member Author

Adressed the last comment regarding error message and rebased on master.

@@ -42,6 +58,42 @@ protected void doXContent(XContentBuilder builder, Params params)
}

@Override
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
Query subQuery = multiTermQueryBuilder.toQuery(parseContext);
if (!(subQuery instanceof MultiTermQuery)) {
Copy link
Member

Choose a reason for hiding this comment

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

Simon would say replace with == false ;)

@cbuescher
Copy link
Member Author

Added changes considering last round of comments.

@cbuescher
Copy link
Member Author

Removed calling RangeQueryBuilder from RandomQueryBuilder utility class, instead creating simple string field range query there now.

}
if (randomBoolean()) {
query.format("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
;
Copy link
Member

Choose a reason for hiding this comment

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

one too many ;

@cbuescher cbuescher force-pushed the feature/query-refactoring-spanmultiterm branch from c15e8a6 to 24d1603 Compare July 21, 2015 15:48
RangeQueryBuilder query = new RangeQueryBuilder(BaseQueryTestCase.STRING_FIELD_NAME);
query.from("a"+RandomStrings.randomAsciiOfLengthBetween(r, 1, 10));
query.to("z"+RandomStrings.randomAsciiOfLengthBetween(r, 1, 10));
return query;
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should call this method createRangeStringQuery instead, and when we add a broader method for multi term queries we call it? so we can also call it where we duplicate its code currently?

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, can do, but I was trying to avoid the RangeQueryBuilderTest calling RandomQueryBuilder or did I missunderstand this previously? So the individual test should be able to call the utility class but not the other way round? Cause we already do so in RandomQueryBuilder#createQuery()

Copy link
Member

Choose a reason for hiding this comment

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

yea I know we already do that, and I don't like it very much... I would try not to have the utility class calling test classes if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this but having the RangeQueryBuilderTest setup calling the utility class just for one of the three cases covered there looks odd. Too much indirection just to save three lines, if I'm honest. Would like to leave it like this for now, so only non-leaf queries need to use RandomQueryBuilder for nested queries, and try to extend this method with other refactored multi term queries later.

Copy link
Member

Choose a reason for hiding this comment

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

alrighty, no problem

@cbuescher
Copy link
Member Author

Last minor cleanup, rebased once again on current

@javanna
Copy link
Member

javanna commented Jul 21, 2015

did another round, left a few comments

@cbuescher cbuescher closed this Jul 21, 2015
@cbuescher
Copy link
Member Author

Sorry, didn't mean to close this.

@cbuescher cbuescher reopened this Jul 21, 2015
@cbuescher
Copy link
Member Author

Added some clarifying comment around edge test case.

@javanna
Copy link
Member

javanna commented Jul 22, 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#12182
@cbuescher cbuescher force-pushed the feature/query-refactoring-spanmultiterm branch from 969644a to 966c02b Compare July 22, 2015 08:36
cbuescher added a commit that referenced this pull request Jul 22, 2015
…anmultiterm

Query refactoring: SpanMultiTermQueryBuilder and Parser
@cbuescher cbuescher merged commit 1a09633 into elastic:feature/query-refactoring Jul 22, 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#12182
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
…ring-spanmultiterm

Query refactoring: SpanMultiTermQueryBuilder and Parser
@cbuescher cbuescher deleted the feature/query-refactoring-spanmultiterm branch March 11, 2016 11:51
@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.

3 participants