-
Notifications
You must be signed in to change notification settings - Fork 841
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
45
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.
+2,257
−0
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
3a52030
Introduce json_queries key in JSON DSL, pass-through to req.getJSON()
Copilot d13108e
Introduce IntervalsQParserPlugin ({!intervals json_query=...}), retur…
Copilot de1cf82
Improve TestIntervalsQParserPlugin: add json_queries pass-through test
Copilot 5e892d5
Implement IntervalsQParserPlugin term interval query from JSON DSL
Copilot 643c95e
Implement OpenSearch-style intervals JSON rule parser
Copilot a402594
Fix intervals DSL parser warnings and finalize validation
Copilot e0841a3
Clarify fuzzy expansion constant in intervals parser
Copilot c76d287
Add interval rule support: term, phrase, regexp, range, max_width, ex…
Copilot 1d9f1e8
Add Intervals Query Parser documentation page and references
Copilot 363eb9e
Fix spelling: analyse -> analyze in intervals-query-parser.adoc
Copilot e2047c3
Add SOLR-13764 changelog fragment
Copilot 655b511
fix changelog
mkhludnev 53c8730
Support df local/query param as field for IntervalsQParser; update tests
Copilot d42e02c
Update intervals-query-parser.adoc to document both df and legacy que…
Copilot 81b3464
Remove legacy format support from IntervalsQParserPlugin
Copilot 92ec988
Rename SOLR-13764-intervals-query-parser-reference-guide.yml to SOLR-…
mkhludnev 73e50a9
Change type to 'added' for intervals query parser
mkhludnev a45e9f4
Revise intervals query parser documentation
mkhludnev b9b9846
Add Lucene intervals package link to intervals-query-parser.adoc
Copilot 4a7e58f
Fix spotless formatting in TestIntervalsQParserPlugin
Copilot 168ff13
Fix the guide
mkhludnev d644ea9
Change source format from json to text in intervals query
mkhludnev a9a1007
Add intervals vs xmlparser nested query comparison test
Copilot 6d7d239
Clarify JSON DSL reference in intervals query parser
mkhludnev 5755f59
Fix typo in author URL field
mkhludnev 5f29a8f
Fix tidy and checkSiteLinks CI failures
Copilot 003d263
Add DistributedQParserTest: cloud-based distributed search test for l…
Copilot f8652de
Add testIntervalsQParser to DistributedQParserTest
Copilot 88e4c3b
fix: reformat DistributedQParserTest.java per spotless rules
Copilot b7e85da
Merge pull request #3 from mkhludnev/copilot/fix-failing-github-actio…
mkhludnev 223440d
Fix Spotless formatting violation in DistributedQParserTest.java
Copilot 11ccd1e
Potential fix for pull request finding
mkhludnev ce87c95
Apply suggestions from code review
mkhludnev 6f2f3ce
multiterm analyzer and QueryEqualityTest
mkhludnev 002e8a4
Merge pull request #4 from mkhludnev/add-json-queries-key
mkhludnev a61b90f
fix tests
mkhludnev 2f3141b
review
mkhludnev da96d7c
Delete solr/.vscode/settings.json
mkhludnev 50130b5
fix test compile
mkhludnev abde6b2
check prefix len
mkhludnev e52214d
change syntax to {!intervals df=title}$foobar
mkhludnev dde6a64
strict field check
mkhludnev c1b4635
assertJQ
mkhludnev c9ccd8a
tiding manually
mkhludnev bac1035
tidyng spaces. dunno why
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,3 +24,4 @@ | |
|
|
||
| lib/ | ||
| test-lib/ | ||
| .vscode/ | ||
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
699 changes: 699 additions & 0 deletions
699
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
166 changes: 166 additions & 0 deletions
166
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,166 @@ | ||
| /* | ||
| * 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.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") | ||
| QueryResponse response = | ||
| new QueryRequest( | ||
| params( | ||
| "q", | ||
| "{!intervals df=subject}$q1", | ||
| "json", | ||
| "{json_queries:{q1:{match:{query:quick}}" | ||
| + (random().nextBoolean() ? ",ignore:{match:{query:lazy}}}}" : "}}"), | ||
| "fl", | ||
| "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 | ||
| QueryResponse lazyResponse = | ||
| new QueryRequest( | ||
| params( | ||
| "q", | ||
| "{!intervals df=subject}$q1", | ||
| "json", | ||
| "{json_queries:{q1:{match:{query:lazy}}" | ||
| + (random().nextBoolean() ? ",ignore:{match:{query:quick}}}}" : "}}"), | ||
| "fl", | ||
| "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 QueryRequest( | ||
| params( | ||
| "q", | ||
| "{!intervals df=subject}$q1", | ||
| "json", | ||
| "{json_queries:{q1:{all_of:{ordered:true," | ||
| + "intervals:[{match:{query:quick}},{match:{query:fox}}]}}}}", | ||
| "fl", | ||
| "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. Note: the leading space before the first "{!" is required, otherwise the | ||
| // whole q string is parsed as a single set of local params rather than two clauses. | ||
| response = | ||
| new QueryRequest( | ||
| params( | ||
| "q", | ||
| " {!intervals df=subject}$q1 {!intervals df=subject}$q2", | ||
| "json", | ||
| "{json_queries:{q1:{match:{query:quick}},q2:{match:{query:lazy}}}}", | ||
| "fl", | ||
| "id")) | ||
| .process(cluster.getSolrClient(), COLLECTION); | ||
| assertEquals(3, response.getResults().getNumFound()); | ||
|
|
||
| // intersection of two top-level interval queries (using "+" to require both clauses): | ||
| // "quick" (docs 1, 3) and "brown" (docs 1, 2) — only doc 1 has both terms | ||
| response = | ||
| new QueryRequest( | ||
| params( | ||
| "q", | ||
| " +{!intervals df=subject}$q1 +{!intervals df=subject}$q2", | ||
| "json", | ||
| "{json_queries:{q1:{match:{query:quick}},q2:{match:{query:brown}}}}", | ||
| "fl", | ||
| "id")) | ||
| .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.