Skip to content

Commit

Permalink
Improve detection of complex script conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 29, 2024
1 parent 3067f52 commit 445887c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/search/st_author.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function test(PaperInfo $row, $xinfo) {
function script_expression(PaperInfo $row, $about) {
if ($this->csm->has_contacts()
|| $this->regex
|| $about !== self::ABOUT_PAPER) {
|| ($about & self::ABOUT_PAPER) === 0) {
return $this->test($row, null);
} else {
return ["type" => "compar", "compar" => $this->csm->relation(), "child" => [
Expand Down
2 changes: 1 addition & 1 deletion src/search/st_conflict.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function test(PaperInfo $row, $xinfo) {
return $this->ccm->test($n);
}
function script_expression(PaperInfo $row, $about) {
if ($about !== self::ABOUT_PAPER) {
if (($about & self::ABOUT_PAPER) === 0) {
return $this->test($row, null);
} else if (!$this->ispc) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/search/st_documentcount.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function test(PaperInfo $row, $xinfo) {
return CountMatcher::compare($n, $this->compar, $this->value);
}
function script_expression(PaperInfo $row, $about) {
if ($about === self::ABOUT_PAPER) {
if (($about & self::ABOUT_PAPER) !== 0) {
return parent::script_expression($row, $about);
} else if ($this->user->can_view_option($row, $this->option)) {
return [
Expand Down
2 changes: 1 addition & 1 deletion src/search/st_optionpresent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function test(PaperInfo $row, $xinfo) {
&& $this->option->value_present($ov);
}
function script_expression(PaperInfo $row, $about) {
if ($about !== self::ABOUT_PAPER) {
if (($about & self::ABOUR_PAPER) === 0) {
return parent::script_expression($row, $about);
} else if ($this->user->can_view_option($row, $this->option)) {
return $this->option->present_script_expression();
Expand Down
2 changes: 1 addition & 1 deletion src/search/st_optionvalue.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function test(PaperInfo $row, $xinfo) {
&& CountMatcher::compare($ov->value, $this->compar, $this->value);
}
function script_expression(PaperInfo $row, $about) {
if ($about !== self::ABOUT_PAPER) {
if (($about & self::ABOUT_PAPER) === 0) {
return parent::script_expression($row, $about);
} else if ($this->user->can_view_option($row, $this->option)) {
if (($se = $this->option->value_script_expression())) {
Expand Down
2 changes: 1 addition & 1 deletion src/search/st_optionvaluein.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function test(PaperInfo $row, $xinfo) {
return false;
}
function script_expression(PaperInfo $row, $about) {
if ($about !== self::ABOUT_PAPER) {
if (($about & self::ABOUT_PAPER) === 0) {
return parent::script_expression($row, $about);
} else if ($this->user->can_view_option($row, $this->option)) {
return $this->option->match_script_expression($this->values);
Expand Down
2 changes: 1 addition & 1 deletion src/search/st_realnumberoption.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function test(PaperInfo $row, $xinfo) {
&& CountMatcher::compare(floatval($ov->data()), $this->compar, $this->value);
}
function script_expression(PaperInfo $row, $about) {
if ($about !== self::ABOUT_PAPER) {
if (($about & self::ABOUT_PAPER) === 0) {
return parent::script_expression($row, $about);
} else if ($this->user->can_view_option($row, $this->option)) {
if (($se = $this->option->value_script_expression())) {
Expand Down
24 changes: 15 additions & 9 deletions src/searchterm.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,19 @@ function default_sort_column($top, $pl) {
return null;
}

const ABOUT_PAPER = 0;
const ABOUT_UNKNOWN = 1;
const ABOUT_REVIEW = 2;
const ABOUT_REVIEW_SET = 3;
/** @return 0|1|2|3 */
const ABOUT_PAPER = 1;
const ABOUT_UNKNOWN = 2;
const ABOUT_REVIEW = 4;
const ABOUT_REVIEW_SET = 8;
const ABOUT_NO_SHORT_CIRCUIT = 16;

/** @return 1|2|4|8 */
function about() {
return self::ABOUT_PAPER;
}


/** @param 0|2 $about
/** @param int $about
* @return null|bool|array{type:string} */
function script_expression(PaperInfo $row, $about) {
return $this->test($row, null);
Expand Down Expand Up @@ -502,10 +504,12 @@ function about() {

/** @param 'and'|'or'|'not'|'xor' $op
* @param list<null|bool|array{type:string}> $sexprs
* @param int $about
* @return null|bool|array{type:string} */
static function combine_script_expressions($op, $sexprs) {
static function combine_script_expressions($op, $sexprs, $about = 0) {
$ok = true;
$bresult = $op === "and";
$xresult = null;
$any = false;
$ch = [];
foreach ($sexprs as $sexpr) {
Expand All @@ -514,16 +518,18 @@ static function combine_script_expressions($op, $sexprs) {
} else if (is_bool($sexpr)) {
$any = true;
if ($sexpr ? $op === "or" : $op === "and") {
return $sexpr;
$xresult = $sexpr;
} else if ($sexpr ? $op === "xor" : $op === "not") {
$bresult = !$bresult;
}
} else {
$ch[] = $sexpr;
}
}
if (!$ok) {
if (!$ok && ($xresult === null || ($about & self::ABOUT_NO_SHORT_CIRCUIT) !== 0)) {
return null;
} else if ($xresult !== null) {
return $xresult;
} else if (empty($ch)) {
return $any && $bresult;
} else if ($op === "not" || ($bresult && $op === "xor" && count($ch) === 1)) {
Expand Down
2 changes: 1 addition & 1 deletion src/settings/s_subfieldcondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static private function validate1($sv, $ctr, $type, $field, $status, $prow) {
}

// check script expression
if ($ps->main_term()->script_expression($prow, SearchTerm::ABOUT_PAPER) === null) {
if ($ps->main_term()->script_expression($prow, SearchTerm::ABOUT_PAPER | SearchTerm::ABOUT_NO_SHORT_CIRCUIT) === null) {
$sv->msg_at($siname, "<0>Invalid search in field condition", $status);
$sv->inform_at($siname, "<0>Field conditions are limited to simple search keywords.");
}
Expand Down

0 comments on commit 445887c

Please sign in to comment.