mirror of https://github.com/apache/lucene.git
SOLR-2275: mm param parsing optimization
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1052299 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f9854132c6
commit
9c61ecdef7
|
@ -608,21 +608,27 @@ public class SolrPluginUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private static Pattern spaceAroundLessThanPattern = Pattern.compile("\\s*<\\s*");
|
||||||
|
private static Pattern spaceAroundLessThanPattern = Pattern.compile("(\\s+<)|(<\\s+)|(\\s+<\\s+)");
|
||||||
|
private static Pattern spacePattern = Pattern.compile(" ");
|
||||||
|
private static Pattern lessThanPattern = Pattern.compile("<");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* helper exposed for UnitTests
|
* helper exposed for UnitTests
|
||||||
* @see #setMinShouldMatch
|
* @see #setMinShouldMatch
|
||||||
*/
|
*/
|
||||||
static int calculateMinShouldMatch(int optionalClauseCount, String specIn) {
|
static int calculateMinShouldMatch(int optionalClauseCount, String spec) {
|
||||||
|
|
||||||
int result = optionalClauseCount;
|
int result = optionalClauseCount;
|
||||||
|
spec = spec.trim();
|
||||||
|
|
||||||
String spec = specIn.replaceAll("\\s*<\\s*", "<");
|
|
||||||
if (-1 < spec.indexOf("<")) {
|
if (-1 < spec.indexOf("<")) {
|
||||||
/* we have conditional spec(s) */
|
/* we have conditional spec(s) */
|
||||||
|
spec = spaceAroundLessThanPattern.matcher(spec).replaceAll("<");
|
||||||
|
|
||||||
for (String s : spec.trim().split(" ")) {
|
for (String s : spacePattern.split(spec)) {
|
||||||
String[] parts = s.split("<");
|
String[] parts = lessThanPattern.split(s);
|
||||||
int upperBound = (new Integer(parts[0].trim())).intValue();
|
int upperBound = Integer.parseInt(parts[0]);
|
||||||
if (optionalClauseCount <= upperBound) {
|
if (optionalClauseCount <= upperBound) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
@ -635,13 +641,14 @@ public class SolrPluginUtils {
|
||||||
|
|
||||||
/* otherwise, simple expresion */
|
/* otherwise, simple expresion */
|
||||||
|
|
||||||
if (-1 < spec.indexOf("%")) {
|
if (-1 < spec.indexOf('%')) {
|
||||||
/* percentage */
|
/* percentage - assume the % was the last char. If not, let Integer.parseInt fail. */
|
||||||
int percent = new Integer(spec.trim().replace("%","")).intValue();
|
spec = spec.substring(0,spec.length()-1);
|
||||||
float calc = (result * percent) / 100f;
|
int percent = Integer.parseInt(spec);
|
||||||
|
float calc = (result * percent) * (1/100f);
|
||||||
result = calc < 0 ? result + (int)calc : (int)calc;
|
result = calc < 0 ? result + (int)calc : (int)calc;
|
||||||
} else {
|
} else {
|
||||||
int calc = (new Integer(spec.trim())).intValue();
|
int calc = Integer.parseInt(spec);
|
||||||
result = calc < 0 ? result + calc : calc;
|
result = calc < 0 ? result + calc : calc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue