mirror of
https://github.com/apache/lucene.git
synced 2025-02-24 11:16:35 +00:00
SOLR-9409: improve error message on unsupported types in collapsing
* Improve error message when collapsing is not supported on given fieldtype * Return 400 error code when unsupported value are passed for max,min or in case of syntax error
This commit is contained in:
parent
2755f26ae4
commit
9228cefbc8
@ -195,6 +195,9 @@ Bug Fixes
|
|||||||
|
|
||||||
* SOLR-13280: Strengthen ScheduledTrigger's preferredOperation parameter validation. (Christine Poerschke)
|
* SOLR-13280: Strengthen ScheduledTrigger's preferredOperation parameter validation. (Christine Poerschke)
|
||||||
|
|
||||||
|
* SOLR-9409: Improve error message for unsupported field types and return 400 error code on
|
||||||
|
unsupported values in collapsing (hossman, Munendra S N)
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
@ -389,10 +389,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
|
|||||||
boostDocsMap,
|
boostDocsMap,
|
||||||
searcher);
|
searcher);
|
||||||
|
|
||||||
} catch (SolrException e) {
|
} catch (IOException e) {
|
||||||
// handle SolrException separately
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -973,7 +970,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
|
|||||||
} else {
|
} else {
|
||||||
NumberType numType = fieldType.getNumberType();
|
NumberType numType = fieldType.getNumberType();
|
||||||
if (null == numType) {
|
if (null == numType) {
|
||||||
throw new IOException("min/max must be either Int/Long/Float based field types");
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "min/max must be either Int/Long/Float based field types");
|
||||||
}
|
}
|
||||||
switch (numType) {
|
switch (numType) {
|
||||||
case INTEGER: {
|
case INTEGER: {
|
||||||
@ -989,7 +986,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new IOException("min/max must be either Int/Long/Float field types");
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "min/max must be either Int/Long/Float field types");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1170,7 +1167,8 @@ public class CollapsingQParserPlugin extends QParserPlugin {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new IOException("min/max must be Int or Float field types when collapsing on numeric fields");
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||||
|
"min/max must be Int or Float field types when collapsing on numeric fields");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1314,7 +1312,8 @@ public class CollapsingQParserPlugin extends QParserPlugin {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(HINT_TOP_FC.equals(hint)) {
|
if(HINT_TOP_FC.equals(hint)) {
|
||||||
throw new IOException("top_fc hint is only supported when collapsing on String Fields");
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||||
|
"top_fc hint is only supported when collapsing on String Fields");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1324,16 +1323,12 @@ public class CollapsingQParserPlugin extends QParserPlugin {
|
|||||||
if (text.indexOf("(") == -1) {
|
if (text.indexOf("(") == -1) {
|
||||||
minMaxFieldType = searcher.getSchema().getField(text).getType();
|
minMaxFieldType = searcher.getSchema().getField(text).getType();
|
||||||
} else {
|
} else {
|
||||||
LocalSolrQueryRequest request = null;
|
SolrParams params = new ModifiableSolrParams();
|
||||||
try {
|
try (SolrQueryRequest request = new LocalSolrQueryRequest(searcher.getCore(), params)) {
|
||||||
SolrParams params = new ModifiableSolrParams();
|
|
||||||
request = new LocalSolrQueryRequest(searcher.getCore(), params);
|
|
||||||
FunctionQParser functionQParser = new FunctionQParser(text, null, null,request);
|
FunctionQParser functionQParser = new FunctionQParser(text, null, null,request);
|
||||||
funcQuery = (FunctionQuery)functionQParser.parse();
|
funcQuery = (FunctionQuery)functionQParser.parse();
|
||||||
} catch (Exception e) {
|
} catch (SyntaxError e) {
|
||||||
throw new IOException(e);
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
|
||||||
} finally {
|
|
||||||
request.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1367,7 +1362,8 @@ public class CollapsingQParserPlugin extends QParserPlugin {
|
|||||||
return new IntScoreCollector(maxDoc, leafCount, nullValue, nullPolicy, size, collapseField, boostDocs);
|
return new IntScoreCollector(maxDoc, leafCount, nullValue, nullPolicy, size, collapseField, boostDocs);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("64 bit numeric collapse fields are not supported");
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||||
|
"Collapsing field should be of either String, Int or Float type");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // min, max, sort, etc.. something other then just "score"
|
} else { // min, max, sort, etc.. something other then just "score"
|
||||||
@ -1419,7 +1415,8 @@ public class CollapsingQParserPlugin extends QParserPlugin {
|
|||||||
funcQuery,
|
funcQuery,
|
||||||
searcher);
|
searcher);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("64 bit numeric collapse fields are not supported");
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||||
|
"Collapsing field should be of either String, Int or Float type");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.solr.search;
|
package org.apache.solr.search;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -970,19 +969,13 @@ public class TestCollapseQParserPlugin extends SolrTestCaseJ4 {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test64BitCollapseFieldException() {
|
public void test64BitCollapseFieldException() {
|
||||||
ModifiableSolrParams doubleParams = new ModifiableSolrParams();
|
assertQEx("Should Fail For collapsing on Long fields", "Collapsing field should be of either String, Int or Float type",
|
||||||
doubleParams.add("q", "*:*");
|
req("q", "*:*", "fq", "{!collapse field=group_l}"), SolrException.ErrorCode.BAD_REQUEST);
|
||||||
doubleParams.add("fq", "{!collapse field=group_d}");
|
|
||||||
expectThrows(RuntimeException.class, IOException.class, () -> h.query(req(doubleParams)));
|
|
||||||
|
|
||||||
ModifiableSolrParams dateParams = new ModifiableSolrParams();
|
assertQEx("Should Fail For collapsing on Double fields", "Collapsing field should be of either String, Int or Float type",
|
||||||
dateParams.add("q", "*:*");
|
req("q", "*:*", "fq", "{!collapse field=group_d}"), SolrException.ErrorCode.BAD_REQUEST);
|
||||||
dateParams.add("fq", "{!collapse field=group_dt}");
|
|
||||||
expectThrows(RuntimeException.class, IOException.class, () -> h.query(req(dateParams)));
|
|
||||||
|
|
||||||
ModifiableSolrParams longParams = new ModifiableSolrParams();
|
assertQEx("Should Fail For collapsing on Date fields", "Collapsing field should be of either String, Int or Float type",
|
||||||
longParams.add("q", "*:*");
|
req("q", "*:*", "fq", "{!collapse field=group_dt}"), SolrException.ErrorCode.BAD_REQUEST);
|
||||||
longParams.add("fq", "{!collapse field=group_l}");
|
|
||||||
expectThrows(RuntimeException.class, IOException.class, () -> h.query(req(longParams)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user