-
Notifications
You must be signed in to change notification settings - Fork 844
SOLR-13764: Introduce IntervalsQParserPlugin #4582
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
Open
mkhludnev
wants to merge
49
commits into
apache:main
Choose a base branch
from
mkhludnev:copilot/add-json-queries-key
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
007d5a8
Introduce json_queries key in JSON DSL, pass-through to req.getJSON()
Copilot 45aa9cb
Introduce IntervalsQParserPlugin ({!intervals json_query=...}), retur…
Copilot f64ca06
Improve TestIntervalsQParserPlugin: add json_queries pass-through test
Copilot a77c3eb
Implement IntervalsQParserPlugin term interval query from JSON DSL
Copilot 0c356b3
Implement OpenSearch-style intervals JSON rule parser
Copilot d89632c
Fix intervals DSL parser warnings and finalize validation
Copilot 0256e7a
Clarify fuzzy expansion constant in intervals parser
Copilot c14938f
Add interval rule support: term, phrase, regexp, range, max_width, ex…
Copilot b4e4394
Add Intervals Query Parser documentation page and references
Copilot f05b945
Fix spelling: analyse -> analyze in intervals-query-parser.adoc
Copilot ef325c3
Add SOLR-13764 changelog fragment
Copilot ac0e13c
fix changelog
mkhludnev 671c3f9
Support df local/query param as field for IntervalsQParser; update tests
Copilot 9e2c4cf
Update intervals-query-parser.adoc to document both df and legacy que…
Copilot a48de05
Remove legacy format support from IntervalsQParserPlugin
Copilot 5631943
Rename SOLR-13764-intervals-query-parser-reference-guide.yml to SOLR-…
mkhludnev 95f95ad
Change type to 'added' for intervals query parser
mkhludnev 6bfa9aa
Revise intervals query parser documentation
mkhludnev e5e1dd7
Add Lucene intervals package link to intervals-query-parser.adoc
Copilot 13e9309
Fix spotless formatting in TestIntervalsQParserPlugin
Copilot d25c401
Fix the guide
mkhludnev 1476ffc
Change source format from json to text in intervals query
mkhludnev fe55aad
Add intervals vs xmlparser nested query comparison test
Copilot a6f8438
Clarify JSON DSL reference in intervals query parser
mkhludnev 9e558f7
Fix typo in author URL field
mkhludnev 1be68da
Fix tidy and checkSiteLinks CI failures
Copilot dbf88de
Add DistributedQParserTest: cloud-based distributed search test for l…
Copilot 9ad5c02
Add testIntervalsQParser to DistributedQParserTest
Copilot cf16eaa
fix: reformat DistributedQParserTest.java per spotless rules
Copilot 5d928f4
Fix Spotless formatting violation in DistributedQParserTest.java
Copilot 0b3b44f
Potential fix for pull request finding
mkhludnev 19b5262
Apply suggestions from code review
mkhludnev 65dd5f9
multiterm analyzer and QueryEqualityTest
mkhludnev 4917c07
fix tests
mkhludnev 966c705
review
mkhludnev 5055635
Delete solr/.vscode/settings.json
mkhludnev 0b589ae
fix test compile
mkhludnev 70645d0
check prefix len
mkhludnev f7e7ac0
change syntax to {!intervals df=title}$foobar
mkhludnev 422b46f
strict field check
mkhludnev 752d5b9
assertJQ
mkhludnev 1343572
tiding manually
mkhludnev bcc0462
tidyng spaces. dunno why
mkhludnev 82fe732
testing pure json requests
mkhludnev 53f0147
wipe settings
mkhludnev 25239fe
add vscode to gitignore
mkhludnev 0a85931
format
mkhludnev 1b86d60
review suggestions
mkhludnev 045c0fe
forbiddenapi
mkhludnev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
changelog/unreleased/SOLR-13764-intervals-query-parser.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc | ||
| title: Add Intervals Query Parser | ||
| type: added | ||
| authors: | ||
| - name: Mikhail Khludnev | ||
| nick: mkhludnev | ||
| url: https://home.apache.org/phonebook.html?uid=mkhl | ||
| links: | ||
| - name: SOLR-13764 | ||
| url: https://issues.apache.org/jira/browse/SOLR-13764 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
704 changes: 704 additions & 0 deletions
704
solr/core/src/java/org/apache/solr/search/IntervalsQParserPlugin.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
solr/core/src/test/org/apache/solr/search/DistributedQParserTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.solr.search; | ||
|
|
||
| import org.apache.solr.client.solrj.request.CollectionAdminRequest; | ||
| import org.apache.solr.client.solrj.request.QueryRequest; | ||
| import org.apache.solr.client.solrj.request.UpdateRequest; | ||
| import org.apache.solr.client.solrj.request.json.DirectJsonQueryRequest; | ||
| import org.apache.solr.client.solrj.response.QueryResponse; | ||
| import org.apache.solr.cloud.SolrCloudTestCase; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Distributed search tests for the standard query parsers: {@code lucene}, {@code dismax}, {@code | ||
| * edismax}, and {@code intervals}. | ||
| */ | ||
| public class DistributedQParserTest extends SolrCloudTestCase { | ||
|
|
||
| private static final String COLLECTION = "distributed-qparser"; | ||
|
|
||
| @BeforeClass | ||
| public static void setupCluster() throws Exception { | ||
| configureCluster(2).addConfig("conf", configset("cloud-dynamic")).configure(); | ||
|
|
||
| CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1) | ||
| .process(cluster.getSolrClient()); | ||
| cluster.waitForActiveCollection(COLLECTION, 2, 2); | ||
|
|
||
| new UpdateRequest() | ||
| .add(sdoc("id", "1", "subject", "quick brown fox")) | ||
| .add(sdoc("id", "2", "subject", "lazy brown dog")) | ||
| .add(sdoc("id", "3", "subject", "quick red dog")) | ||
| .add(sdoc("id", "4", "subject", "slow green cat")) | ||
| .commit(cluster.getSolrClient(), COLLECTION); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLuceneQParser() throws Exception { | ||
| QueryResponse response = | ||
| new QueryRequest(params("q", "subject:quick", "defType", "lucene", "fl", "id")) | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(2, response.getResults().getNumFound()); | ||
|
|
||
| response = | ||
| new QueryRequest(params("q", "subject:brown", "defType", "lucene", "fl", "id")) | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(2, response.getResults().getNumFound()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDismaxQParser() throws Exception { | ||
| QueryResponse response = | ||
| new QueryRequest(params("q", "quick", "defType", "dismax", "qf", "subject", "fl", "id")) | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(2, response.getResults().getNumFound()); | ||
|
|
||
| response = | ||
| new QueryRequest(params("q", "brown dog", "defType", "dismax", "qf", "subject", "fl", "id")) | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(3, response.getResults().getNumFound()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEdismaxQParser() throws Exception { | ||
| QueryResponse response = | ||
| new QueryRequest(params("q", "quick", "defType", "edismax", "qf", "subject", "fl", "id")) | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(2, response.getResults().getNumFound()); | ||
|
|
||
| response = | ||
| new QueryRequest( | ||
| params("q", "brown dog", "defType", "edismax", "qf", "subject", "fl", "id")) | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(3, response.getResults().getNumFound()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIntervalsQParser() throws Exception { | ||
| // match rule: "quick" appears in docs 1 ("quick brown fox") and 3 ("quick red dog") | ||
| String jsonQueries = | ||
| "'q1': {'match': {'query': 'quick'}}" | ||
| + (random().nextBoolean() ? ", 'ignore': {'match': {'query': 'lazy'}}" : ""); | ||
| QueryResponse response = | ||
| new DirectJsonQueryRequest( | ||
| "{" | ||
| + "'query': {intervals: {df: subject, query: $q1}}," | ||
| + "'json_queries': {" | ||
| + jsonQueries | ||
| + "}," | ||
| + "'fields': 'id'" | ||
| + "}") | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(2, response.getResults().getNumFound()); | ||
|
|
||
| // a distinct match rule: "lazy" appears only in doc 2 ("lazy brown dog") — confirm the | ||
| // result differs from the "quick" query above | ||
| jsonQueries = | ||
| "'q1': {'match': {'query': 'lazy'}}" | ||
| + (random().nextBoolean() ? ", 'ignore': {'match': {'query': 'quick'}}" : ""); | ||
| QueryResponse lazyResponse = | ||
| new DirectJsonQueryRequest( | ||
| "{" | ||
| + "'query': {intervals: {df: subject, query: $q1}}," | ||
| + "'json_queries': {" | ||
| + jsonQueries | ||
| + "}," | ||
| + "'fields': 'id'" | ||
| + "}") | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(1, lazyResponse.getResults().getNumFound()); | ||
| assertNotEquals(response.getResults().getNumFound(), lazyResponse.getResults().getNumFound()); | ||
|
|
||
| // all_of ordered: "quick" then "fox" — only doc 1 ("quick brown fox") matches | ||
| response = | ||
| new DirectJsonQueryRequest( | ||
| "{" | ||
| + "'query': {intervals: {df: subject, query: $q1}}," | ||
| + "'json_queries': {'q1': {'all_of': {'ordered': true," | ||
| + "'intervals': [{'match': {'query': 'quick'}},{'match': {'query': 'fox'}}]}}}," | ||
| + "'fields': 'id'" | ||
| + "}") | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(1, response.getResults().getNumFound()); | ||
|
|
||
| // union of two top-level interval queries: "quick" (docs 1, 3) or "lazy" (doc 2) — three | ||
| // docs match | ||
| response = | ||
| new DirectJsonQueryRequest( | ||
| "{" | ||
| + "'query': {'bool': {'should': [" | ||
| + "{intervals: {df: subject, query: $q1}}," | ||
| + "{intervals: {df: subject, query: $q2}}]}}," | ||
| + "'json_queries': {'q1': {'match': {'query': 'quick'}}," | ||
| + "'q2': {'match': {'query': 'lazy'}}}," | ||
| + "'fields': 'id'" | ||
| + "}") | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(3, response.getResults().getNumFound()); | ||
|
|
||
| // intersection of two top-level interval queries: "quick" (docs 1, 3) and "brown" | ||
| // (docs 1, 2) — only doc 1 has both terms | ||
| response = | ||
| new DirectJsonQueryRequest( | ||
| "{" | ||
| + "'query': {'bool': {'must': [" | ||
| + " {intervals: {df: subject, query: $q1}}," | ||
| + " {intervals: { query: $q2}}" | ||
| + "]}}," | ||
| + "'json_queries': {'q1': {'match': {'query': 'quick'}}," | ||
| + "'q2': {'match': {'query': 'brown'}}}," | ||
| + "'fields': 'id'," | ||
| + "params:{df: subject}" | ||
| + "}") | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(1, response.getResults().getNumFound()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have this... shouldn't this be only for intervals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if the intent is testing distributed... well we have a whole test framework for that which is quite good:
BaseDistributedSearchTestCase. Doesn't even require SolrCloud!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afiak SolrCloudTestCase is rather faster and convenient. It's a little bit redundant for local-only QP, but there's a https://github.com/apache/solr/pull/4582#issuecomment-4861727946 regarding transferring new JSON request entries. I've decided to double check.
We cad drop it if you wish.