Skip to content

Commit

Permalink
SAI-4737: System prop solr.MaxBasicQueriesOverride for surround que…
Browse files Browse the repository at this point in the history
…ry (#172)

* Added support of system prop solr.absoluteMaxBasicQueries for surround query

* Moved param lookup logic to static, as we should only need to do and log it once.

And solr.absoluteMaxBasicQueries should only kick in if the original maxBasicQueries is greater

* ./gradlew tidy

* Changed solr.absoluteMaxBasicQueries to solr.maxBasicQueriesOverride, this requires less deployment but is a more temporary implementation.

* Renamed variable

* ./gradlew tidy
  • Loading branch information
patsonluk committed Dec 7, 2023
1 parent 6f786dd commit 1dc2064
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@
public class SurroundQParserPlugin extends QParserPlugin {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String NAME = "surround";
private static final String MAX_BASIC_QUERIES_SYSTEM_PROP = "solr.maxBasicQueriesOverride";
private static final int MAX_BASIC_QUERIES_OVERRIDE = readMaxBasicQueriesOverride();

private static int readMaxBasicQueriesOverride() {
String maxBasicQueriesSystemProp = System.getProperty(MAX_BASIC_QUERIES_SYSTEM_PROP);
if (maxBasicQueriesSystemProp != null) {
try {
int maxBasicQueriesOverride = Integer.parseInt(maxBasicQueriesSystemProp);
if (maxBasicQueriesOverride > 0) {
log.info(
"maxBasicQueries with system property {} with value {}",
MAX_BASIC_QUERIES_SYSTEM_PROP,
maxBasicQueriesSystemProp);
return maxBasicQueriesOverride;
} else {
log.info(
"Ignoring system property {} value {} since it is non-positive",
MAX_BASIC_QUERIES_SYSTEM_PROP,
maxBasicQueriesSystemProp);
}
} catch (NumberFormatException e) {
log.warn(
"Invalid system property {} value {}",
MAX_BASIC_QUERIES_SYSTEM_PROP,
maxBasicQueriesSystemProp);
}
}
return -1; // -1 indicates no max basic queries override
}

@Override
public QParser createParser(
Expand Down Expand Up @@ -77,6 +106,11 @@ public Query parse() throws SyntaxError {
this.maxBasicQueries = DEFMAXBASICQUERIES;
}
}

if (MAX_BASIC_QUERIES_OVERRIDE > 0) {
this.maxBasicQueries = MAX_BASIC_QUERIES_OVERRIDE;
}

// ugh .. colliding ParseExceptions
try {
sq = org.apache.lucene.queryparser.surround.parser.QueryParser.parse(qstr);
Expand Down

0 comments on commit 1dc2064

Please sign in to comment.