Skip to content

Commit

Permalink
Better detection of misconfigured searches (CO-1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Oct 3, 2021
1 parent a4c7ced commit 17dec12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/src/Lib/Match/MatchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ protected function search(string $mode,
// how we handle all this
switch($ruleattr->search_type) {
case SearchTypeEnum::Distance:
if(empty($attribute->search_distance)) {
// We're configured for search distance but we don't have a value
Log::write('debug', $sor . "/" . $sorid . " No search distance configured for attribute " . $attribute->name . ", skipping rule " . $rule->name);
continue 2;
}
$maxdistance = (int)($attribute->search_distance)+1;
$attrclause = "LEVENSHTEIN_LESS_EQUAL("
. $colclause
Expand All @@ -595,6 +600,11 @@ protected function search(string $mode,
$attrclause = $colclause . "=?";
break;
case SearchTypeEnum::Mapping:
if(empty($attribute->attribute_map_id)) {
// We're configured for attribute mapping, but we don't have a Map
Log::write('debug', $sor . "/" . $sorid . " No Attribute Map configured for attribute " . $attribute->name . ", skipping rule " . $rule->name);
continue 2;
}
$qclause = (!$attribute->case_sensitive ? "LOWER(query)" : "query");
$attrclause = "(" . $colclause . "
IN (SELECT value
Expand All @@ -606,6 +616,11 @@ protected function search(string $mode,
$attrSql['vals'][$ruleattr->attribute->id][] = (!$attribute->case_sensitive ? strtolower($val) : $val);
break;
case SearchTypeEnum::Substring:
if(empty($attribute->search_substr_from) || empty($attribute->search_substr_for)) {
// We're configured for substring search but we don't have a value
Log::write('debug', $sor . "/" . $sorid . " Substring search values not properly configured for attribute " . $attribute->name . ", skipping rule " . $rule->name);
continue 2;
}
$attrclause = "SUBSTRING("
. $colclause
. " FROM "
Expand Down
2 changes: 1 addition & 1 deletion app/src/Model/Table/RulesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function validationDefault(Validator $validator): Validator {
'content',
[ 'rule' => 'isInteger' ]
);
$validator->allowEmpty('ordr');
$validator->allowEmptyString('ordr');

return $validator;
}
Expand Down

0 comments on commit 17dec12

Please sign in to comment.