repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
drutiny/drutiny | src/Driver/DrushDriver.php | DrushDriver.sqlq | public function sqlq($sql) {
// $args = ['--db-prefix', '"' . $sql . '"'];
$sql = strtr($sql, [
"{" => '',
"}" => ''
]);
$output = trim($this->__call('sqlq', ['"' . $sql . '"']));
$output = $this->cleanOutput($output);
return $output;
} | php | public function sqlq($sql) {
// $args = ['--db-prefix', '"' . $sql . '"'];
$sql = strtr($sql, [
"{" => '',
"}" => ''
]);
$output = trim($this->__call('sqlq', ['"' . $sql . '"']));
$output = $this->cleanOutput($output);
return $output;
} | [
"public",
"function",
"sqlq",
"(",
"$",
"sql",
")",
"{",
"// $args = ['--db-prefix', '\"' . $sql . '\"'];",
"$",
"sql",
"=",
"strtr",
"(",
"$",
"sql",
",",
"[",
"\"{\"",
"=>",
"''",
",",
"\"}\"",
"=>",
"''",
"]",
")",
";",
"$",
"output",
"=",
"trim",
"(",
"$",
"this",
"->",
"__call",
"(",
"'sqlq'",
",",
"[",
"'\"'",
".",
"$",
"sql",
".",
"'\"'",
"]",
")",
")",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"cleanOutput",
"(",
"$",
"output",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Override for drush command 'sqlq'. | [
"Override",
"for",
"drush",
"command",
"sqlq",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Driver/DrushDriver.php#L242-L251 |
drutiny/drutiny | src/Driver/DrushDriver.php | DrushDriver.evaluate | public function evaluate(\Closure $callback, Array $args = []) {
$args = array_values($args);
$func = new \ReflectionFunction($callback);
$filename = $func->getFileName();
$start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
$end_line = $func->getEndLine();
$length = $end_line - $start_line;
$source = file($filename);
$body = array_slice($source, $start_line, $length);
$col = strpos($body[0], 'function');
$body[0] = substr($body[0], $col);
$last = count($body) - 1;
$col = strpos($body[$last], '}') + 1;
$body[$last] = substr($body[$last], 0, $col);
$code = ['<?php'];
$calling_args = [];
foreach ($func->getParameters() as $i => $param) {
$code[] = '$' . $param->name . ' = ' . var_export($args[$i], TRUE) . ';';
$calling_args[] = '$' . $param->name;
}
$code[] = '$evaluation = ' . implode("", $body) . ';';
$code[] = 'echo json_encode($evaluation(' . implode(', ', $calling_args) . '));';
$transfer = base64_encode(implode(PHP_EOL, $code));
$execution = [];
// Linux uses tempfile while OSX uses mktemp.
$execution[] = 't=`which tempfile || which mktemp`; f=$($t)';
$execution[] = "echo $transfer | base64 --decode > \$f";
$pipe = implode(';' . PHP_EOL, $execution);
$execution[] = strtr('@bin @alias @options scr $f', [
'@options' => implode(' ', $this->getOptions()),
'@alias' => $this->getAlias(),
'@bin' => $this->drushBin,
]);
$execution[] = 'rm $f';
$transfer = implode(';' . PHP_EOL, $execution);
$output = $this->target->exec($transfer);
return json_decode($output, TRUE);
} | php | public function evaluate(\Closure $callback, Array $args = []) {
$args = array_values($args);
$func = new \ReflectionFunction($callback);
$filename = $func->getFileName();
$start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
$end_line = $func->getEndLine();
$length = $end_line - $start_line;
$source = file($filename);
$body = array_slice($source, $start_line, $length);
$col = strpos($body[0], 'function');
$body[0] = substr($body[0], $col);
$last = count($body) - 1;
$col = strpos($body[$last], '}') + 1;
$body[$last] = substr($body[$last], 0, $col);
$code = ['<?php'];
$calling_args = [];
foreach ($func->getParameters() as $i => $param) {
$code[] = '$' . $param->name . ' = ' . var_export($args[$i], TRUE) . ';';
$calling_args[] = '$' . $param->name;
}
$code[] = '$evaluation = ' . implode("", $body) . ';';
$code[] = 'echo json_encode($evaluation(' . implode(', ', $calling_args) . '));';
$transfer = base64_encode(implode(PHP_EOL, $code));
$execution = [];
// Linux uses tempfile while OSX uses mktemp.
$execution[] = 't=`which tempfile || which mktemp`; f=$($t)';
$execution[] = "echo $transfer | base64 --decode > \$f";
$pipe = implode(';' . PHP_EOL, $execution);
$execution[] = strtr('@bin @alias @options scr $f', [
'@options' => implode(' ', $this->getOptions()),
'@alias' => $this->getAlias(),
'@bin' => $this->drushBin,
]);
$execution[] = 'rm $f';
$transfer = implode(';' . PHP_EOL, $execution);
$output = $this->target->exec($transfer);
return json_decode($output, TRUE);
} | [
"public",
"function",
"evaluate",
"(",
"\\",
"Closure",
"$",
"callback",
",",
"Array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"args",
"=",
"array_values",
"(",
"$",
"args",
")",
";",
"$",
"func",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"callback",
")",
";",
"$",
"filename",
"=",
"$",
"func",
"->",
"getFileName",
"(",
")",
";",
"$",
"start_line",
"=",
"$",
"func",
"->",
"getStartLine",
"(",
")",
"-",
"1",
";",
"// it's actually - 1, otherwise you wont get the function() block",
"$",
"end_line",
"=",
"$",
"func",
"->",
"getEndLine",
"(",
")",
";",
"$",
"length",
"=",
"$",
"end_line",
"-",
"$",
"start_line",
";",
"$",
"source",
"=",
"file",
"(",
"$",
"filename",
")",
";",
"$",
"body",
"=",
"array_slice",
"(",
"$",
"source",
",",
"$",
"start_line",
",",
"$",
"length",
")",
";",
"$",
"col",
"=",
"strpos",
"(",
"$",
"body",
"[",
"0",
"]",
",",
"'function'",
")",
";",
"$",
"body",
"[",
"0",
"]",
"=",
"substr",
"(",
"$",
"body",
"[",
"0",
"]",
",",
"$",
"col",
")",
";",
"$",
"last",
"=",
"count",
"(",
"$",
"body",
")",
"-",
"1",
";",
"$",
"col",
"=",
"strpos",
"(",
"$",
"body",
"[",
"$",
"last",
"]",
",",
"'}'",
")",
"+",
"1",
";",
"$",
"body",
"[",
"$",
"last",
"]",
"=",
"substr",
"(",
"$",
"body",
"[",
"$",
"last",
"]",
",",
"0",
",",
"$",
"col",
")",
";",
"$",
"code",
"=",
"[",
"'<?php'",
"]",
";",
"$",
"calling_args",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"func",
"->",
"getParameters",
"(",
")",
"as",
"$",
"i",
"=>",
"$",
"param",
")",
"{",
"$",
"code",
"[",
"]",
"=",
"'$'",
".",
"$",
"param",
"->",
"name",
".",
"' = '",
".",
"var_export",
"(",
"$",
"args",
"[",
"$",
"i",
"]",
",",
"TRUE",
")",
".",
"';'",
";",
"$",
"calling_args",
"[",
"]",
"=",
"'$'",
".",
"$",
"param",
"->",
"name",
";",
"}",
"$",
"code",
"[",
"]",
"=",
"'$evaluation = '",
".",
"implode",
"(",
"\"\"",
",",
"$",
"body",
")",
".",
"';'",
";",
"$",
"code",
"[",
"]",
"=",
"'echo json_encode($evaluation('",
".",
"implode",
"(",
"', '",
",",
"$",
"calling_args",
")",
".",
"'));'",
";",
"$",
"transfer",
"=",
"base64_encode",
"(",
"implode",
"(",
"PHP_EOL",
",",
"$",
"code",
")",
")",
";",
"$",
"execution",
"=",
"[",
"]",
";",
"// Linux uses tempfile while OSX uses mktemp.",
"$",
"execution",
"[",
"]",
"=",
"'t=`which tempfile || which mktemp`; f=$($t)'",
";",
"$",
"execution",
"[",
"]",
"=",
"\"echo $transfer | base64 --decode > \\$f\"",
";",
"$",
"pipe",
"=",
"implode",
"(",
"';'",
".",
"PHP_EOL",
",",
"$",
"execution",
")",
";",
"$",
"execution",
"[",
"]",
"=",
"strtr",
"(",
"'@bin @alias @options scr $f'",
",",
"[",
"'@options'",
"=>",
"implode",
"(",
"' '",
",",
"$",
"this",
"->",
"getOptions",
"(",
")",
")",
",",
"'@alias'",
"=>",
"$",
"this",
"->",
"getAlias",
"(",
")",
",",
"'@bin'",
"=>",
"$",
"this",
"->",
"drushBin",
",",
"]",
")",
";",
"$",
"execution",
"[",
"]",
"=",
"'rm $f'",
";",
"$",
"transfer",
"=",
"implode",
"(",
"';'",
".",
"PHP_EOL",
",",
"$",
"execution",
")",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"target",
"->",
"exec",
"(",
"$",
"transfer",
")",
";",
"return",
"json_decode",
"(",
"$",
"output",
",",
"TRUE",
")",
";",
"}"
] | This function takes PHP in this execution scope (Closure) and executes it
against the Drupal target using Drush php-script.
@param \Closure $callback
@param array $args
@return mixed | [
"This",
"function",
"takes",
"PHP",
"in",
"this",
"execution",
"scope",
"(",
"Closure",
")",
"and",
"executes",
"it",
"against",
"the",
"Drupal",
"target",
"using",
"Drush",
"php",
"-",
"script",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Driver/DrushDriver.php#L268-L316 |
drutiny/drutiny | src/Profile.php | Profile.loadFromFile | public static function loadFromFile($filepath)
{
$info = Yaml::parseFile($filepath);
$name = str_replace('.profile.yml', '', pathinfo($filepath, PATHINFO_BASENAME));
$profile = new static();
$profile->setTitle($info['title'])
->setName($name)
->setFilepath($filepath);
if (isset($info['description'])) {
$profile->setDescription($info['description']);
}
if (isset($info['policies'])) {
$v21_keys = ['parameters', 'severity'];
foreach ($info['policies'] as $name => $metadata) {
// Check for v2.0.x style profiles.
if (!empty($metadata) && !count(array_intersect($v21_keys, array_keys($metadata)))) {
throw new \Exception("{$info['title']} is a v2.0.x profile. Please upgrade $filepath to v2.2.x schema.");
}
$weight = array_search($name, array_keys($info['policies']));
$profile->addPolicyDefinition(PolicyDefinition::createFromProfile($name, $weight, $metadata));
}
}
if (isset($info['excluded_policies']) && is_array($info['excluded_policies'])) {
$profile->addExcludedPolicies($info['excluded_policies']);
}
if (isset($info['include'])) {
foreach ($info['include'] as $name) {
$include = ProfileSource::loadProfileByName($name);
$profile->addInclude($include);
}
}
if (isset($info['format'])) {
foreach ($info['format'] as $format => $options) {
$profile->addFormatOptions(Format::create($format, $options));
}
}
return $profile;
} | php | public static function loadFromFile($filepath)
{
$info = Yaml::parseFile($filepath);
$name = str_replace('.profile.yml', '', pathinfo($filepath, PATHINFO_BASENAME));
$profile = new static();
$profile->setTitle($info['title'])
->setName($name)
->setFilepath($filepath);
if (isset($info['description'])) {
$profile->setDescription($info['description']);
}
if (isset($info['policies'])) {
$v21_keys = ['parameters', 'severity'];
foreach ($info['policies'] as $name => $metadata) {
// Check for v2.0.x style profiles.
if (!empty($metadata) && !count(array_intersect($v21_keys, array_keys($metadata)))) {
throw new \Exception("{$info['title']} is a v2.0.x profile. Please upgrade $filepath to v2.2.x schema.");
}
$weight = array_search($name, array_keys($info['policies']));
$profile->addPolicyDefinition(PolicyDefinition::createFromProfile($name, $weight, $metadata));
}
}
if (isset($info['excluded_policies']) && is_array($info['excluded_policies'])) {
$profile->addExcludedPolicies($info['excluded_policies']);
}
if (isset($info['include'])) {
foreach ($info['include'] as $name) {
$include = ProfileSource::loadProfileByName($name);
$profile->addInclude($include);
}
}
if (isset($info['format'])) {
foreach ($info['format'] as $format => $options) {
$profile->addFormatOptions(Format::create($format, $options));
}
}
return $profile;
} | [
"public",
"static",
"function",
"loadFromFile",
"(",
"$",
"filepath",
")",
"{",
"$",
"info",
"=",
"Yaml",
"::",
"parseFile",
"(",
"$",
"filepath",
")",
";",
"$",
"name",
"=",
"str_replace",
"(",
"'.profile.yml'",
",",
"''",
",",
"pathinfo",
"(",
"$",
"filepath",
",",
"PATHINFO_BASENAME",
")",
")",
";",
"$",
"profile",
"=",
"new",
"static",
"(",
")",
";",
"$",
"profile",
"->",
"setTitle",
"(",
"$",
"info",
"[",
"'title'",
"]",
")",
"->",
"setName",
"(",
"$",
"name",
")",
"->",
"setFilepath",
"(",
"$",
"filepath",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"profile",
"->",
"setDescription",
"(",
"$",
"info",
"[",
"'description'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'policies'",
"]",
")",
")",
"{",
"$",
"v21_keys",
"=",
"[",
"'parameters'",
",",
"'severity'",
"]",
";",
"foreach",
"(",
"$",
"info",
"[",
"'policies'",
"]",
"as",
"$",
"name",
"=>",
"$",
"metadata",
")",
"{",
"// Check for v2.0.x style profiles.",
"if",
"(",
"!",
"empty",
"(",
"$",
"metadata",
")",
"&&",
"!",
"count",
"(",
"array_intersect",
"(",
"$",
"v21_keys",
",",
"array_keys",
"(",
"$",
"metadata",
")",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"{$info['title']} is a v2.0.x profile. Please upgrade $filepath to v2.2.x schema.\"",
")",
";",
"}",
"$",
"weight",
"=",
"array_search",
"(",
"$",
"name",
",",
"array_keys",
"(",
"$",
"info",
"[",
"'policies'",
"]",
")",
")",
";",
"$",
"profile",
"->",
"addPolicyDefinition",
"(",
"PolicyDefinition",
"::",
"createFromProfile",
"(",
"$",
"name",
",",
"$",
"weight",
",",
"$",
"metadata",
")",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'excluded_policies'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"info",
"[",
"'excluded_policies'",
"]",
")",
")",
"{",
"$",
"profile",
"->",
"addExcludedPolicies",
"(",
"$",
"info",
"[",
"'excluded_policies'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'include'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"info",
"[",
"'include'",
"]",
"as",
"$",
"name",
")",
"{",
"$",
"include",
"=",
"ProfileSource",
"::",
"loadProfileByName",
"(",
"$",
"name",
")",
";",
"$",
"profile",
"->",
"addInclude",
"(",
"$",
"include",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'format'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"info",
"[",
"'format'",
"]",
"as",
"$",
"format",
"=>",
"$",
"options",
")",
"{",
"$",
"profile",
"->",
"addFormatOptions",
"(",
"Format",
"::",
"create",
"(",
"$",
"format",
",",
"$",
"options",
")",
")",
";",
"}",
"}",
"return",
"$",
"profile",
";",
"}"
] | Load a profile from file.
@var $filepath string | [
"Load",
"a",
"profile",
"from",
"file",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Profile.php#L88-L132 |
drutiny/drutiny | src/Profile.php | Profile.getFormatOption | public function getFormatOption($format, $options = [])
{
$format = isset($this->format[$format]) ? $this->format[$format] : Format::create($format, $options);
if (isset($options['output']) && empty($format->getOutput())) {
$format->setOutput($options['output']);
}
return $format;
} | php | public function getFormatOption($format, $options = [])
{
$format = isset($this->format[$format]) ? $this->format[$format] : Format::create($format, $options);
if (isset($options['output']) && empty($format->getOutput())) {
$format->setOutput($options['output']);
}
return $format;
} | [
"public",
"function",
"getFormatOption",
"(",
"$",
"format",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"format",
"=",
"isset",
"(",
"$",
"this",
"->",
"format",
"[",
"$",
"format",
"]",
")",
"?",
"$",
"this",
"->",
"format",
"[",
"$",
"format",
"]",
":",
"Format",
"::",
"create",
"(",
"$",
"format",
",",
"$",
"options",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'output'",
"]",
")",
"&&",
"empty",
"(",
"$",
"format",
"->",
"getOutput",
"(",
")",
")",
")",
"{",
"$",
"format",
"->",
"setOutput",
"(",
"$",
"options",
"[",
"'output'",
"]",
")",
";",
"}",
"return",
"$",
"format",
";",
"}"
] | Add a FormatOptions to the profile. | [
"Add",
"a",
"FormatOptions",
"to",
"the",
"profile",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Profile.php#L146-L153 |
drutiny/drutiny | src/Profile.php | Profile.addPolicyDefinition | public function addPolicyDefinition(PolicyDefinition $definition)
{
// Do not include excluded dependencies
if (!in_array($definition->getName(), $this->excludedPolicies)) {
$this->policies[$definition->getName()] = $definition;
}
return $this;
} | php | public function addPolicyDefinition(PolicyDefinition $definition)
{
// Do not include excluded dependencies
if (!in_array($definition->getName(), $this->excludedPolicies)) {
$this->policies[$definition->getName()] = $definition;
}
return $this;
} | [
"public",
"function",
"addPolicyDefinition",
"(",
"PolicyDefinition",
"$",
"definition",
")",
"{",
"// Do not include excluded dependencies",
"if",
"(",
"!",
"in_array",
"(",
"$",
"definition",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"excludedPolicies",
")",
")",
"{",
"$",
"this",
"->",
"policies",
"[",
"$",
"definition",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"definition",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a PolicyDefinition to the profile. | [
"Add",
"a",
"PolicyDefinition",
"to",
"the",
"profile",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Profile.php#L158-L165 |
drutiny/drutiny | src/Profile.php | Profile.getPolicyDefinition | public function getPolicyDefinition($name)
{
return isset($this->policies[$name]) ? $this->policies[$name] : FALSE;
} | php | public function getPolicyDefinition($name)
{
return isset($this->policies[$name]) ? $this->policies[$name] : FALSE;
} | [
"public",
"function",
"getPolicyDefinition",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"policies",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"policies",
"[",
"$",
"name",
"]",
":",
"FALSE",
";",
"}"
] | Add a PolicyDefinition to the profile. | [
"Add",
"a",
"PolicyDefinition",
"to",
"the",
"profile",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Profile.php#L176-L179 |
drutiny/drutiny | src/Profile.php | Profile.getAllPolicyDefinitions | public function getAllPolicyDefinitions()
{
// Sort $policies
// 1. By weight. Lighter policies float to the top.
// 2. By name, alphabetical sorting.
uasort($this->policies, function (PolicyDefinition $a, PolicyDefinition $b) {
// 1. By weight. Lighter policies float to the top.
if ($a->getWeight() == $b->getWeight()) {
$alpha = [$a->getName(), $b->getName()];
sort($alpha);
// 2. By name, alphabetical sorting.
return $alpha[0] == $a->getName() ? -1 : 1;
}
return $a->getWeight() > $b->getWeight() ? 1 : -1;
});
return $this->policies;
} | php | public function getAllPolicyDefinitions()
{
// Sort $policies
// 1. By weight. Lighter policies float to the top.
// 2. By name, alphabetical sorting.
uasort($this->policies, function (PolicyDefinition $a, PolicyDefinition $b) {
// 1. By weight. Lighter policies float to the top.
if ($a->getWeight() == $b->getWeight()) {
$alpha = [$a->getName(), $b->getName()];
sort($alpha);
// 2. By name, alphabetical sorting.
return $alpha[0] == $a->getName() ? -1 : 1;
}
return $a->getWeight() > $b->getWeight() ? 1 : -1;
});
return $this->policies;
} | [
"public",
"function",
"getAllPolicyDefinitions",
"(",
")",
"{",
"// Sort $policies",
"// 1. By weight. Lighter policies float to the top.",
"// 2. By name, alphabetical sorting.",
"uasort",
"(",
"$",
"this",
"->",
"policies",
",",
"function",
"(",
"PolicyDefinition",
"$",
"a",
",",
"PolicyDefinition",
"$",
"b",
")",
"{",
"// 1. By weight. Lighter policies float to the top.",
"if",
"(",
"$",
"a",
"->",
"getWeight",
"(",
")",
"==",
"$",
"b",
"->",
"getWeight",
"(",
")",
")",
"{",
"$",
"alpha",
"=",
"[",
"$",
"a",
"->",
"getName",
"(",
")",
",",
"$",
"b",
"->",
"getName",
"(",
")",
"]",
";",
"sort",
"(",
"$",
"alpha",
")",
";",
"// 2. By name, alphabetical sorting.",
"return",
"$",
"alpha",
"[",
"0",
"]",
"==",
"$",
"a",
"->",
"getName",
"(",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"return",
"$",
"a",
"->",
"getWeight",
"(",
")",
">",
"$",
"b",
"->",
"getWeight",
"(",
")",
"?",
"1",
":",
"-",
"1",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"policies",
";",
"}"
] | Add a PolicyDefinition to the profile. | [
"Add",
"a",
"PolicyDefinition",
"to",
"the",
"profile",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Profile.php#L184-L202 |
drutiny/drutiny | src/Profile.php | Profile.addInclude | public function addInclude(Profile $profile)
{
$profile->setParent($this);
$this->include[$profile->getName()] = $profile;
foreach ($profile->getAllPolicyDefinitions() as $policy) {
// Do not override policies already specified, they take priority.
if ($this->getPolicyDefinition($policy->getName())) {
continue;
}
$this->addPolicyDefinition($policy);
}
return $this;
} | php | public function addInclude(Profile $profile)
{
$profile->setParent($this);
$this->include[$profile->getName()] = $profile;
foreach ($profile->getAllPolicyDefinitions() as $policy) {
// Do not override policies already specified, they take priority.
if ($this->getPolicyDefinition($policy->getName())) {
continue;
}
$this->addPolicyDefinition($policy);
}
return $this;
} | [
"public",
"function",
"addInclude",
"(",
"Profile",
"$",
"profile",
")",
"{",
"$",
"profile",
"->",
"setParent",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"include",
"[",
"$",
"profile",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"profile",
";",
"foreach",
"(",
"$",
"profile",
"->",
"getAllPolicyDefinitions",
"(",
")",
"as",
"$",
"policy",
")",
"{",
"// Do not override policies already specified, they take priority.",
"if",
"(",
"$",
"this",
"->",
"getPolicyDefinition",
"(",
"$",
"policy",
"->",
"getName",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"addPolicyDefinition",
"(",
"$",
"policy",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a Profile to the profile. | [
"Add",
"a",
"Profile",
"to",
"the",
"profile",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Profile.php#L275-L287 |
drutiny/drutiny | src/Profile.php | Profile.setParent | public function setParent(Profile $parent)
{
// Ensure parent doesn't already have this profile loaded.
// This prevents recursive looping.
if (!$parent->getParent($this->getName())) {
$this->parent = $parent;
return $this;
}
throw new \Exception($this->getName() . ' already found in profile lineage.');
} | php | public function setParent(Profile $parent)
{
// Ensure parent doesn't already have this profile loaded.
// This prevents recursive looping.
if (!$parent->getParent($this->getName())) {
$this->parent = $parent;
return $this;
}
throw new \Exception($this->getName() . ' already found in profile lineage.');
} | [
"public",
"function",
"setParent",
"(",
"Profile",
"$",
"parent",
")",
"{",
"// Ensure parent doesn't already have this profile loaded.",
"// This prevents recursive looping.",
"if",
"(",
"!",
"$",
"parent",
"->",
"getParent",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"parent",
"=",
"$",
"parent",
";",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"' already found in profile lineage.'",
")",
";",
"}"
] | Add a Profile to the profile. | [
"Add",
"a",
"Profile",
"to",
"the",
"profile",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Profile.php#L308-L317 |
drutiny/drutiny | src/Profile.php | Profile.getParent | public function getParent($name = NULL)
{
if (!$this->parent) {
return FALSE;
}
if ($name) {
if ($this->parent->getName() == $name) {
return $this->parent;
}
if ($parent = $this->parent->getInclude($name)) {
return $parent;
}
// Recurse up the tree to find if the parent is in the tree.
return $this->parent->getParent($name);
}
return $this->parent;
} | php | public function getParent($name = NULL)
{
if (!$this->parent) {
return FALSE;
}
if ($name) {
if ($this->parent->getName() == $name) {
return $this->parent;
}
if ($parent = $this->parent->getInclude($name)) {
return $parent;
}
// Recurse up the tree to find if the parent is in the tree.
return $this->parent->getParent($name);
}
return $this->parent;
} | [
"public",
"function",
"getParent",
"(",
"$",
"name",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parent",
")",
"{",
"return",
"FALSE",
";",
"}",
"if",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parent",
"->",
"getName",
"(",
")",
"==",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"parent",
";",
"}",
"if",
"(",
"$",
"parent",
"=",
"$",
"this",
"->",
"parent",
"->",
"getInclude",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"parent",
";",
"}",
"// Recurse up the tree to find if the parent is in the tree.",
"return",
"$",
"this",
"->",
"parent",
"->",
"getParent",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parent",
";",
"}"
] | Find a parent in the tree of parent profiles. | [
"Find",
"a",
"parent",
"in",
"the",
"tree",
"of",
"parent",
"profiles",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Profile.php#L322-L338 |
drutiny/drutiny | src/Policy/Dependency.php | Dependency.execute | public function execute(Sandbox $sandbox)
{
$language = new ExpressionLanguage($sandbox);
Container::getLogger()->info("Evaluating expression: " . $language->compile($this->expression));
try {
if ($return = $language->evaluate($this->expression)) {
Container::getLogger()->debug(__CLASS__ . ": Expression PASSED: $return");
return $return;
}
}
catch (\Exception $e) {
Container::getLogger()->warning($e->getMessage());
}
Container::getLogger()->debug(__CLASS__ . ": Expression FAILED.");
// Execute the on fail behaviour.
throw new DependencyException($this);
} | php | public function execute(Sandbox $sandbox)
{
$language = new ExpressionLanguage($sandbox);
Container::getLogger()->info("Evaluating expression: " . $language->compile($this->expression));
try {
if ($return = $language->evaluate($this->expression)) {
Container::getLogger()->debug(__CLASS__ . ": Expression PASSED: $return");
return $return;
}
}
catch (\Exception $e) {
Container::getLogger()->warning($e->getMessage());
}
Container::getLogger()->debug(__CLASS__ . ": Expression FAILED.");
// Execute the on fail behaviour.
throw new DependencyException($this);
} | [
"public",
"function",
"execute",
"(",
"Sandbox",
"$",
"sandbox",
")",
"{",
"$",
"language",
"=",
"new",
"ExpressionLanguage",
"(",
"$",
"sandbox",
")",
";",
"Container",
"::",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Evaluating expression: \"",
".",
"$",
"language",
"->",
"compile",
"(",
"$",
"this",
"->",
"expression",
")",
")",
";",
"try",
"{",
"if",
"(",
"$",
"return",
"=",
"$",
"language",
"->",
"evaluate",
"(",
"$",
"this",
"->",
"expression",
")",
")",
"{",
"Container",
"::",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"__CLASS__",
".",
"\": Expression PASSED: $return\"",
")",
";",
"return",
"$",
"return",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"Container",
"::",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"Container",
"::",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"__CLASS__",
".",
"\": Expression FAILED.\"",
")",
";",
"// Execute the on fail behaviour.",
"throw",
"new",
"DependencyException",
"(",
"$",
"this",
")",
";",
"}"
] | Evaluate the dependency. | [
"Evaluate",
"the",
"dependency",
"."
] | train | https://github.com/drutiny/drutiny/blob/ba16557024f36e0f2f1612aae7f35cac9f460d81/src/Policy/Dependency.php#L95-L112 |
silverstripe/silverstripe-fulltextsearch | src/Search/Processors/SearchUpdateBatchedProcessor.php | SearchUpdateBatchedProcessor.process | public function process()
{
// Skip blank queues
if (empty($this->batches)) {
return true;
}
// Don't re-process completed queue
if ($this->currentBatch >= count($this->batches)) {
return true;
}
// Send current patch to indexes
$this->prepareIndexes();
// Advance to next batch if successful
$this->setBatch($this->currentBatch + 1);
return true;
} | php | public function process()
{
// Skip blank queues
if (empty($this->batches)) {
return true;
}
// Don't re-process completed queue
if ($this->currentBatch >= count($this->batches)) {
return true;
}
// Send current patch to indexes
$this->prepareIndexes();
// Advance to next batch if successful
$this->setBatch($this->currentBatch + 1);
return true;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"// Skip blank queues",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"batches",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Don't re-process completed queue",
"if",
"(",
"$",
"this",
"->",
"currentBatch",
">=",
"count",
"(",
"$",
"this",
"->",
"batches",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Send current patch to indexes",
"$",
"this",
"->",
"prepareIndexes",
"(",
")",
";",
"// Advance to next batch if successful",
"$",
"this",
"->",
"setBatch",
"(",
"$",
"this",
"->",
"currentBatch",
"+",
"1",
")",
";",
"return",
"true",
";",
"}"
] | Process the current queue
@return boolean | [
"Process",
"the",
"current",
"queue"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Processors/SearchUpdateBatchedProcessor.php#L84-L102 |
silverstripe/silverstripe-fulltextsearch | src/Search/Processors/SearchUpdateBatchedProcessor.php | SearchUpdateBatchedProcessor.segmentBatches | protected function segmentBatches($source)
{
// Measure batch_size
$batchSize = static::config()->get('batch_size');
if ($batchSize === 0) {
return array($source);
}
$softCap = static::config()->get('batch_soft_cap');
// Clear batches
$batches = array();
$current = array();
$currentSize = 0;
// Build batches from data
foreach ($source as $base => $statefulids) {
if (!$statefulids) {
continue;
}
foreach ($statefulids as $stateKey => $statefulid) {
$state = $statefulid['state'];
$ids = $statefulid['ids'];
if (!$ids) {
continue;
}
// Extract items from $ids until empty
while ($ids) {
// Estimate maximum number of items to take for this iteration, allowing for the soft cap
$take = $batchSize - $currentSize;
if (count($ids) <= $take + $softCap) {
$take += $softCap;
}
$items = array_slice($ids, 0, $take, true);
$ids = array_slice($ids, count($items), null, true);
// Update batch
$currentSize += count($items);
$merge = array(
$base => array(
$stateKey => array(
'state' => $state,
'ids' => $items
)
)
);
$current = $current ? array_merge_recursive($current, $merge) : $merge;
if ($currentSize >= $batchSize) {
$batches[] = $current;
$current = array();
$currentSize = 0;
}
}
}
}
// Add incomplete batch
if ($currentSize) {
$batches[] = $current;
}
return $batches;
} | php | protected function segmentBatches($source)
{
// Measure batch_size
$batchSize = static::config()->get('batch_size');
if ($batchSize === 0) {
return array($source);
}
$softCap = static::config()->get('batch_soft_cap');
// Clear batches
$batches = array();
$current = array();
$currentSize = 0;
// Build batches from data
foreach ($source as $base => $statefulids) {
if (!$statefulids) {
continue;
}
foreach ($statefulids as $stateKey => $statefulid) {
$state = $statefulid['state'];
$ids = $statefulid['ids'];
if (!$ids) {
continue;
}
// Extract items from $ids until empty
while ($ids) {
// Estimate maximum number of items to take for this iteration, allowing for the soft cap
$take = $batchSize - $currentSize;
if (count($ids) <= $take + $softCap) {
$take += $softCap;
}
$items = array_slice($ids, 0, $take, true);
$ids = array_slice($ids, count($items), null, true);
// Update batch
$currentSize += count($items);
$merge = array(
$base => array(
$stateKey => array(
'state' => $state,
'ids' => $items
)
)
);
$current = $current ? array_merge_recursive($current, $merge) : $merge;
if ($currentSize >= $batchSize) {
$batches[] = $current;
$current = array();
$currentSize = 0;
}
}
}
}
// Add incomplete batch
if ($currentSize) {
$batches[] = $current;
}
return $batches;
} | [
"protected",
"function",
"segmentBatches",
"(",
"$",
"source",
")",
"{",
"// Measure batch_size",
"$",
"batchSize",
"=",
"static",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'batch_size'",
")",
";",
"if",
"(",
"$",
"batchSize",
"===",
"0",
")",
"{",
"return",
"array",
"(",
"$",
"source",
")",
";",
"}",
"$",
"softCap",
"=",
"static",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'batch_soft_cap'",
")",
";",
"// Clear batches",
"$",
"batches",
"=",
"array",
"(",
")",
";",
"$",
"current",
"=",
"array",
"(",
")",
";",
"$",
"currentSize",
"=",
"0",
";",
"// Build batches from data",
"foreach",
"(",
"$",
"source",
"as",
"$",
"base",
"=>",
"$",
"statefulids",
")",
"{",
"if",
"(",
"!",
"$",
"statefulids",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"statefulids",
"as",
"$",
"stateKey",
"=>",
"$",
"statefulid",
")",
"{",
"$",
"state",
"=",
"$",
"statefulid",
"[",
"'state'",
"]",
";",
"$",
"ids",
"=",
"$",
"statefulid",
"[",
"'ids'",
"]",
";",
"if",
"(",
"!",
"$",
"ids",
")",
"{",
"continue",
";",
"}",
"// Extract items from $ids until empty",
"while",
"(",
"$",
"ids",
")",
"{",
"// Estimate maximum number of items to take for this iteration, allowing for the soft cap",
"$",
"take",
"=",
"$",
"batchSize",
"-",
"$",
"currentSize",
";",
"if",
"(",
"count",
"(",
"$",
"ids",
")",
"<=",
"$",
"take",
"+",
"$",
"softCap",
")",
"{",
"$",
"take",
"+=",
"$",
"softCap",
";",
"}",
"$",
"items",
"=",
"array_slice",
"(",
"$",
"ids",
",",
"0",
",",
"$",
"take",
",",
"true",
")",
";",
"$",
"ids",
"=",
"array_slice",
"(",
"$",
"ids",
",",
"count",
"(",
"$",
"items",
")",
",",
"null",
",",
"true",
")",
";",
"// Update batch",
"$",
"currentSize",
"+=",
"count",
"(",
"$",
"items",
")",
";",
"$",
"merge",
"=",
"array",
"(",
"$",
"base",
"=>",
"array",
"(",
"$",
"stateKey",
"=>",
"array",
"(",
"'state'",
"=>",
"$",
"state",
",",
"'ids'",
"=>",
"$",
"items",
")",
")",
")",
";",
"$",
"current",
"=",
"$",
"current",
"?",
"array_merge_recursive",
"(",
"$",
"current",
",",
"$",
"merge",
")",
":",
"$",
"merge",
";",
"if",
"(",
"$",
"currentSize",
">=",
"$",
"batchSize",
")",
"{",
"$",
"batches",
"[",
"]",
"=",
"$",
"current",
";",
"$",
"current",
"=",
"array",
"(",
")",
";",
"$",
"currentSize",
"=",
"0",
";",
"}",
"}",
"}",
"}",
"// Add incomplete batch",
"if",
"(",
"$",
"currentSize",
")",
"{",
"$",
"batches",
"[",
"]",
"=",
"$",
"current",
";",
"}",
"return",
"$",
"batches",
";",
"}"
] | Segments batches acording to the specified rules
@param array $source Source input
@return array Batches | [
"Segments",
"batches",
"acording",
"to",
"the",
"specified",
"rules"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Processors/SearchUpdateBatchedProcessor.php#L110-L172 |
silverstripe/silverstripe-fulltextsearch | src/Search/Extensions/SearchUpdater_ObjectHandler.php | SearchUpdater_ObjectHandler.triggerReindex | public function triggerReindex()
{
if (!$this->owner->ID) {
return;
}
$id = $this->owner->ID;
$class = $this->owner->ClassName;
$state = SearchVariant::current_state($class);
$base = DataObject::getSchema()->baseDataClass($class);
$key = "$id:$base:" . serialize($state);
$statefulids = array(array(
'id' => $id,
'state' => $state
));
$writes = array(
$key => array(
'base' => $base,
'class' => $class,
'id' => $id,
'statefulids' => $statefulids,
'fields' => array()
)
);
SearchUpdater::process_writes($writes);
} | php | public function triggerReindex()
{
if (!$this->owner->ID) {
return;
}
$id = $this->owner->ID;
$class = $this->owner->ClassName;
$state = SearchVariant::current_state($class);
$base = DataObject::getSchema()->baseDataClass($class);
$key = "$id:$base:" . serialize($state);
$statefulids = array(array(
'id' => $id,
'state' => $state
));
$writes = array(
$key => array(
'base' => $base,
'class' => $class,
'id' => $id,
'statefulids' => $statefulids,
'fields' => array()
)
);
SearchUpdater::process_writes($writes);
} | [
"public",
"function",
"triggerReindex",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"owner",
"->",
"ID",
")",
"{",
"return",
";",
"}",
"$",
"id",
"=",
"$",
"this",
"->",
"owner",
"->",
"ID",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"owner",
"->",
"ClassName",
";",
"$",
"state",
"=",
"SearchVariant",
"::",
"current_state",
"(",
"$",
"class",
")",
";",
"$",
"base",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"baseDataClass",
"(",
"$",
"class",
")",
";",
"$",
"key",
"=",
"\"$id:$base:\"",
".",
"serialize",
"(",
"$",
"state",
")",
";",
"$",
"statefulids",
"=",
"array",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'state'",
"=>",
"$",
"state",
")",
")",
";",
"$",
"writes",
"=",
"array",
"(",
"$",
"key",
"=>",
"array",
"(",
"'base'",
"=>",
"$",
"base",
",",
"'class'",
"=>",
"$",
"class",
",",
"'id'",
"=>",
"$",
"id",
",",
"'statefulids'",
"=>",
"$",
"statefulids",
",",
"'fields'",
"=>",
"array",
"(",
")",
")",
")",
";",
"SearchUpdater",
"::",
"process_writes",
"(",
"$",
"writes",
")",
";",
"}"
] | Forces this object to trigger a re-index in the current state | [
"Forces",
"this",
"object",
"to",
"trigger",
"a",
"re",
"-",
"index",
"in",
"the",
"current",
"state"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Extensions/SearchUpdater_ObjectHandler.php#L54-L82 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Solr.php | Solr.configure_server | public static function configure_server($options = array())
{
self::$solr_options = array_merge(self::$solr_options, $options);
self::$merged_solr_options = null;
self::$service_singleton = null;
self::$service_core_singletons = array();
} | php | public static function configure_server($options = array())
{
self::$solr_options = array_merge(self::$solr_options, $options);
self::$merged_solr_options = null;
self::$service_singleton = null;
self::$service_core_singletons = array();
} | [
"public",
"static",
"function",
"configure_server",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"self",
"::",
"$",
"solr_options",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"solr_options",
",",
"$",
"options",
")",
";",
"self",
"::",
"$",
"merged_solr_options",
"=",
"null",
";",
"self",
"::",
"$",
"service_singleton",
"=",
"null",
";",
"self",
"::",
"$",
"service_core_singletons",
"=",
"array",
"(",
")",
";",
"}"
] | Update the configuration for Solr. See $solr_options for a discussion of the accepted array keys
@param array $options - The options to update | [
"Update",
"the",
"configuration",
"for",
"Solr",
".",
"See",
"$solr_options",
"for",
"a",
"discussion",
"of",
"the",
"accepted",
"array",
"keys"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Solr.php#L64-L71 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Solr.php | Solr.solr_options | public static function solr_options()
{
if (self::$merged_solr_options) {
return self::$merged_solr_options;
}
$defaults = array(
'host' => 'localhost',
'port' => 8983,
'path' => '/solr',
'version' => '4'
);
// Build some by-version defaults
$version = isset(self::$solr_options['version']) ? self::$solr_options['version'] : $defaults['version'];
/** @var Module $module */
$module = ModuleLoader::getModule('silverstripe/fulltextsearch');
$modulePath = $module->getPath();
if (version_compare($version, '4', '>=')) {
$versionDefaults = [
'service' => Solr4Service::class,
'extraspath' => $modulePath . '/conf/solr/4/extras/',
'templatespath' => $modulePath . '/conf/solr/4/templates/',
];
} else {
$versionDefaults = [
'service' => Solr3Service::class,
'extraspath' => $modulePath . '/conf/solr/3/extras/',
'templatespath' => $modulePath . '/conf/solr/3/templates/',
];
}
return (self::$merged_solr_options = array_merge($defaults, $versionDefaults, self::$solr_options));
} | php | public static function solr_options()
{
if (self::$merged_solr_options) {
return self::$merged_solr_options;
}
$defaults = array(
'host' => 'localhost',
'port' => 8983,
'path' => '/solr',
'version' => '4'
);
// Build some by-version defaults
$version = isset(self::$solr_options['version']) ? self::$solr_options['version'] : $defaults['version'];
/** @var Module $module */
$module = ModuleLoader::getModule('silverstripe/fulltextsearch');
$modulePath = $module->getPath();
if (version_compare($version, '4', '>=')) {
$versionDefaults = [
'service' => Solr4Service::class,
'extraspath' => $modulePath . '/conf/solr/4/extras/',
'templatespath' => $modulePath . '/conf/solr/4/templates/',
];
} else {
$versionDefaults = [
'service' => Solr3Service::class,
'extraspath' => $modulePath . '/conf/solr/3/extras/',
'templatespath' => $modulePath . '/conf/solr/3/templates/',
];
}
return (self::$merged_solr_options = array_merge($defaults, $versionDefaults, self::$solr_options));
} | [
"public",
"static",
"function",
"solr_options",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"merged_solr_options",
")",
"{",
"return",
"self",
"::",
"$",
"merged_solr_options",
";",
"}",
"$",
"defaults",
"=",
"array",
"(",
"'host'",
"=>",
"'localhost'",
",",
"'port'",
"=>",
"8983",
",",
"'path'",
"=>",
"'/solr'",
",",
"'version'",
"=>",
"'4'",
")",
";",
"// Build some by-version defaults",
"$",
"version",
"=",
"isset",
"(",
"self",
"::",
"$",
"solr_options",
"[",
"'version'",
"]",
")",
"?",
"self",
"::",
"$",
"solr_options",
"[",
"'version'",
"]",
":",
"$",
"defaults",
"[",
"'version'",
"]",
";",
"/** @var Module $module */",
"$",
"module",
"=",
"ModuleLoader",
"::",
"getModule",
"(",
"'silverstripe/fulltextsearch'",
")",
";",
"$",
"modulePath",
"=",
"$",
"module",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"version_compare",
"(",
"$",
"version",
",",
"'4'",
",",
"'>='",
")",
")",
"{",
"$",
"versionDefaults",
"=",
"[",
"'service'",
"=>",
"Solr4Service",
"::",
"class",
",",
"'extraspath'",
"=>",
"$",
"modulePath",
".",
"'/conf/solr/4/extras/'",
",",
"'templatespath'",
"=>",
"$",
"modulePath",
".",
"'/conf/solr/4/templates/'",
",",
"]",
";",
"}",
"else",
"{",
"$",
"versionDefaults",
"=",
"[",
"'service'",
"=>",
"Solr3Service",
"::",
"class",
",",
"'extraspath'",
"=>",
"$",
"modulePath",
".",
"'/conf/solr/3/extras/'",
",",
"'templatespath'",
"=>",
"$",
"modulePath",
".",
"'/conf/solr/3/templates/'",
",",
"]",
";",
"}",
"return",
"(",
"self",
"::",
"$",
"merged_solr_options",
"=",
"array_merge",
"(",
"$",
"defaults",
",",
"$",
"versionDefaults",
",",
"self",
"::",
"$",
"solr_options",
")",
")",
";",
"}"
] | Get the configured Solr options with the defaults all merged in
@return array - The merged options | [
"Get",
"the",
"configured",
"Solr",
"options",
"with",
"the",
"defaults",
"all",
"merged",
"in"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Solr.php#L77-L112 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Solr.php | Solr.service | public static function service($core = null)
{
$options = self::solr_options();
if (!self::$service_singleton) {
self::$service_singleton = Injector::inst()->create(
$options['service'],
$options['host'],
$options['port'],
$options['path']
);
}
if ($core) {
if (!isset(self::$service_core_singletons[$core])) {
self::$service_core_singletons[$core] = self::$service_singleton->serviceForCore(
singleton($core)->getIndexName()
);
}
return self::$service_core_singletons[$core];
}
return self::$service_singleton;
} | php | public static function service($core = null)
{
$options = self::solr_options();
if (!self::$service_singleton) {
self::$service_singleton = Injector::inst()->create(
$options['service'],
$options['host'],
$options['port'],
$options['path']
);
}
if ($core) {
if (!isset(self::$service_core_singletons[$core])) {
self::$service_core_singletons[$core] = self::$service_singleton->serviceForCore(
singleton($core)->getIndexName()
);
}
return self::$service_core_singletons[$core];
}
return self::$service_singleton;
} | [
"public",
"static",
"function",
"service",
"(",
"$",
"core",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"self",
"::",
"solr_options",
"(",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"service_singleton",
")",
"{",
"self",
"::",
"$",
"service_singleton",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"$",
"options",
"[",
"'service'",
"]",
",",
"$",
"options",
"[",
"'host'",
"]",
",",
"$",
"options",
"[",
"'port'",
"]",
",",
"$",
"options",
"[",
"'path'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"core",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"service_core_singletons",
"[",
"$",
"core",
"]",
")",
")",
"{",
"self",
"::",
"$",
"service_core_singletons",
"[",
"$",
"core",
"]",
"=",
"self",
"::",
"$",
"service_singleton",
"->",
"serviceForCore",
"(",
"singleton",
"(",
"$",
"core",
")",
"->",
"getIndexName",
"(",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"service_core_singletons",
"[",
"$",
"core",
"]",
";",
"}",
"return",
"self",
"::",
"$",
"service_singleton",
";",
"}"
] | Get a SolrService
@param string $core Optional name of index class
@return SolrService|SolrService_Core | [
"Get",
"a",
"SolrService"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Solr.php#L132-L155 |
silverstripe/silverstripe-fulltextsearch | src/Search/Queries/SearchQuery.php | SearchQuery.addFuzzySearchTerm | public function addFuzzySearchTerm($text, $fields = null, $boost = [])
{
$this->search[] = [
'text' => $text,
'fields' => $fields ? (array) $fields : null,
'boost' => $boost,
'fuzzy' => true
];
return $this;
} | php | public function addFuzzySearchTerm($text, $fields = null, $boost = [])
{
$this->search[] = [
'text' => $text,
'fields' => $fields ? (array) $fields : null,
'boost' => $boost,
'fuzzy' => true
];
return $this;
} | [
"public",
"function",
"addFuzzySearchTerm",
"(",
"$",
"text",
",",
"$",
"fields",
"=",
"null",
",",
"$",
"boost",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"search",
"[",
"]",
"=",
"[",
"'text'",
"=>",
"$",
"text",
",",
"'fields'",
"=>",
"$",
"fields",
"?",
"(",
"array",
")",
"$",
"fields",
":",
"null",
",",
"'boost'",
"=>",
"$",
"boost",
",",
"'fuzzy'",
"=>",
"true",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Similar to {@link addSearchTerm()}, but uses stemming and other similarity algorithms
to find the searched terms. For example, a term "fishing" would also likely find results
containing "fish" or "fisher". Depends on search implementation.
@param string $text See {@link addSearchTerm()}
@param array $fields See {@link addSearchTerm()}
@param array $boost See {@link addSearchTerm()}
@return $this | [
"Similar",
"to",
"{",
"@link",
"addSearchTerm",
"()",
"}",
"but",
"uses",
"stemming",
"and",
"other",
"similarity",
"algorithms",
"to",
"find",
"the",
"searched",
"terms",
".",
"For",
"example",
"a",
"term",
"fishing",
"would",
"also",
"likely",
"find",
"results",
"containing",
"fish",
"or",
"fisher",
".",
"Depends",
"on",
"search",
"implementation",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Queries/SearchQuery.php#L102-L111 |
silverstripe/silverstripe-fulltextsearch | src/Search/Queries/SearchQuery.php | SearchQuery.addFilter | public function addFilter($field, $values)
{
$requires = isset($this->require[$field]) ? $this->require[$field] : [];
$values = is_array($values) ? $values : [$values];
$this->require[$field] = array_merge($requires, $values);
return $this;
} | php | public function addFilter($field, $values)
{
$requires = isset($this->require[$field]) ? $this->require[$field] : [];
$values = is_array($values) ? $values : [$values];
$this->require[$field] = array_merge($requires, $values);
return $this;
} | [
"public",
"function",
"addFilter",
"(",
"$",
"field",
",",
"$",
"values",
")",
"{",
"$",
"requires",
"=",
"isset",
"(",
"$",
"this",
"->",
"require",
"[",
"$",
"field",
"]",
")",
"?",
"$",
"this",
"->",
"require",
"[",
"$",
"field",
"]",
":",
"[",
"]",
";",
"$",
"values",
"=",
"is_array",
"(",
"$",
"values",
")",
"?",
"$",
"values",
":",
"[",
"$",
"values",
"]",
";",
"$",
"this",
"->",
"require",
"[",
"$",
"field",
"]",
"=",
"array_merge",
"(",
"$",
"requires",
",",
"$",
"values",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Similar to {@link addSearchTerm()}, but typically used to further narrow down
based on other facets which don't influence the field relevancy.
@param string $field Composite name of the field
@param mixed $values Scalar value, array of values, or an instance of SearchQuery_Range
@return $this | [
"Similar",
"to",
"{",
"@link",
"addSearchTerm",
"()",
"}",
"but",
"typically",
"used",
"to",
"further",
"narrow",
"down",
"based",
"on",
"other",
"facets",
"which",
"don",
"t",
"influence",
"the",
"field",
"relevancy",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Queries/SearchQuery.php#L151-L157 |
silverstripe/silverstripe-fulltextsearch | src/Search/Queries/SearchQuery.php | SearchQuery.addExclude | public function addExclude($field, $values)
{
$excludes = isset($this->exclude[$field]) ? $this->exclude[$field] : [];
$values = is_array($values) ? $values : [$values];
$this->exclude[$field] = array_merge($excludes, $values);
return $this;
} | php | public function addExclude($field, $values)
{
$excludes = isset($this->exclude[$field]) ? $this->exclude[$field] : [];
$values = is_array($values) ? $values : [$values];
$this->exclude[$field] = array_merge($excludes, $values);
return $this;
} | [
"public",
"function",
"addExclude",
"(",
"$",
"field",
",",
"$",
"values",
")",
"{",
"$",
"excludes",
"=",
"isset",
"(",
"$",
"this",
"->",
"exclude",
"[",
"$",
"field",
"]",
")",
"?",
"$",
"this",
"->",
"exclude",
"[",
"$",
"field",
"]",
":",
"[",
"]",
";",
"$",
"values",
"=",
"is_array",
"(",
"$",
"values",
")",
"?",
"$",
"values",
":",
"[",
"$",
"values",
"]",
";",
"$",
"this",
"->",
"exclude",
"[",
"$",
"field",
"]",
"=",
"array_merge",
"(",
"$",
"excludes",
",",
"$",
"values",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Excludes results which match these criteria, inverse of {@link addFilter()}.
@param string $field
@param mixed $values
@return $this | [
"Excludes",
"results",
"which",
"match",
"these",
"criteria",
"inverse",
"of",
"{",
"@link",
"addFilter",
"()",
"}",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Queries/SearchQuery.php#L174-L180 |
silverstripe/silverstripe-fulltextsearch | src/Search/Queries/SearchQuery.php | SearchQuery.filterBy | public function filterBy(
$target,
$value = null,
$comparison = null,
AbstractSearchQueryWriter $searchQueryWriter = null
) {
if (!$target instanceof SearchCriteriaInterface) {
$target = new SearchCriteria($target, $value, $comparison, $searchQueryWriter);
}
$this->addCriteria($target);
return $target;
} | php | public function filterBy(
$target,
$value = null,
$comparison = null,
AbstractSearchQueryWriter $searchQueryWriter = null
) {
if (!$target instanceof SearchCriteriaInterface) {
$target = new SearchCriteria($target, $value, $comparison, $searchQueryWriter);
}
$this->addCriteria($target);
return $target;
} | [
"public",
"function",
"filterBy",
"(",
"$",
"target",
",",
"$",
"value",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
",",
"AbstractSearchQueryWriter",
"$",
"searchQueryWriter",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"target",
"instanceof",
"SearchCriteriaInterface",
")",
"{",
"$",
"target",
"=",
"new",
"SearchCriteria",
"(",
"$",
"target",
",",
"$",
"value",
",",
"$",
"comparison",
",",
"$",
"searchQueryWriter",
")",
";",
"}",
"$",
"this",
"->",
"addCriteria",
"(",
"$",
"target",
")",
";",
"return",
"$",
"target",
";",
"}"
] | You can pass through a string value, Criteria object, or Criterion object for $target.
String value might be "SiteTree_Title" or whatever field in your index that you're trying to target.
If you require complex filtering then you can build your Criteria object first with multiple layers/levels of
Criteria, and then pass it in here when you're ready.
If you have your own Criterion object that you've created that you want to use, you can also pass that in here.
@param string|SearchCriteriaInterface $target
@param mixed $value
@param string|null $comparison
@param AbstractSearchQueryWriter $searchQueryWriter
@return SearchCriteriaInterface | [
"You",
"can",
"pass",
"through",
"a",
"string",
"value",
"Criteria",
"object",
"or",
"Criterion",
"object",
"for",
"$target",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Queries/SearchQuery.php#L206-L219 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Handlers/SolrReindexBase.php | SolrReindexBase.processIndex | protected function processIndex(
LoggerInterface $logger,
SolrIndex $indexInstance,
$batchSize,
$taskName,
$classes = null
) {
// Filter classes for this index
$indexClasses = $this->getClassesForIndex($indexInstance, $classes);
// Clear all records in this index which do not contain the given classes
$logger->info("Clearing obsolete classes from " . $indexInstance->getIndexName());
$indexInstance->clearObsoleteClasses($indexClasses);
// Build queue for each class
foreach ($indexClasses as $class => $options) {
$includeSubclasses = $options['include_children'];
foreach (SearchVariant::reindex_states($class, $includeSubclasses) as $state) {
$this->processVariant($logger, $indexInstance, $state, $class, $includeSubclasses, $batchSize, $taskName);
}
}
} | php | protected function processIndex(
LoggerInterface $logger,
SolrIndex $indexInstance,
$batchSize,
$taskName,
$classes = null
) {
// Filter classes for this index
$indexClasses = $this->getClassesForIndex($indexInstance, $classes);
// Clear all records in this index which do not contain the given classes
$logger->info("Clearing obsolete classes from " . $indexInstance->getIndexName());
$indexInstance->clearObsoleteClasses($indexClasses);
// Build queue for each class
foreach ($indexClasses as $class => $options) {
$includeSubclasses = $options['include_children'];
foreach (SearchVariant::reindex_states($class, $includeSubclasses) as $state) {
$this->processVariant($logger, $indexInstance, $state, $class, $includeSubclasses, $batchSize, $taskName);
}
}
} | [
"protected",
"function",
"processIndex",
"(",
"LoggerInterface",
"$",
"logger",
",",
"SolrIndex",
"$",
"indexInstance",
",",
"$",
"batchSize",
",",
"$",
"taskName",
",",
"$",
"classes",
"=",
"null",
")",
"{",
"// Filter classes for this index",
"$",
"indexClasses",
"=",
"$",
"this",
"->",
"getClassesForIndex",
"(",
"$",
"indexInstance",
",",
"$",
"classes",
")",
";",
"// Clear all records in this index which do not contain the given classes",
"$",
"logger",
"->",
"info",
"(",
"\"Clearing obsolete classes from \"",
".",
"$",
"indexInstance",
"->",
"getIndexName",
"(",
")",
")",
";",
"$",
"indexInstance",
"->",
"clearObsoleteClasses",
"(",
"$",
"indexClasses",
")",
";",
"// Build queue for each class",
"foreach",
"(",
"$",
"indexClasses",
"as",
"$",
"class",
"=>",
"$",
"options",
")",
"{",
"$",
"includeSubclasses",
"=",
"$",
"options",
"[",
"'include_children'",
"]",
";",
"foreach",
"(",
"SearchVariant",
"::",
"reindex_states",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
")",
"as",
"$",
"state",
")",
"{",
"$",
"this",
"->",
"processVariant",
"(",
"$",
"logger",
",",
"$",
"indexInstance",
",",
"$",
"state",
",",
"$",
"class",
",",
"$",
"includeSubclasses",
",",
"$",
"batchSize",
",",
"$",
"taskName",
")",
";",
"}",
"}",
"}"
] | Process index for a single SolrIndex instance
@param LoggerInterface $logger
@param SolrIndex $indexInstance
@param int $batchSize
@param string $taskName
@param string $classes | [
"Process",
"index",
"for",
"a",
"single",
"SolrIndex",
"instance"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Handlers/SolrReindexBase.php#L36-L58 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Handlers/SolrReindexBase.php | SolrReindexBase.getClassesForIndex | protected function getClassesForIndex(SolrIndex $index, $filterClasses = null)
{
// Get base classes
$classes = $index->getClasses();
if (!$filterClasses) {
return $classes;
}
// Apply filter
if (!is_array($filterClasses)) {
$filterClasses = explode(',', $filterClasses);
}
return array_intersect_key($classes, array_combine($filterClasses, $filterClasses));
} | php | protected function getClassesForIndex(SolrIndex $index, $filterClasses = null)
{
// Get base classes
$classes = $index->getClasses();
if (!$filterClasses) {
return $classes;
}
// Apply filter
if (!is_array($filterClasses)) {
$filterClasses = explode(',', $filterClasses);
}
return array_intersect_key($classes, array_combine($filterClasses, $filterClasses));
} | [
"protected",
"function",
"getClassesForIndex",
"(",
"SolrIndex",
"$",
"index",
",",
"$",
"filterClasses",
"=",
"null",
")",
"{",
"// Get base classes",
"$",
"classes",
"=",
"$",
"index",
"->",
"getClasses",
"(",
")",
";",
"if",
"(",
"!",
"$",
"filterClasses",
")",
"{",
"return",
"$",
"classes",
";",
"}",
"// Apply filter",
"if",
"(",
"!",
"is_array",
"(",
"$",
"filterClasses",
")",
")",
"{",
"$",
"filterClasses",
"=",
"explode",
"(",
"','",
",",
"$",
"filterClasses",
")",
";",
"}",
"return",
"array_intersect_key",
"(",
"$",
"classes",
",",
"array_combine",
"(",
"$",
"filterClasses",
",",
"$",
"filterClasses",
")",
")",
";",
"}"
] | Get valid classes and options for an index with an optional filter
@param SolrIndex $index
@param string|array $filterClasses Optional class or classes to limit to
@return array List of classes, where the key is the classname and value is list of options | [
"Get",
"valid",
"classes",
"and",
"options",
"for",
"an",
"index",
"with",
"an",
"optional",
"filter"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Handlers/SolrReindexBase.php#L67-L80 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Handlers/SolrReindexBase.php | SolrReindexBase.processVariant | protected function processVariant(
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$includeSubclasses,
$batchSize,
$taskName
) {
// Set state
SearchVariant::activate_state($state);
// Count records
$query = $class::get();
if (!$includeSubclasses) {
$query = $query->filter('ClassName', $class);
}
$total = $query->count();
// Skip this variant if nothing to process, or if there are no records
if ($total == 0 || $indexInstance->variantStateExcluded($state)) {
// Remove all records in the current state, since there are no groups to process
$logger->info("Clearing all records of type {$class} in the current state: " . json_encode($state));
$this->clearRecords($indexInstance, $class);
return;
}
// For each group, run processing
$groups = (int)(($total + $batchSize - 1) / $batchSize);
for ($group = 0; $group < $groups; $group++) {
$this->processGroup($logger, $indexInstance, $state, $class, $groups, $group, $taskName);
}
} | php | protected function processVariant(
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$includeSubclasses,
$batchSize,
$taskName
) {
// Set state
SearchVariant::activate_state($state);
// Count records
$query = $class::get();
if (!$includeSubclasses) {
$query = $query->filter('ClassName', $class);
}
$total = $query->count();
// Skip this variant if nothing to process, or if there are no records
if ($total == 0 || $indexInstance->variantStateExcluded($state)) {
// Remove all records in the current state, since there are no groups to process
$logger->info("Clearing all records of type {$class} in the current state: " . json_encode($state));
$this->clearRecords($indexInstance, $class);
return;
}
// For each group, run processing
$groups = (int)(($total + $batchSize - 1) / $batchSize);
for ($group = 0; $group < $groups; $group++) {
$this->processGroup($logger, $indexInstance, $state, $class, $groups, $group, $taskName);
}
} | [
"protected",
"function",
"processVariant",
"(",
"LoggerInterface",
"$",
"logger",
",",
"SolrIndex",
"$",
"indexInstance",
",",
"$",
"state",
",",
"$",
"class",
",",
"$",
"includeSubclasses",
",",
"$",
"batchSize",
",",
"$",
"taskName",
")",
"{",
"// Set state",
"SearchVariant",
"::",
"activate_state",
"(",
"$",
"state",
")",
";",
"// Count records",
"$",
"query",
"=",
"$",
"class",
"::",
"get",
"(",
")",
";",
"if",
"(",
"!",
"$",
"includeSubclasses",
")",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"filter",
"(",
"'ClassName'",
",",
"$",
"class",
")",
";",
"}",
"$",
"total",
"=",
"$",
"query",
"->",
"count",
"(",
")",
";",
"// Skip this variant if nothing to process, or if there are no records",
"if",
"(",
"$",
"total",
"==",
"0",
"||",
"$",
"indexInstance",
"->",
"variantStateExcluded",
"(",
"$",
"state",
")",
")",
"{",
"// Remove all records in the current state, since there are no groups to process",
"$",
"logger",
"->",
"info",
"(",
"\"Clearing all records of type {$class} in the current state: \"",
".",
"json_encode",
"(",
"$",
"state",
")",
")",
";",
"$",
"this",
"->",
"clearRecords",
"(",
"$",
"indexInstance",
",",
"$",
"class",
")",
";",
"return",
";",
"}",
"// For each group, run processing",
"$",
"groups",
"=",
"(",
"int",
")",
"(",
"(",
"$",
"total",
"+",
"$",
"batchSize",
"-",
"1",
")",
"/",
"$",
"batchSize",
")",
";",
"for",
"(",
"$",
"group",
"=",
"0",
";",
"$",
"group",
"<",
"$",
"groups",
";",
"$",
"group",
"++",
")",
"{",
"$",
"this",
"->",
"processGroup",
"(",
"$",
"logger",
",",
"$",
"indexInstance",
",",
"$",
"state",
",",
"$",
"class",
",",
"$",
"groups",
",",
"$",
"group",
",",
"$",
"taskName",
")",
";",
"}",
"}"
] | Process re-index for a given variant state and class
@param LoggerInterface $logger
@param SolrIndex $indexInstance
@param array $state Variant state
@param string $class
@param bool $includeSubclasses
@param int $batchSize
@param string $taskName | [
"Process",
"re",
"-",
"index",
"for",
"a",
"given",
"variant",
"state",
"and",
"class"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Handlers/SolrReindexBase.php#L93-L125 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Handlers/SolrReindexBase.php | SolrReindexBase.runGroup | public function runGroup(
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group
) {
// Set time limit and state
Environment::increaseTimeLimitTo();
SearchVariant::activate_state($state);
$logger->info("Adding $class");
// Prior to adding these records to solr, delete existing solr records
$this->clearRecords($indexInstance, $class, $groups, $group);
// Process selected records in this class
$items = $this->getRecordsInGroup($indexInstance, $class, $groups, $group);
$processed = array();
foreach ($items as $item) {
$processed[] = $item->ID;
// By this point, obsolete classes/states have been removed in processVariant
// and obsolete records have been removed in clearRecords
$indexInstance->add($item);
$item->destroy();
}
$logger->info("Updated " . implode(',', $processed));
// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex
DB::query('SELECT 1');
$logger->info("Done");
} | php | public function runGroup(
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group
) {
// Set time limit and state
Environment::increaseTimeLimitTo();
SearchVariant::activate_state($state);
$logger->info("Adding $class");
// Prior to adding these records to solr, delete existing solr records
$this->clearRecords($indexInstance, $class, $groups, $group);
// Process selected records in this class
$items = $this->getRecordsInGroup($indexInstance, $class, $groups, $group);
$processed = array();
foreach ($items as $item) {
$processed[] = $item->ID;
// By this point, obsolete classes/states have been removed in processVariant
// and obsolete records have been removed in clearRecords
$indexInstance->add($item);
$item->destroy();
}
$logger->info("Updated " . implode(',', $processed));
// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex
DB::query('SELECT 1');
$logger->info("Done");
} | [
"public",
"function",
"runGroup",
"(",
"LoggerInterface",
"$",
"logger",
",",
"SolrIndex",
"$",
"indexInstance",
",",
"$",
"state",
",",
"$",
"class",
",",
"$",
"groups",
",",
"$",
"group",
")",
"{",
"// Set time limit and state",
"Environment",
"::",
"increaseTimeLimitTo",
"(",
")",
";",
"SearchVariant",
"::",
"activate_state",
"(",
"$",
"state",
")",
";",
"$",
"logger",
"->",
"info",
"(",
"\"Adding $class\"",
")",
";",
"// Prior to adding these records to solr, delete existing solr records",
"$",
"this",
"->",
"clearRecords",
"(",
"$",
"indexInstance",
",",
"$",
"class",
",",
"$",
"groups",
",",
"$",
"group",
")",
";",
"// Process selected records in this class",
"$",
"items",
"=",
"$",
"this",
"->",
"getRecordsInGroup",
"(",
"$",
"indexInstance",
",",
"$",
"class",
",",
"$",
"groups",
",",
"$",
"group",
")",
";",
"$",
"processed",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"processed",
"[",
"]",
"=",
"$",
"item",
"->",
"ID",
";",
"// By this point, obsolete classes/states have been removed in processVariant",
"// and obsolete records have been removed in clearRecords",
"$",
"indexInstance",
"->",
"add",
"(",
"$",
"item",
")",
";",
"$",
"item",
"->",
"destroy",
"(",
")",
";",
"}",
"$",
"logger",
"->",
"info",
"(",
"\"Updated \"",
".",
"implode",
"(",
"','",
",",
"$",
"processed",
")",
")",
";",
"// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex",
"DB",
"::",
"query",
"(",
"'SELECT 1'",
")",
";",
"$",
"logger",
"->",
"info",
"(",
"\"Done\"",
")",
";",
"}"
] | Explicitly invoke the process that performs the group
processing. Can be run either by a background task or a queuedjob.
Does not commit changes to the index, so this must be controlled externally.
@param LoggerInterface $logger
@param SolrIndex $indexInstance
@param array $state
@param string $class
@param int $groups
@param int $group | [
"Explicitly",
"invoke",
"the",
"process",
"that",
"performs",
"the",
"group",
"processing",
".",
"Can",
"be",
"run",
"either",
"by",
"a",
"background",
"task",
"or",
"a",
"queuedjob",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Handlers/SolrReindexBase.php#L161-L194 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Handlers/SolrReindexBase.php | SolrReindexBase.getRecordsInGroup | protected function getRecordsInGroup(SolrIndex $indexInstance, $class, $groups, $group)
{
// Generate filtered list of local records
$baseClass = DataObject::getSchema()->baseDataClass($class);
$items = DataList::create($class)
->where(sprintf(
'"%s"."ID" %% \'%d\' = \'%d\'',
DataObject::getSchema()->tableName($baseClass),
intval($groups),
intval($group)
))
->sort("ID");
// Add child filter
$classes = $indexInstance->getClasses();
$options = $classes[$class];
if (!$options['include_children']) {
$items = $items->filter('ClassName', $class);
}
return $items;
} | php | protected function getRecordsInGroup(SolrIndex $indexInstance, $class, $groups, $group)
{
// Generate filtered list of local records
$baseClass = DataObject::getSchema()->baseDataClass($class);
$items = DataList::create($class)
->where(sprintf(
'"%s"."ID" %% \'%d\' = \'%d\'',
DataObject::getSchema()->tableName($baseClass),
intval($groups),
intval($group)
))
->sort("ID");
// Add child filter
$classes = $indexInstance->getClasses();
$options = $classes[$class];
if (!$options['include_children']) {
$items = $items->filter('ClassName', $class);
}
return $items;
} | [
"protected",
"function",
"getRecordsInGroup",
"(",
"SolrIndex",
"$",
"indexInstance",
",",
"$",
"class",
",",
"$",
"groups",
",",
"$",
"group",
")",
"{",
"// Generate filtered list of local records",
"$",
"baseClass",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"baseDataClass",
"(",
"$",
"class",
")",
";",
"$",
"items",
"=",
"DataList",
"::",
"create",
"(",
"$",
"class",
")",
"->",
"where",
"(",
"sprintf",
"(",
"'\"%s\".\"ID\" %% \\'%d\\' = \\'%d\\''",
",",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableName",
"(",
"$",
"baseClass",
")",
",",
"intval",
"(",
"$",
"groups",
")",
",",
"intval",
"(",
"$",
"group",
")",
")",
")",
"->",
"sort",
"(",
"\"ID\"",
")",
";",
"// Add child filter",
"$",
"classes",
"=",
"$",
"indexInstance",
"->",
"getClasses",
"(",
")",
";",
"$",
"options",
"=",
"$",
"classes",
"[",
"$",
"class",
"]",
";",
"if",
"(",
"!",
"$",
"options",
"[",
"'include_children'",
"]",
")",
"{",
"$",
"items",
"=",
"$",
"items",
"->",
"filter",
"(",
"'ClassName'",
",",
"$",
"class",
")",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Gets the datalist of records in the given group in the current state
Assumes that the desired variant state is in effect.
@param SolrIndex $indexInstance
@param string $class
@param int $groups
@param int $group
@return DataList | [
"Gets",
"the",
"datalist",
"of",
"records",
"in",
"the",
"given",
"group",
"in",
"the",
"current",
"state"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Handlers/SolrReindexBase.php#L207-L228 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Handlers/SolrReindexBase.php | SolrReindexBase.clearRecords | protected function clearRecords(SolrIndex $indexInstance, $class, $groups = null, $group = null)
{
// Clear by classname
$conditions = array("+(ClassHierarchy:{$class})");
// If grouping, delete from this group only
if ($groups) {
$conditions[] = "+_query_:\"{!frange l={$group} u={$group}}mod(ID, {$groups})\"";
}
// Also filter by state (suffix on document ID)
$query = new SearchQuery();
SearchVariant::with($class)
->call('alterQuery', $query, $indexInstance);
if ($query->isfiltered()) {
$conditions = array_merge($conditions, $indexInstance->getFiltersComponent($query));
}
// Invoke delete on index
$deleteQuery = implode(' ', $conditions);
$indexInstance
->getService()
->deleteByQuery($deleteQuery);
} | php | protected function clearRecords(SolrIndex $indexInstance, $class, $groups = null, $group = null)
{
// Clear by classname
$conditions = array("+(ClassHierarchy:{$class})");
// If grouping, delete from this group only
if ($groups) {
$conditions[] = "+_query_:\"{!frange l={$group} u={$group}}mod(ID, {$groups})\"";
}
// Also filter by state (suffix on document ID)
$query = new SearchQuery();
SearchVariant::with($class)
->call('alterQuery', $query, $indexInstance);
if ($query->isfiltered()) {
$conditions = array_merge($conditions, $indexInstance->getFiltersComponent($query));
}
// Invoke delete on index
$deleteQuery = implode(' ', $conditions);
$indexInstance
->getService()
->deleteByQuery($deleteQuery);
} | [
"protected",
"function",
"clearRecords",
"(",
"SolrIndex",
"$",
"indexInstance",
",",
"$",
"class",
",",
"$",
"groups",
"=",
"null",
",",
"$",
"group",
"=",
"null",
")",
"{",
"// Clear by classname",
"$",
"conditions",
"=",
"array",
"(",
"\"+(ClassHierarchy:{$class})\"",
")",
";",
"// If grouping, delete from this group only",
"if",
"(",
"$",
"groups",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"+_query_:\\\"{!frange l={$group} u={$group}}mod(ID, {$groups})\\\"\"",
";",
"}",
"// Also filter by state (suffix on document ID)",
"$",
"query",
"=",
"new",
"SearchQuery",
"(",
")",
";",
"SearchVariant",
"::",
"with",
"(",
"$",
"class",
")",
"->",
"call",
"(",
"'alterQuery'",
",",
"$",
"query",
",",
"$",
"indexInstance",
")",
";",
"if",
"(",
"$",
"query",
"->",
"isfiltered",
"(",
")",
")",
"{",
"$",
"conditions",
"=",
"array_merge",
"(",
"$",
"conditions",
",",
"$",
"indexInstance",
"->",
"getFiltersComponent",
"(",
"$",
"query",
")",
")",
";",
"}",
"// Invoke delete on index",
"$",
"deleteQuery",
"=",
"implode",
"(",
"' '",
",",
"$",
"conditions",
")",
";",
"$",
"indexInstance",
"->",
"getService",
"(",
")",
"->",
"deleteByQuery",
"(",
"$",
"deleteQuery",
")",
";",
"}"
] | Clear all records of the given class in the current state ONLY.
Optionally delete from a given group (where the group is defined as the ID % total groups)
@param SolrIndex $indexInstance Index instance
@param string $class Class name
@param int $groups Number of groups, if clearing from a striped group
@param int $group Group number, if clearing from a striped group | [
"Clear",
"all",
"records",
"of",
"the",
"given",
"class",
"in",
"the",
"current",
"state",
"ONLY",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Handlers/SolrReindexBase.php#L240-L263 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Handlers/SolrReindexQueuedHandler.php | SolrReindexQueuedHandler.cancelExistingJobs | protected function cancelExistingJobs($type)
{
$clearable = array(
// Paused jobs need to be discarded
QueuedJob::STATUS_PAUSED,
// These types would be automatically started
QueuedJob::STATUS_NEW,
QueuedJob::STATUS_WAIT,
// Cancel any in-progress job
QueuedJob::STATUS_INIT,
QueuedJob::STATUS_RUN
);
DB::query(sprintf(
'UPDATE "%s" '
. ' SET "JobStatus" = \'%s\''
. ' WHERE "JobStatus" IN (\'%s\')'
. ' AND "Implementation" = \'%s\'',
Convert::raw2sql(DataObject::getSchema()->tableName(QueuedJobDescriptor::class)),
Convert::raw2sql(QueuedJob::STATUS_CANCELLED),
implode("','", Convert::raw2sql($clearable)),
Convert::raw2sql($type)
));
return DB::affected_rows();
} | php | protected function cancelExistingJobs($type)
{
$clearable = array(
// Paused jobs need to be discarded
QueuedJob::STATUS_PAUSED,
// These types would be automatically started
QueuedJob::STATUS_NEW,
QueuedJob::STATUS_WAIT,
// Cancel any in-progress job
QueuedJob::STATUS_INIT,
QueuedJob::STATUS_RUN
);
DB::query(sprintf(
'UPDATE "%s" '
. ' SET "JobStatus" = \'%s\''
. ' WHERE "JobStatus" IN (\'%s\')'
. ' AND "Implementation" = \'%s\'',
Convert::raw2sql(DataObject::getSchema()->tableName(QueuedJobDescriptor::class)),
Convert::raw2sql(QueuedJob::STATUS_CANCELLED),
implode("','", Convert::raw2sql($clearable)),
Convert::raw2sql($type)
));
return DB::affected_rows();
} | [
"protected",
"function",
"cancelExistingJobs",
"(",
"$",
"type",
")",
"{",
"$",
"clearable",
"=",
"array",
"(",
"// Paused jobs need to be discarded",
"QueuedJob",
"::",
"STATUS_PAUSED",
",",
"// These types would be automatically started",
"QueuedJob",
"::",
"STATUS_NEW",
",",
"QueuedJob",
"::",
"STATUS_WAIT",
",",
"// Cancel any in-progress job",
"QueuedJob",
"::",
"STATUS_INIT",
",",
"QueuedJob",
"::",
"STATUS_RUN",
")",
";",
"DB",
"::",
"query",
"(",
"sprintf",
"(",
"'UPDATE \"%s\" '",
".",
"' SET \"JobStatus\" = \\'%s\\''",
".",
"' WHERE \"JobStatus\" IN (\\'%s\\')'",
".",
"' AND \"Implementation\" = \\'%s\\''",
",",
"Convert",
"::",
"raw2sql",
"(",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableName",
"(",
"QueuedJobDescriptor",
"::",
"class",
")",
")",
",",
"Convert",
"::",
"raw2sql",
"(",
"QueuedJob",
"::",
"STATUS_CANCELLED",
")",
",",
"implode",
"(",
"\"','\"",
",",
"Convert",
"::",
"raw2sql",
"(",
"$",
"clearable",
")",
")",
",",
"Convert",
"::",
"raw2sql",
"(",
"$",
"type",
")",
")",
")",
";",
"return",
"DB",
"::",
"affected_rows",
"(",
")",
";",
"}"
] | Cancel any cancellable jobs
@param string $type Type of job to cancel
@return int Number of jobs cleared | [
"Cancel",
"any",
"cancellable",
"jobs"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Handlers/SolrReindexQueuedHandler.php#L41-L66 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Writers/SolrSearchQueryWriterRange.php | SolrSearchQueryWriterRange.getLeftComparison | protected function getLeftComparison(SearchCriterion $searchCriterion)
{
switch ($searchCriterion->getComparison()) {
case SearchCriterion::GREATER_EQUAL:
case SearchCriterion::GREATER_THAN:
return $searchCriterion->getValue();
case SearchCriterion::ISNULL:
case SearchCriterion::ISNOTNULL:
case SearchCriterion::LESS_EQUAL:
case SearchCriterion::LESS_THAN:
return '*';
default:
throw new InvalidArgumentException('Invalid comparison for RangeCriterion');
}
} | php | protected function getLeftComparison(SearchCriterion $searchCriterion)
{
switch ($searchCriterion->getComparison()) {
case SearchCriterion::GREATER_EQUAL:
case SearchCriterion::GREATER_THAN:
return $searchCriterion->getValue();
case SearchCriterion::ISNULL:
case SearchCriterion::ISNOTNULL:
case SearchCriterion::LESS_EQUAL:
case SearchCriterion::LESS_THAN:
return '*';
default:
throw new InvalidArgumentException('Invalid comparison for RangeCriterion');
}
} | [
"protected",
"function",
"getLeftComparison",
"(",
"SearchCriterion",
"$",
"searchCriterion",
")",
"{",
"switch",
"(",
"$",
"searchCriterion",
"->",
"getComparison",
"(",
")",
")",
"{",
"case",
"SearchCriterion",
"::",
"GREATER_EQUAL",
":",
"case",
"SearchCriterion",
"::",
"GREATER_THAN",
":",
"return",
"$",
"searchCriterion",
"->",
"getValue",
"(",
")",
";",
"case",
"SearchCriterion",
"::",
"ISNULL",
":",
"case",
"SearchCriterion",
"::",
"ISNOTNULL",
":",
"case",
"SearchCriterion",
"::",
"LESS_EQUAL",
":",
"case",
"SearchCriterion",
"::",
"LESS_THAN",
":",
"return",
"'*'",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid comparison for RangeCriterion'",
")",
";",
"}",
"}"
] | Select the value that we want as our left comparison value.
@param SearchCriterion $searchCriterion
@return mixed|string
@throws InvalidArgumentException | [
"Select",
"the",
"value",
"that",
"we",
"want",
"as",
"our",
"left",
"comparison",
"value",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Writers/SolrSearchQueryWriterRange.php#L56-L70 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Writers/SolrSearchQueryWriterRange.php | SolrSearchQueryWriterRange.getOpenComparisonContainer | protected function getOpenComparisonContainer($comparison)
{
switch ($comparison) {
case SearchCriterion::GREATER_EQUAL:
case SearchCriterion::LESS_EQUAL:
case SearchCriterion::ISNULL:
case SearchCriterion::ISNOTNULL:
return '[';
case SearchCriterion::GREATER_THAN:
case SearchCriterion::LESS_THAN:
return '{';
default:
throw new InvalidArgumentException('Invalid comparison for RangeCriterion');
}
} | php | protected function getOpenComparisonContainer($comparison)
{
switch ($comparison) {
case SearchCriterion::GREATER_EQUAL:
case SearchCriterion::LESS_EQUAL:
case SearchCriterion::ISNULL:
case SearchCriterion::ISNOTNULL:
return '[';
case SearchCriterion::GREATER_THAN:
case SearchCriterion::LESS_THAN:
return '{';
default:
throw new InvalidArgumentException('Invalid comparison for RangeCriterion');
}
} | [
"protected",
"function",
"getOpenComparisonContainer",
"(",
"$",
"comparison",
")",
"{",
"switch",
"(",
"$",
"comparison",
")",
"{",
"case",
"SearchCriterion",
"::",
"GREATER_EQUAL",
":",
"case",
"SearchCriterion",
"::",
"LESS_EQUAL",
":",
"case",
"SearchCriterion",
"::",
"ISNULL",
":",
"case",
"SearchCriterion",
"::",
"ISNOTNULL",
":",
"return",
"'['",
";",
"case",
"SearchCriterion",
"::",
"GREATER_THAN",
":",
"case",
"SearchCriterion",
"::",
"LESS_THAN",
":",
"return",
"'{'",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid comparison for RangeCriterion'",
")",
";",
"}",
"}"
] | Does our comparison need a container? EG: "[* TO *]"? If so, return the opening container brace.
@param string $comparison
@return string
@throws InvalidArgumentException | [
"Does",
"our",
"comparison",
"need",
"a",
"container?",
"EG",
":",
"[",
"*",
"TO",
"*",
"]",
"?",
"If",
"so",
"return",
"the",
"opening",
"container",
"brace",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Writers/SolrSearchQueryWriterRange.php#L112-L126 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Jobs/SolrReindexQueuedJobBase.php | SolrReindexQueuedJobBase.getLogger | protected function getLogger()
{
if ($this->logger) {
return $this->logger;
}
// Set logger for this job
$this->logger = $this
->getLoggerFactory()
->getQueuedJobLogger($this);
return $this->logger;
} | php | protected function getLogger()
{
if ($this->logger) {
return $this->logger;
}
// Set logger for this job
$this->logger = $this
->getLoggerFactory()
->getQueuedJobLogger($this);
return $this->logger;
} | [
"protected",
"function",
"getLogger",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
")",
"{",
"return",
"$",
"this",
"->",
"logger",
";",
"}",
"// Set logger for this job",
"$",
"this",
"->",
"logger",
"=",
"$",
"this",
"->",
"getLoggerFactory",
"(",
")",
"->",
"getQueuedJobLogger",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
"->",
"logger",
";",
"}"
] | Gets a logger for this job
@return LoggerInterface | [
"Gets",
"a",
"logger",
"for",
"this",
"job"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Jobs/SolrReindexQueuedJobBase.php#L62-L73 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Reindex/Handlers/SolrReindexImmediateHandler.php | SolrReindexImmediateHandler.processGroup | protected function processGroup(
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group,
$taskName
) {
$indexClass = get_class($indexInstance);
// Build script parameters
$indexClassEscaped = $indexClass;
$statevar = json_encode($state);
if (strpos(PHP_OS, "WIN") !== false) {
$statevar = '"' . str_replace('"', '\\"', $statevar) . '"';
} else {
$statevar = "'" . $statevar . "'";
$class = addslashes($class);
$indexClassEscaped = addslashes($indexClass);
}
$php = Environment::getEnv('SS_PHP_BIN') ?: Config::inst()->get(static::class, 'php_bin');
// Build script line
$frameworkPath = ModuleLoader::getModule('silverstripe/framework')->getPath();
$scriptPath = sprintf("%s%scli-script.php", $frameworkPath, DIRECTORY_SEPARATOR);
$scriptTask = "{$php} {$scriptPath} dev/tasks/{$taskName}";
$cmd = "{$scriptTask} index={$indexClassEscaped} class={$class} group={$group} groups={$groups} variantstate={$statevar}";
$cmd .= " verbose=1";
$logger->info("Running '$cmd'");
// Execute script via shell
$process = new Process($cmd);
// Set timeout from config. Process default is 60 seconds
$process->setTimeout($this->config()->get('process_timeout'));
$process->inheritEnvironmentVariables();
$process->run();
$res = $process->getOutput();
if ($logger) {
$logger->info(preg_replace('/\r\n|\n/', '$0 ', $res));
}
// If we're in dev mode, commit more often for fun and profit
if (Director::isDev()) {
Solr::service($indexClass)->commit();
}
// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex
DB::query('SELECT 1');
} | php | protected function processGroup(
LoggerInterface $logger,
SolrIndex $indexInstance,
$state,
$class,
$groups,
$group,
$taskName
) {
$indexClass = get_class($indexInstance);
// Build script parameters
$indexClassEscaped = $indexClass;
$statevar = json_encode($state);
if (strpos(PHP_OS, "WIN") !== false) {
$statevar = '"' . str_replace('"', '\\"', $statevar) . '"';
} else {
$statevar = "'" . $statevar . "'";
$class = addslashes($class);
$indexClassEscaped = addslashes($indexClass);
}
$php = Environment::getEnv('SS_PHP_BIN') ?: Config::inst()->get(static::class, 'php_bin');
// Build script line
$frameworkPath = ModuleLoader::getModule('silverstripe/framework')->getPath();
$scriptPath = sprintf("%s%scli-script.php", $frameworkPath, DIRECTORY_SEPARATOR);
$scriptTask = "{$php} {$scriptPath} dev/tasks/{$taskName}";
$cmd = "{$scriptTask} index={$indexClassEscaped} class={$class} group={$group} groups={$groups} variantstate={$statevar}";
$cmd .= " verbose=1";
$logger->info("Running '$cmd'");
// Execute script via shell
$process = new Process($cmd);
// Set timeout from config. Process default is 60 seconds
$process->setTimeout($this->config()->get('process_timeout'));
$process->inheritEnvironmentVariables();
$process->run();
$res = $process->getOutput();
if ($logger) {
$logger->info(preg_replace('/\r\n|\n/', '$0 ', $res));
}
// If we're in dev mode, commit more often for fun and profit
if (Director::isDev()) {
Solr::service($indexClass)->commit();
}
// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex
DB::query('SELECT 1');
} | [
"protected",
"function",
"processGroup",
"(",
"LoggerInterface",
"$",
"logger",
",",
"SolrIndex",
"$",
"indexInstance",
",",
"$",
"state",
",",
"$",
"class",
",",
"$",
"groups",
",",
"$",
"group",
",",
"$",
"taskName",
")",
"{",
"$",
"indexClass",
"=",
"get_class",
"(",
"$",
"indexInstance",
")",
";",
"// Build script parameters",
"$",
"indexClassEscaped",
"=",
"$",
"indexClass",
";",
"$",
"statevar",
"=",
"json_encode",
"(",
"$",
"state",
")",
";",
"if",
"(",
"strpos",
"(",
"PHP_OS",
",",
"\"WIN\"",
")",
"!==",
"false",
")",
"{",
"$",
"statevar",
"=",
"'\"'",
".",
"str_replace",
"(",
"'\"'",
",",
"'\\\\\"'",
",",
"$",
"statevar",
")",
".",
"'\"'",
";",
"}",
"else",
"{",
"$",
"statevar",
"=",
"\"'\"",
".",
"$",
"statevar",
".",
"\"'\"",
";",
"$",
"class",
"=",
"addslashes",
"(",
"$",
"class",
")",
";",
"$",
"indexClassEscaped",
"=",
"addslashes",
"(",
"$",
"indexClass",
")",
";",
"}",
"$",
"php",
"=",
"Environment",
"::",
"getEnv",
"(",
"'SS_PHP_BIN'",
")",
"?",
":",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"static",
"::",
"class",
",",
"'php_bin'",
")",
";",
"// Build script line",
"$",
"frameworkPath",
"=",
"ModuleLoader",
"::",
"getModule",
"(",
"'silverstripe/framework'",
")",
"->",
"getPath",
"(",
")",
";",
"$",
"scriptPath",
"=",
"sprintf",
"(",
"\"%s%scli-script.php\"",
",",
"$",
"frameworkPath",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"$",
"scriptTask",
"=",
"\"{$php} {$scriptPath} dev/tasks/{$taskName}\"",
";",
"$",
"cmd",
"=",
"\"{$scriptTask} index={$indexClassEscaped} class={$class} group={$group} groups={$groups} variantstate={$statevar}\"",
";",
"$",
"cmd",
".=",
"\" verbose=1\"",
";",
"$",
"logger",
"->",
"info",
"(",
"\"Running '$cmd'\"",
")",
";",
"// Execute script via shell",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"cmd",
")",
";",
"// Set timeout from config. Process default is 60 seconds",
"$",
"process",
"->",
"setTimeout",
"(",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'process_timeout'",
")",
")",
";",
"$",
"process",
"->",
"inheritEnvironmentVariables",
"(",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"$",
"res",
"=",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"if",
"(",
"$",
"logger",
")",
"{",
"$",
"logger",
"->",
"info",
"(",
"preg_replace",
"(",
"'/\\r\\n|\\n/'",
",",
"'$0 '",
",",
"$",
"res",
")",
")",
";",
"}",
"// If we're in dev mode, commit more often for fun and profit",
"if",
"(",
"Director",
"::",
"isDev",
"(",
")",
")",
"{",
"Solr",
"::",
"service",
"(",
"$",
"indexClass",
")",
"->",
"commit",
"(",
")",
";",
"}",
"// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex",
"DB",
"::",
"query",
"(",
"'SELECT 1'",
")",
";",
"}"
] | Process a single group.
Without queuedjobs, it's necessary to shell this out to a background task as this is
very memory intensive.
The sub-process will then invoke $processor->runGroup() in {@see Solr_Reindex::doReindex}
@param LoggerInterface $logger
@param SolrIndex $indexInstance Index instance
@param array $state Variant state
@param string $class Class to index
@param int $groups Total groups
@param int $group Index of group to process
@param string $taskName Name of task script to run | [
"Process",
"a",
"single",
"group",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Reindex/Handlers/SolrReindexImmediateHandler.php#L68-L123 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Control/ContentControllerExtension.php | ContentControllerExtension.SearchForm | public function SearchForm()
{
$searchText = _t('SilverStripe\\CMS\\Search\\SearchForm.SEARCH', 'Search');
/** @var HTTPRequest $currentRequest */
$currentRequest = $this->owner->getRequest();
if ($currentRequest && $currentRequest->getVar('Search')) {
$searchText = $currentRequest->getVar('Search');
}
$fields = FieldList::create(
TextField::create('Search', false, $searchText)
);
$actions = FieldList::create(
FormAction::create('results', _t('SilverStripe\\CMS\\Search\\SearchForm.GO', 'Go'))
);
return SearchForm::create($this->owner, 'SearchForm', $fields, $actions);
} | php | public function SearchForm()
{
$searchText = _t('SilverStripe\\CMS\\Search\\SearchForm.SEARCH', 'Search');
/** @var HTTPRequest $currentRequest */
$currentRequest = $this->owner->getRequest();
if ($currentRequest && $currentRequest->getVar('Search')) {
$searchText = $currentRequest->getVar('Search');
}
$fields = FieldList::create(
TextField::create('Search', false, $searchText)
);
$actions = FieldList::create(
FormAction::create('results', _t('SilverStripe\\CMS\\Search\\SearchForm.GO', 'Go'))
);
return SearchForm::create($this->owner, 'SearchForm', $fields, $actions);
} | [
"public",
"function",
"SearchForm",
"(",
")",
"{",
"$",
"searchText",
"=",
"_t",
"(",
"'SilverStripe\\\\CMS\\\\Search\\\\SearchForm.SEARCH'",
",",
"'Search'",
")",
";",
"/** @var HTTPRequest $currentRequest */",
"$",
"currentRequest",
"=",
"$",
"this",
"->",
"owner",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"currentRequest",
"&&",
"$",
"currentRequest",
"->",
"getVar",
"(",
"'Search'",
")",
")",
"{",
"$",
"searchText",
"=",
"$",
"currentRequest",
"->",
"getVar",
"(",
"'Search'",
")",
";",
"}",
"$",
"fields",
"=",
"FieldList",
"::",
"create",
"(",
"TextField",
"::",
"create",
"(",
"'Search'",
",",
"false",
",",
"$",
"searchText",
")",
")",
";",
"$",
"actions",
"=",
"FieldList",
"::",
"create",
"(",
"FormAction",
"::",
"create",
"(",
"'results'",
",",
"_t",
"(",
"'SilverStripe\\\\CMS\\\\Search\\\\SearchForm.GO'",
",",
"'Go'",
")",
")",
")",
";",
"return",
"SearchForm",
"::",
"create",
"(",
"$",
"this",
"->",
"owner",
",",
"'SearchForm'",
",",
"$",
"fields",
",",
"$",
"actions",
")",
";",
"}"
] | Site search form
@return SearchForm | [
"Site",
"search",
"form"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Control/ContentControllerExtension.php#L25-L42 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Control/ContentControllerExtension.php | ContentControllerExtension.results | public function results($data, $form, $request)
{
$data = [
'Results' => $form->getResults(),
'Query' => DBField::create_field('Text', $form->getSearchQuery()),
'Title' => _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results')
];
return $this->owner->customise($data)->renderWith(['Page_results_solr', 'Page_results', 'Page']);
} | php | public function results($data, $form, $request)
{
$data = [
'Results' => $form->getResults(),
'Query' => DBField::create_field('Text', $form->getSearchQuery()),
'Title' => _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results')
];
return $this->owner->customise($data)->renderWith(['Page_results_solr', 'Page_results', 'Page']);
} | [
"public",
"function",
"results",
"(",
"$",
"data",
",",
"$",
"form",
",",
"$",
"request",
")",
"{",
"$",
"data",
"=",
"[",
"'Results'",
"=>",
"$",
"form",
"->",
"getResults",
"(",
")",
",",
"'Query'",
"=>",
"DBField",
"::",
"create_field",
"(",
"'Text'",
",",
"$",
"form",
"->",
"getSearchQuery",
"(",
")",
")",
",",
"'Title'",
"=>",
"_t",
"(",
"'SilverStripe\\\\CMS\\\\Search\\\\SearchForm.SearchResults'",
",",
"'Search Results'",
")",
"]",
";",
"return",
"$",
"this",
"->",
"owner",
"->",
"customise",
"(",
"$",
"data",
")",
"->",
"renderWith",
"(",
"[",
"'Page_results_solr'",
",",
"'Page_results'",
",",
"'Page'",
"]",
")",
";",
"}"
] | Process and render search results.
@param array $data The raw request data submitted by user
@param SearchForm $form The form instance that was submitted
@param HTTPRequest $request Request generated for this action | [
"Process",
"and",
"render",
"search",
"results",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Control/ContentControllerExtension.php#L51-L59 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Services/Solr4Service_Core.php | Solr4Service_Core.commit | public function commit($expungeDeletes = false, $waitFlush = null, $waitSearcher = true, $timeout = 3600)
{
if ($waitFlush) {
user_error('waitFlush must be false when using Solr 4.0+' . E_USER_ERROR);
}
$expungeValue = $expungeDeletes ? 'true' : 'false';
$searcherValue = $waitSearcher ? 'true' : 'false';
$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitSearcher="' . $searcherValue . '" />';
return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
} | php | public function commit($expungeDeletes = false, $waitFlush = null, $waitSearcher = true, $timeout = 3600)
{
if ($waitFlush) {
user_error('waitFlush must be false when using Solr 4.0+' . E_USER_ERROR);
}
$expungeValue = $expungeDeletes ? 'true' : 'false';
$searcherValue = $waitSearcher ? 'true' : 'false';
$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitSearcher="' . $searcherValue . '" />';
return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
} | [
"public",
"function",
"commit",
"(",
"$",
"expungeDeletes",
"=",
"false",
",",
"$",
"waitFlush",
"=",
"null",
",",
"$",
"waitSearcher",
"=",
"true",
",",
"$",
"timeout",
"=",
"3600",
")",
"{",
"if",
"(",
"$",
"waitFlush",
")",
"{",
"user_error",
"(",
"'waitFlush must be false when using Solr 4.0+'",
".",
"E_USER_ERROR",
")",
";",
"}",
"$",
"expungeValue",
"=",
"$",
"expungeDeletes",
"?",
"'true'",
":",
"'false'",
";",
"$",
"searcherValue",
"=",
"$",
"waitSearcher",
"?",
"'true'",
":",
"'false'",
";",
"$",
"rawPost",
"=",
"'<commit expungeDeletes=\"'",
".",
"$",
"expungeValue",
".",
"'\" waitSearcher=\"'",
".",
"$",
"searcherValue",
".",
"'\" />'",
";",
"return",
"$",
"this",
"->",
"_sendRawPost",
"(",
"$",
"this",
"->",
"_updateUrl",
",",
"$",
"rawPost",
",",
"$",
"timeout",
")",
";",
"}"
] | Replace underlying commit function to remove waitFlush in 4.0+, since it's been deprecated and 4.4 throws errors
if you pass it | [
"Replace",
"underlying",
"commit",
"function",
"to",
"remove",
"waitFlush",
"in",
"4",
".",
"0",
"+",
"since",
"it",
"s",
"been",
"deprecated",
"and",
"4",
".",
"4",
"throws",
"errors",
"if",
"you",
"pass",
"it"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Services/Solr4Service_Core.php#L11-L22 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Services/Solr4Service_Core.php | Solr4Service_Core.addDocuments | public function addDocuments(
$documents,
$allowDups = false,
$overwritePending = true,
$overwriteCommitted = true,
$commitWithin = 0
) {
$overwriteVal = $allowDups ? 'false' : 'true';
$commitWithin = (int) $commitWithin;
$commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
$rawPost = "<add overwrite=\"{$overwriteVal}\"{$commitWithinString}>";
foreach ($documents as $document) {
if ($document instanceof \Apache_Solr_Document) {
$rawPost .= $this->_documentToXmlFragment($document);
}
}
$rawPost .= '</add>';
return $this->add($rawPost);
} | php | public function addDocuments(
$documents,
$allowDups = false,
$overwritePending = true,
$overwriteCommitted = true,
$commitWithin = 0
) {
$overwriteVal = $allowDups ? 'false' : 'true';
$commitWithin = (int) $commitWithin;
$commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
$rawPost = "<add overwrite=\"{$overwriteVal}\"{$commitWithinString}>";
foreach ($documents as $document) {
if ($document instanceof \Apache_Solr_Document) {
$rawPost .= $this->_documentToXmlFragment($document);
}
}
$rawPost .= '</add>';
return $this->add($rawPost);
} | [
"public",
"function",
"addDocuments",
"(",
"$",
"documents",
",",
"$",
"allowDups",
"=",
"false",
",",
"$",
"overwritePending",
"=",
"true",
",",
"$",
"overwriteCommitted",
"=",
"true",
",",
"$",
"commitWithin",
"=",
"0",
")",
"{",
"$",
"overwriteVal",
"=",
"$",
"allowDups",
"?",
"'false'",
":",
"'true'",
";",
"$",
"commitWithin",
"=",
"(",
"int",
")",
"$",
"commitWithin",
";",
"$",
"commitWithinString",
"=",
"$",
"commitWithin",
">",
"0",
"?",
"\" commitWithin=\\\"{$commitWithin}\\\"\"",
":",
"''",
";",
"$",
"rawPost",
"=",
"\"<add overwrite=\\\"{$overwriteVal}\\\"{$commitWithinString}>\"",
";",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"if",
"(",
"$",
"document",
"instanceof",
"\\",
"Apache_Solr_Document",
")",
"{",
"$",
"rawPost",
".=",
"$",
"this",
"->",
"_documentToXmlFragment",
"(",
"$",
"document",
")",
";",
"}",
"}",
"$",
"rawPost",
".=",
"'</add>'",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"rawPost",
")",
";",
"}"
] | Solr 4.0 compat http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22add.22
Remove allowDups, overwritePending and overwriteComitted | [
"Solr",
"4",
".",
"0",
"compat",
"http",
":",
"//",
"wiki",
".",
"apache",
".",
"org",
"/",
"solr",
"/",
"UpdateXmlMessages#Optional_attributes_for_",
".",
"22add",
".",
"22",
"Remove",
"allowDups",
"overwritePending",
"and",
"overwriteComitted"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Services/Solr4Service_Core.php#L42-L62 |
silverstripe/silverstripe-fulltextsearch | src/Search/Extensions/ProxyDBExtension.php | ProxyDBExtension.updateProxy | public function updateProxy(ProxyGenerator &$proxy)
{
$proxy = $proxy->addMethod('manipulate', function ($args, $next) {
$manipulation = $args[0];
SearchUpdater::handle_manipulation($manipulation);
return $next(...$args);
});
} | php | public function updateProxy(ProxyGenerator &$proxy)
{
$proxy = $proxy->addMethod('manipulate', function ($args, $next) {
$manipulation = $args[0];
SearchUpdater::handle_manipulation($manipulation);
return $next(...$args);
});
} | [
"public",
"function",
"updateProxy",
"(",
"ProxyGenerator",
"&",
"$",
"proxy",
")",
"{",
"$",
"proxy",
"=",
"$",
"proxy",
"->",
"addMethod",
"(",
"'manipulate'",
",",
"function",
"(",
"$",
"args",
",",
"$",
"next",
")",
"{",
"$",
"manipulation",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"SearchUpdater",
"::",
"handle_manipulation",
"(",
"$",
"manipulation",
")",
";",
"return",
"$",
"next",
"(",
"...",
"$",
"args",
")",
";",
"}",
")",
";",
"}"
] | @param ProxyGenerator $proxy
Ensure the search index is kept up to date by monitoring SilverStripe database manipulations | [
"@param",
"ProxyGenerator",
"$proxy"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Extensions/ProxyDBExtension.php#L21-L28 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Tasks/Solr_Configure.php | Solr_Configure.updateIndex | protected function updateIndex($instance, $store)
{
$index = $instance->getIndexName();
$this->getLogger()->info("Configuring $index.");
// Upload the config files for this index
$this->getLogger()->info("Uploading configuration ...");
$instance->uploadConfig($store);
// Then tell Solr to use those config files
$service = Solr::service();
if ($service->coreIsActive($index)) {
$this->getLogger()->info("Reloading core ...");
$service->coreReload($index);
} else {
$this->getLogger()->info("Creating core ...");
$service->coreCreate($index, $store->instanceDir($index));
}
$this->getLogger()->info("Done");
} | php | protected function updateIndex($instance, $store)
{
$index = $instance->getIndexName();
$this->getLogger()->info("Configuring $index.");
// Upload the config files for this index
$this->getLogger()->info("Uploading configuration ...");
$instance->uploadConfig($store);
// Then tell Solr to use those config files
$service = Solr::service();
if ($service->coreIsActive($index)) {
$this->getLogger()->info("Reloading core ...");
$service->coreReload($index);
} else {
$this->getLogger()->info("Creating core ...");
$service->coreCreate($index, $store->instanceDir($index));
}
$this->getLogger()->info("Done");
} | [
"protected",
"function",
"updateIndex",
"(",
"$",
"instance",
",",
"$",
"store",
")",
"{",
"$",
"index",
"=",
"$",
"instance",
"->",
"getIndexName",
"(",
")",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Configuring $index.\"",
")",
";",
"// Upload the config files for this index",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Uploading configuration ...\"",
")",
";",
"$",
"instance",
"->",
"uploadConfig",
"(",
"$",
"store",
")",
";",
"// Then tell Solr to use those config files",
"$",
"service",
"=",
"Solr",
"::",
"service",
"(",
")",
";",
"if",
"(",
"$",
"service",
"->",
"coreIsActive",
"(",
"$",
"index",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Reloading core ...\"",
")",
";",
"$",
"service",
"->",
"coreReload",
"(",
"$",
"index",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Creating core ...\"",
")",
";",
"$",
"service",
"->",
"coreCreate",
"(",
"$",
"index",
",",
"$",
"store",
"->",
"instanceDir",
"(",
"$",
"index",
")",
")",
";",
"}",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Done\"",
")",
";",
"}"
] | Update the index on the given store
@param SolrIndex $instance Instance
@param SolrConfigStore $store | [
"Update",
"the",
"index",
"on",
"the",
"given",
"store"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Tasks/Solr_Configure.php#L52-L72 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Tasks/Solr_Configure.php | Solr_Configure.getSolrConfigStore | protected function getSolrConfigStore()
{
$options = Solr::solr_options();
if (!isset($options['indexstore']) || !($indexstore = $options['indexstore'])) {
throw new Exception('No index configuration for Solr provided', E_USER_ERROR);
}
// Find the IndexStore handler, which will handle uploading config files to Solr
$mode = $indexstore['mode'];
if ($mode === 'file') {
return new SolrConfigStore_File($indexstore);
}
if ($mode === 'webdav') {
return new SolrConfigStore_WebDAV($indexstore);
}
if ($mode === 'post') {
return new SolrConfigStore_Post($indexstore);
}
if (ClassInfo::exists($mode) && ClassInfo::classImplements($mode, SolrConfigStore::class)) {
return new $mode($indexstore);
}
user_error('Unknown Solr index mode ' . $indexstore['mode'], E_USER_ERROR);
} | php | protected function getSolrConfigStore()
{
$options = Solr::solr_options();
if (!isset($options['indexstore']) || !($indexstore = $options['indexstore'])) {
throw new Exception('No index configuration for Solr provided', E_USER_ERROR);
}
// Find the IndexStore handler, which will handle uploading config files to Solr
$mode = $indexstore['mode'];
if ($mode === 'file') {
return new SolrConfigStore_File($indexstore);
}
if ($mode === 'webdav') {
return new SolrConfigStore_WebDAV($indexstore);
}
if ($mode === 'post') {
return new SolrConfigStore_Post($indexstore);
}
if (ClassInfo::exists($mode) && ClassInfo::classImplements($mode, SolrConfigStore::class)) {
return new $mode($indexstore);
}
user_error('Unknown Solr index mode ' . $indexstore['mode'], E_USER_ERROR);
} | [
"protected",
"function",
"getSolrConfigStore",
"(",
")",
"{",
"$",
"options",
"=",
"Solr",
"::",
"solr_options",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'indexstore'",
"]",
")",
"||",
"!",
"(",
"$",
"indexstore",
"=",
"$",
"options",
"[",
"'indexstore'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'No index configuration for Solr provided'",
",",
"E_USER_ERROR",
")",
";",
"}",
"// Find the IndexStore handler, which will handle uploading config files to Solr",
"$",
"mode",
"=",
"$",
"indexstore",
"[",
"'mode'",
"]",
";",
"if",
"(",
"$",
"mode",
"===",
"'file'",
")",
"{",
"return",
"new",
"SolrConfigStore_File",
"(",
"$",
"indexstore",
")",
";",
"}",
"if",
"(",
"$",
"mode",
"===",
"'webdav'",
")",
"{",
"return",
"new",
"SolrConfigStore_WebDAV",
"(",
"$",
"indexstore",
")",
";",
"}",
"if",
"(",
"$",
"mode",
"===",
"'post'",
")",
"{",
"return",
"new",
"SolrConfigStore_Post",
"(",
"$",
"indexstore",
")",
";",
"}",
"if",
"(",
"ClassInfo",
"::",
"exists",
"(",
"$",
"mode",
")",
"&&",
"ClassInfo",
"::",
"classImplements",
"(",
"$",
"mode",
",",
"SolrConfigStore",
"::",
"class",
")",
")",
"{",
"return",
"new",
"$",
"mode",
"(",
"$",
"indexstore",
")",
";",
"}",
"user_error",
"(",
"'Unknown Solr index mode '",
".",
"$",
"indexstore",
"[",
"'mode'",
"]",
",",
"E_USER_ERROR",
")",
";",
"}"
] | Get config store
@return SolrConfigStore
@throws Exception | [
"Get",
"config",
"store"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Tasks/Solr_Configure.php#L80-L104 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariant.php | SearchVariant.variants | public static function variants($class = null, $includeSubclasses = true)
{
if (!$class) {
// Build up and cache a list of all search variants (subclasses of SearchVariant)
if (self::$variants === null) {
$classes = ClassInfo::subclassesFor(static::class);
$concrete = array();
foreach ($classes as $variantclass) {
$ref = new ReflectionClass($variantclass);
if ($ref->isInstantiable()) {
$variant = singleton($variantclass);
if ($variant->appliesToEnvironment()) {
$concrete[$variantclass] = $variant;
}
}
}
self::$variants = $concrete;
}
return self::$variants;
} else {
$key = $class . '!' . $includeSubclasses;
if (!isset(self::$class_variants[$key])) {
self::$class_variants[$key] = array();
foreach (self::variants() as $variantclass => $instance) {
if ($instance->appliesTo($class, $includeSubclasses)) {
self::$class_variants[$key][$variantclass] = $instance;
}
}
}
return self::$class_variants[$key];
}
} | php | public static function variants($class = null, $includeSubclasses = true)
{
if (!$class) {
// Build up and cache a list of all search variants (subclasses of SearchVariant)
if (self::$variants === null) {
$classes = ClassInfo::subclassesFor(static::class);
$concrete = array();
foreach ($classes as $variantclass) {
$ref = new ReflectionClass($variantclass);
if ($ref->isInstantiable()) {
$variant = singleton($variantclass);
if ($variant->appliesToEnvironment()) {
$concrete[$variantclass] = $variant;
}
}
}
self::$variants = $concrete;
}
return self::$variants;
} else {
$key = $class . '!' . $includeSubclasses;
if (!isset(self::$class_variants[$key])) {
self::$class_variants[$key] = array();
foreach (self::variants() as $variantclass => $instance) {
if ($instance->appliesTo($class, $includeSubclasses)) {
self::$class_variants[$key][$variantclass] = $instance;
}
}
}
return self::$class_variants[$key];
}
} | [
"public",
"static",
"function",
"variants",
"(",
"$",
"class",
"=",
"null",
",",
"$",
"includeSubclasses",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"// Build up and cache a list of all search variants (subclasses of SearchVariant)",
"if",
"(",
"self",
"::",
"$",
"variants",
"===",
"null",
")",
"{",
"$",
"classes",
"=",
"ClassInfo",
"::",
"subclassesFor",
"(",
"static",
"::",
"class",
")",
";",
"$",
"concrete",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"variantclass",
")",
"{",
"$",
"ref",
"=",
"new",
"ReflectionClass",
"(",
"$",
"variantclass",
")",
";",
"if",
"(",
"$",
"ref",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"$",
"variant",
"=",
"singleton",
"(",
"$",
"variantclass",
")",
";",
"if",
"(",
"$",
"variant",
"->",
"appliesToEnvironment",
"(",
")",
")",
"{",
"$",
"concrete",
"[",
"$",
"variantclass",
"]",
"=",
"$",
"variant",
";",
"}",
"}",
"}",
"self",
"::",
"$",
"variants",
"=",
"$",
"concrete",
";",
"}",
"return",
"self",
"::",
"$",
"variants",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"$",
"class",
".",
"'!'",
".",
"$",
"includeSubclasses",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"class_variants",
"[",
"$",
"key",
"]",
")",
")",
"{",
"self",
"::",
"$",
"class_variants",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"variants",
"(",
")",
"as",
"$",
"variantclass",
"=>",
"$",
"instance",
")",
"{",
"if",
"(",
"$",
"instance",
"->",
"appliesTo",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
")",
")",
"{",
"self",
"::",
"$",
"class_variants",
"[",
"$",
"key",
"]",
"[",
"$",
"variantclass",
"]",
"=",
"$",
"instance",
";",
"}",
"}",
"}",
"return",
"self",
"::",
"$",
"class_variants",
"[",
"$",
"key",
"]",
";",
"}",
"}"
] | Returns an array of variants.
With no arguments, returns all variants
With a classname as the first argument, returns the variants that apply to that class
(optionally including subclasses)
@static
@param string $class - The class name to get variants for
@param bool $includeSubclasses - True if variants should be included if they apply to at least one subclass of $class
@return array - An array of (string)$variantClassName => (Object)$variantInstance pairs | [
"Returns",
"an",
"array",
"of",
"variants",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariant.php#L94-L131 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariant.php | SearchVariant.with | public static function with($class = null, $includeSubclasses = true)
{
// Make the cache key
$key = $class ? $class . '!' . $includeSubclasses : '!';
// If no SearchVariant_Caller instance yet, create it
if (!isset(self::$call_instances[$key])) {
self::$call_instances[$key] = new SearchVariant_Caller(self::variants($class, $includeSubclasses));
}
// Then return it
return self::$call_instances[$key];
} | php | public static function with($class = null, $includeSubclasses = true)
{
// Make the cache key
$key = $class ? $class . '!' . $includeSubclasses : '!';
// If no SearchVariant_Caller instance yet, create it
if (!isset(self::$call_instances[$key])) {
self::$call_instances[$key] = new SearchVariant_Caller(self::variants($class, $includeSubclasses));
}
// Then return it
return self::$call_instances[$key];
} | [
"public",
"static",
"function",
"with",
"(",
"$",
"class",
"=",
"null",
",",
"$",
"includeSubclasses",
"=",
"true",
")",
"{",
"// Make the cache key",
"$",
"key",
"=",
"$",
"class",
"?",
"$",
"class",
".",
"'!'",
".",
"$",
"includeSubclasses",
":",
"'!'",
";",
"// If no SearchVariant_Caller instance yet, create it",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"call_instances",
"[",
"$",
"key",
"]",
")",
")",
"{",
"self",
"::",
"$",
"call_instances",
"[",
"$",
"key",
"]",
"=",
"new",
"SearchVariant_Caller",
"(",
"self",
"::",
"variants",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
")",
")",
";",
"}",
"// Then return it",
"return",
"self",
"::",
"$",
"call_instances",
"[",
"$",
"key",
"]",
";",
"}"
] | Lets you call any function on all variants that support it, in the same manner as "Object#extend" calls
a method from extensions.
Usage: SearchVariant::with(...)->call($method, $arg1, ...);
@static
@param string $class - (Optional) a classname. If passed, only variants that apply to that class will be checked / called
@param bool $includeSubclasses - (Optional) If false, only variants that apply strictly to the passed class or its super-classes
will be checked. If true (the default), variants that apply to any sub-class of the passed class with also be checked
@return SearchVariant_Caller An object with one method, call() | [
"Lets",
"you",
"call",
"any",
"function",
"on",
"all",
"variants",
"that",
"support",
"it",
"in",
"the",
"same",
"manner",
"as",
"Object#extend",
"calls",
"a",
"method",
"from",
"extensions",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariant.php#L159-L169 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariant.php | SearchVariant.withCommon | public static function withCommon(array $classes = [])
{
// Allow caching
$cacheKey = sha1(serialize($classes));
if (isset(self::$call_instances[$cacheKey])) {
return self::$call_instances[$cacheKey];
}
// Construct new array of variants applicable to at least one class in the list
$commonVariants = [];
foreach ($classes as $class => $options) {
// BC for numerically indexed list of classes
if (is_numeric($class) && !empty($options['class'])) {
$class = $options['class']; // $options['class'] is assumed to exist throughout the code base
}
// Extract relevant class options
$includeSubclasses = isset($options['include_children']) ? $options['include_children'] : true;
// Get the variants for the current class
$variantsForClass = self::variants($class, $includeSubclasses);
// Merge the variants applicable to the current class into the list of common variants, using
// the variant instance to replace any previous versions for the same class name (should be singleton
// anyway).
$commonVariants = array_replace($commonVariants, $variantsForClass);
}
// Cache for future calls
self::$call_instances[$cacheKey] = new SearchVariant_Caller($commonVariants);
return self::$call_instances[$cacheKey];
} | php | public static function withCommon(array $classes = [])
{
// Allow caching
$cacheKey = sha1(serialize($classes));
if (isset(self::$call_instances[$cacheKey])) {
return self::$call_instances[$cacheKey];
}
// Construct new array of variants applicable to at least one class in the list
$commonVariants = [];
foreach ($classes as $class => $options) {
// BC for numerically indexed list of classes
if (is_numeric($class) && !empty($options['class'])) {
$class = $options['class']; // $options['class'] is assumed to exist throughout the code base
}
// Extract relevant class options
$includeSubclasses = isset($options['include_children']) ? $options['include_children'] : true;
// Get the variants for the current class
$variantsForClass = self::variants($class, $includeSubclasses);
// Merge the variants applicable to the current class into the list of common variants, using
// the variant instance to replace any previous versions for the same class name (should be singleton
// anyway).
$commonVariants = array_replace($commonVariants, $variantsForClass);
}
// Cache for future calls
self::$call_instances[$cacheKey] = new SearchVariant_Caller($commonVariants);
return self::$call_instances[$cacheKey];
} | [
"public",
"static",
"function",
"withCommon",
"(",
"array",
"$",
"classes",
"=",
"[",
"]",
")",
"{",
"// Allow caching",
"$",
"cacheKey",
"=",
"sha1",
"(",
"serialize",
"(",
"$",
"classes",
")",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"call_instances",
"[",
"$",
"cacheKey",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"call_instances",
"[",
"$",
"cacheKey",
"]",
";",
"}",
"// Construct new array of variants applicable to at least one class in the list",
"$",
"commonVariants",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
"=>",
"$",
"options",
")",
"{",
"// BC for numerically indexed list of classes",
"if",
"(",
"is_numeric",
"(",
"$",
"class",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"options",
"[",
"'class'",
"]",
";",
"// $options['class'] is assumed to exist throughout the code base",
"}",
"// Extract relevant class options",
"$",
"includeSubclasses",
"=",
"isset",
"(",
"$",
"options",
"[",
"'include_children'",
"]",
")",
"?",
"$",
"options",
"[",
"'include_children'",
"]",
":",
"true",
";",
"// Get the variants for the current class",
"$",
"variantsForClass",
"=",
"self",
"::",
"variants",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
")",
";",
"// Merge the variants applicable to the current class into the list of common variants, using",
"// the variant instance to replace any previous versions for the same class name (should be singleton",
"// anyway).",
"$",
"commonVariants",
"=",
"array_replace",
"(",
"$",
"commonVariants",
",",
"$",
"variantsForClass",
")",
";",
"}",
"// Cache for future calls",
"self",
"::",
"$",
"call_instances",
"[",
"$",
"cacheKey",
"]",
"=",
"new",
"SearchVariant_Caller",
"(",
"$",
"commonVariants",
")",
";",
"return",
"self",
"::",
"$",
"call_instances",
"[",
"$",
"cacheKey",
"]",
";",
"}"
] | Similar to {@link SearchVariant::with}, except will only use variants that apply to at least one of the classes
in the input array, where {@link SearchVariant::with} will run the query on the specific class you give it.
@param string[] $classes
@return SearchVariant_Caller | [
"Similar",
"to",
"{",
"@link",
"SearchVariant",
"::",
"with",
"}",
"except",
"will",
"only",
"use",
"variants",
"that",
"apply",
"to",
"at",
"least",
"one",
"of",
"the",
"classes",
"in",
"the",
"input",
"array",
"where",
"{",
"@link",
"SearchVariant",
"::",
"with",
"}",
"will",
"run",
"the",
"query",
"on",
"the",
"specific",
"class",
"you",
"give",
"it",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariant.php#L178-L210 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariant.php | SearchVariant.current_state | public static function current_state($class = null, $includeSubclasses = true)
{
$state = array();
foreach (self::variants($class, $includeSubclasses) as $variant => $instance) {
$state[$variant] = $instance->currentState();
}
return $state;
} | php | public static function current_state($class = null, $includeSubclasses = true)
{
$state = array();
foreach (self::variants($class, $includeSubclasses) as $variant => $instance) {
$state[$variant] = $instance->currentState();
}
return $state;
} | [
"public",
"static",
"function",
"current_state",
"(",
"$",
"class",
"=",
"null",
",",
"$",
"includeSubclasses",
"=",
"true",
")",
"{",
"$",
"state",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"variants",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
")",
"as",
"$",
"variant",
"=>",
"$",
"instance",
")",
"{",
"$",
"state",
"[",
"$",
"variant",
"]",
"=",
"$",
"instance",
"->",
"currentState",
"(",
")",
";",
"}",
"return",
"$",
"state",
";",
"}"
] | Get the current state of every variant
@static
@return array | [
"Get",
"the",
"current",
"state",
"of",
"every",
"variant"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariant.php#L228-L235 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariant.php | SearchVariant.activate_state | public static function activate_state($state)
{
foreach (self::variants() as $variant => $instance) {
if (isset($state[$variant]) && $instance->appliesToEnvironment()) {
$instance->activateState($state[$variant]);
}
}
} | php | public static function activate_state($state)
{
foreach (self::variants() as $variant => $instance) {
if (isset($state[$variant]) && $instance->appliesToEnvironment()) {
$instance->activateState($state[$variant]);
}
}
} | [
"public",
"static",
"function",
"activate_state",
"(",
"$",
"state",
")",
"{",
"foreach",
"(",
"self",
"::",
"variants",
"(",
")",
"as",
"$",
"variant",
"=>",
"$",
"instance",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"state",
"[",
"$",
"variant",
"]",
")",
"&&",
"$",
"instance",
"->",
"appliesToEnvironment",
"(",
")",
")",
"{",
"$",
"instance",
"->",
"activateState",
"(",
"$",
"state",
"[",
"$",
"variant",
"]",
")",
";",
"}",
"}",
"}"
] | Activate all the states in the passed argument
@static
@param array $state A set of (string)$variantClass => (any)$state pairs , e.g. as returned by
SearchVariant::current_state()
@return void | [
"Activate",
"all",
"the",
"states",
"in",
"the",
"passed",
"argument"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariant.php#L244-L251 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariant.php | SearchVariant.reindex_states | public static function reindex_states($class = null, $includeSubclasses = true)
{
$allstates = array();
foreach (self::variants($class, $includeSubclasses) as $variant => $instance) {
if ($states = $instance->reindexStates()) {
$allstates[$variant] = $states;
}
}
return $allstates ? new CombinationsArrayIterator($allstates) : array(array());
} | php | public static function reindex_states($class = null, $includeSubclasses = true)
{
$allstates = array();
foreach (self::variants($class, $includeSubclasses) as $variant => $instance) {
if ($states = $instance->reindexStates()) {
$allstates[$variant] = $states;
}
}
return $allstates ? new CombinationsArrayIterator($allstates) : array(array());
} | [
"public",
"static",
"function",
"reindex_states",
"(",
"$",
"class",
"=",
"null",
",",
"$",
"includeSubclasses",
"=",
"true",
")",
"{",
"$",
"allstates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"variants",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
")",
"as",
"$",
"variant",
"=>",
"$",
"instance",
")",
"{",
"if",
"(",
"$",
"states",
"=",
"$",
"instance",
"->",
"reindexStates",
"(",
")",
")",
"{",
"$",
"allstates",
"[",
"$",
"variant",
"]",
"=",
"$",
"states",
";",
"}",
"}",
"return",
"$",
"allstates",
"?",
"new",
"CombinationsArrayIterator",
"(",
"$",
"allstates",
")",
":",
"array",
"(",
"array",
"(",
")",
")",
";",
"}"
] | Return an iterator that, when used in a for loop, activates one combination of reindex states per loop, and restores
back to the original state at the end
@static
@param string $class - The class name to get variants for
@param bool $includeSubclasses - True if variants should be included if they apply to at least one subclass of $class
@return SearchVariant_ReindexStateIteratorRet - The iterator to foreach loop over | [
"Return",
"an",
"iterator",
"that",
"when",
"used",
"in",
"a",
"for",
"loop",
"activates",
"one",
"combination",
"of",
"reindex",
"states",
"per",
"loop",
"and",
"restores",
"back",
"to",
"the",
"original",
"state",
"at",
"the",
"end"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariant.php#L261-L272 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariant.php | SearchVariant.addFilterField | protected function addFilterField($index, $name, $field)
{
// If field already exists, make sure to merge origin / base fields
if (isset($index->filterFields[$name])) {
$field['base'] = $this->mergeClasses(
$index->filterFields[$name]['base'],
$field['base']
);
$field['origin'] = $this->mergeClasses(
$index->filterFields[$name]['origin'],
$field['origin']
);
}
$index->filterFields[$name] = $field;
} | php | protected function addFilterField($index, $name, $field)
{
// If field already exists, make sure to merge origin / base fields
if (isset($index->filterFields[$name])) {
$field['base'] = $this->mergeClasses(
$index->filterFields[$name]['base'],
$field['base']
);
$field['origin'] = $this->mergeClasses(
$index->filterFields[$name]['origin'],
$field['origin']
);
}
$index->filterFields[$name] = $field;
} | [
"protected",
"function",
"addFilterField",
"(",
"$",
"index",
",",
"$",
"name",
",",
"$",
"field",
")",
"{",
"// If field already exists, make sure to merge origin / base fields",
"if",
"(",
"isset",
"(",
"$",
"index",
"->",
"filterFields",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"field",
"[",
"'base'",
"]",
"=",
"$",
"this",
"->",
"mergeClasses",
"(",
"$",
"index",
"->",
"filterFields",
"[",
"$",
"name",
"]",
"[",
"'base'",
"]",
",",
"$",
"field",
"[",
"'base'",
"]",
")",
";",
"$",
"field",
"[",
"'origin'",
"]",
"=",
"$",
"this",
"->",
"mergeClasses",
"(",
"$",
"index",
"->",
"filterFields",
"[",
"$",
"name",
"]",
"[",
"'origin'",
"]",
",",
"$",
"field",
"[",
"'origin'",
"]",
")",
";",
"}",
"$",
"index",
"->",
"filterFields",
"[",
"$",
"name",
"]",
"=",
"$",
"field",
";",
"}"
] | Add new filter field to index safely.
This method will respect existing filters with the same field name that
correspond to multiple classes
@param SearchIndex $index
@param string $name Field name
@param array $field Field spec | [
"Add",
"new",
"filter",
"field",
"to",
"index",
"safely",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariant.php#L285-L300 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariant.php | SearchVariant.mergeClasses | protected function mergeClasses($left, $right)
{
// Merge together and remove dupes
if (!is_array($left)) {
$left = array($left);
}
if (!is_array($right)) {
$right = array($right);
}
$merged = array_values(array_unique(array_merge($left, $right)));
// If there is only one item, return it as a single string
if (count($merged) === 1) {
return reset($merged);
}
return $merged;
} | php | protected function mergeClasses($left, $right)
{
// Merge together and remove dupes
if (!is_array($left)) {
$left = array($left);
}
if (!is_array($right)) {
$right = array($right);
}
$merged = array_values(array_unique(array_merge($left, $right)));
// If there is only one item, return it as a single string
if (count($merged) === 1) {
return reset($merged);
}
return $merged;
} | [
"protected",
"function",
"mergeClasses",
"(",
"$",
"left",
",",
"$",
"right",
")",
"{",
"// Merge together and remove dupes",
"if",
"(",
"!",
"is_array",
"(",
"$",
"left",
")",
")",
"{",
"$",
"left",
"=",
"array",
"(",
"$",
"left",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"right",
")",
")",
"{",
"$",
"right",
"=",
"array",
"(",
"$",
"right",
")",
";",
"}",
"$",
"merged",
"=",
"array_values",
"(",
"array_unique",
"(",
"array_merge",
"(",
"$",
"left",
",",
"$",
"right",
")",
")",
")",
";",
"// If there is only one item, return it as a single string",
"if",
"(",
"count",
"(",
"$",
"merged",
")",
"===",
"1",
")",
"{",
"return",
"reset",
"(",
"$",
"merged",
")",
";",
"}",
"return",
"$",
"merged",
";",
"}"
] | Merge sets of (or individual) class names together for a search index field.
If there is only one unique class name, then just return it as a string instead of array.
@param array|string $left Left class(es)
@param array|string $right Right class(es)
@return array|string List of classes, or single class | [
"Merge",
"sets",
"of",
"(",
"or",
"individual",
")",
"class",
"names",
"together",
"for",
"a",
"search",
"index",
"field",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariant.php#L311-L327 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Forms/SearchForm.php | SearchForm.getResults | public function getResults()
{
// Get request data from request handler
$request = $this->getRequestHandler()->getRequest();
$searchTerms = $request->requestVar('Search');
$query = SearchQuery::create()->addSearchTerm($searchTerms);
if ($start = $request->requestVar('start')) {
$query->setStart($start);
}
$params = [
'spellcheck' => 'true',
'spellcheck.collate' => 'true',
];
// Get the first index
$indexClasses = FullTextSearch::get_indexes(SolrIndex::class);
$indexClass = reset($indexClasses);
/** @var SolrIndex $index */
$index = $indexClass::singleton();
$results = $index->search($query, -1, -1, $params);
// filter by permission
if ($results) {
foreach ($results->Matches as $match) {
/** @var DataObject $match */
if (!$match->canView()) {
$results->Matches->remove($match);
}
}
}
return $results;
} | php | public function getResults()
{
// Get request data from request handler
$request = $this->getRequestHandler()->getRequest();
$searchTerms = $request->requestVar('Search');
$query = SearchQuery::create()->addSearchTerm($searchTerms);
if ($start = $request->requestVar('start')) {
$query->setStart($start);
}
$params = [
'spellcheck' => 'true',
'spellcheck.collate' => 'true',
];
// Get the first index
$indexClasses = FullTextSearch::get_indexes(SolrIndex::class);
$indexClass = reset($indexClasses);
/** @var SolrIndex $index */
$index = $indexClass::singleton();
$results = $index->search($query, -1, -1, $params);
// filter by permission
if ($results) {
foreach ($results->Matches as $match) {
/** @var DataObject $match */
if (!$match->canView()) {
$results->Matches->remove($match);
}
}
}
return $results;
} | [
"public",
"function",
"getResults",
"(",
")",
"{",
"// Get request data from request handler",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequestHandler",
"(",
")",
"->",
"getRequest",
"(",
")",
";",
"$",
"searchTerms",
"=",
"$",
"request",
"->",
"requestVar",
"(",
"'Search'",
")",
";",
"$",
"query",
"=",
"SearchQuery",
"::",
"create",
"(",
")",
"->",
"addSearchTerm",
"(",
"$",
"searchTerms",
")",
";",
"if",
"(",
"$",
"start",
"=",
"$",
"request",
"->",
"requestVar",
"(",
"'start'",
")",
")",
"{",
"$",
"query",
"->",
"setStart",
"(",
"$",
"start",
")",
";",
"}",
"$",
"params",
"=",
"[",
"'spellcheck'",
"=>",
"'true'",
",",
"'spellcheck.collate'",
"=>",
"'true'",
",",
"]",
";",
"// Get the first index",
"$",
"indexClasses",
"=",
"FullTextSearch",
"::",
"get_indexes",
"(",
"SolrIndex",
"::",
"class",
")",
";",
"$",
"indexClass",
"=",
"reset",
"(",
"$",
"indexClasses",
")",
";",
"/** @var SolrIndex $index */",
"$",
"index",
"=",
"$",
"indexClass",
"::",
"singleton",
"(",
")",
";",
"$",
"results",
"=",
"$",
"index",
"->",
"search",
"(",
"$",
"query",
",",
"-",
"1",
",",
"-",
"1",
",",
"$",
"params",
")",
";",
"// filter by permission",
"if",
"(",
"$",
"results",
")",
"{",
"foreach",
"(",
"$",
"results",
"->",
"Matches",
"as",
"$",
"match",
")",
"{",
"/** @var DataObject $match */",
"if",
"(",
"!",
"$",
"match",
"->",
"canView",
"(",
")",
")",
"{",
"$",
"results",
"->",
"Matches",
"->",
"remove",
"(",
"$",
"match",
")",
";",
"}",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] | Return dataObjectSet of the results using current request to get info from form.
Simplest implementation loops over all Solr indexes
@return ArrayData | [
"Return",
"dataObjectSet",
"of",
"the",
"results",
"using",
"current",
"request",
"to",
"get",
"info",
"from",
"form",
".",
"Simplest",
"implementation",
"loops",
"over",
"all",
"Solr",
"indexes"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Forms/SearchForm.php#L60-L95 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Services/SolrService.php | SolrService.coreCommand | protected function coreCommand($command, $core, $params = array())
{
$command = strtoupper($command);
$params = array_merge($params, array('action' => $command, 'wt' => 'json'));
$params[$command == 'CREATE' ? 'name' : 'core'] = $core;
return $this->_sendRawGet($this->_constructUrl('admin/cores', $params));
} | php | protected function coreCommand($command, $core, $params = array())
{
$command = strtoupper($command);
$params = array_merge($params, array('action' => $command, 'wt' => 'json'));
$params[$command == 'CREATE' ? 'name' : 'core'] = $core;
return $this->_sendRawGet($this->_constructUrl('admin/cores', $params));
} | [
"protected",
"function",
"coreCommand",
"(",
"$",
"command",
",",
"$",
"core",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"command",
"=",
"strtoupper",
"(",
"$",
"command",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"array",
"(",
"'action'",
"=>",
"$",
"command",
",",
"'wt'",
"=>",
"'json'",
")",
")",
";",
"$",
"params",
"[",
"$",
"command",
"==",
"'CREATE'",
"?",
"'name'",
":",
"'core'",
"]",
"=",
"$",
"core",
";",
"return",
"$",
"this",
"->",
"_sendRawGet",
"(",
"$",
"this",
"->",
"_constructUrl",
"(",
"'admin/cores'",
",",
"$",
"params",
")",
")",
";",
"}"
] | Handle encoding the GET parameters and making the HTTP call to execute a core command | [
"Handle",
"encoding",
"the",
"GET",
"parameters",
"and",
"making",
"the",
"HTTP",
"call",
"to",
"execute",
"a",
"core",
"command"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Services/SolrService.php#L22-L29 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Services/SolrService.php | SolrService.coreIsActive | public function coreIsActive($core)
{
// Request the status of the full core name
$result = $this->coreCommand('STATUS', $core);
return isset($result->status->$core->uptime);
} | php | public function coreIsActive($core)
{
// Request the status of the full core name
$result = $this->coreCommand('STATUS', $core);
return isset($result->status->$core->uptime);
} | [
"public",
"function",
"coreIsActive",
"(",
"$",
"core",
")",
"{",
"// Request the status of the full core name",
"$",
"result",
"=",
"$",
"this",
"->",
"coreCommand",
"(",
"'STATUS'",
",",
"$",
"core",
")",
";",
"return",
"isset",
"(",
"$",
"result",
"->",
"status",
"->",
"$",
"core",
"->",
"uptime",
")",
";",
"}"
] | Is the passed core active?
@param string $core The name of the core (an encoded class name)
@return boolean True if that core exists & is active | [
"Is",
"the",
"passed",
"core",
"active?"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Services/SolrService.php#L36-L41 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Services/SolrService.php | SolrService.coreCreate | public function coreCreate($core, $instancedir, $config = null, $schema = null, $datadir = null)
{
$args = array('instanceDir' => $instancedir);
if ($config) {
$args['config'] = $config;
}
if ($schema) {
$args['schema'] = $schema;
}
if ($datadir) {
$args['dataDir'] = $datadir;
}
return $this->coreCommand('CREATE', $core, $args);
} | php | public function coreCreate($core, $instancedir, $config = null, $schema = null, $datadir = null)
{
$args = array('instanceDir' => $instancedir);
if ($config) {
$args['config'] = $config;
}
if ($schema) {
$args['schema'] = $schema;
}
if ($datadir) {
$args['dataDir'] = $datadir;
}
return $this->coreCommand('CREATE', $core, $args);
} | [
"public",
"function",
"coreCreate",
"(",
"$",
"core",
",",
"$",
"instancedir",
",",
"$",
"config",
"=",
"null",
",",
"$",
"schema",
"=",
"null",
",",
"$",
"datadir",
"=",
"null",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'instanceDir'",
"=>",
"$",
"instancedir",
")",
";",
"if",
"(",
"$",
"config",
")",
"{",
"$",
"args",
"[",
"'config'",
"]",
"=",
"$",
"config",
";",
"}",
"if",
"(",
"$",
"schema",
")",
"{",
"$",
"args",
"[",
"'schema'",
"]",
"=",
"$",
"schema",
";",
"}",
"if",
"(",
"$",
"datadir",
")",
"{",
"$",
"args",
"[",
"'dataDir'",
"]",
"=",
"$",
"datadir",
";",
"}",
"return",
"$",
"this",
"->",
"coreCommand",
"(",
"'CREATE'",
",",
"$",
"core",
",",
"$",
"args",
")",
";",
"}"
] | Create a new core
@param $core string - The name of the core
@param $instancedir string - The base path of the core on the server
@param $config string - The filename of solrconfig.xml on the server. Default is $instancedir/solrconfig.xml
@param $schema string - The filename of schema.xml on the server. Default is $instancedir/schema.xml
@param $datadir string - The path to store data for this core on the server. Default depends on solrconfig.xml
@return Apache_Solr_Response | [
"Create",
"a",
"new",
"core"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Services/SolrService.php#L52-L66 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Services/SolrService.php | SolrService.serviceForCore | public function serviceForCore($core)
{
$klass = Config::inst()->get(get_called_class(), 'core_class');
return new $klass($this->_host, $this->_port, $this->_path . $core, $this->_httpTransport);
} | php | public function serviceForCore($core)
{
$klass = Config::inst()->get(get_called_class(), 'core_class');
return new $klass($this->_host, $this->_port, $this->_path . $core, $this->_httpTransport);
} | [
"public",
"function",
"serviceForCore",
"(",
"$",
"core",
")",
"{",
"$",
"klass",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"get_called_class",
"(",
")",
",",
"'core_class'",
")",
";",
"return",
"new",
"$",
"klass",
"(",
"$",
"this",
"->",
"_host",
",",
"$",
"this",
"->",
"_port",
",",
"$",
"this",
"->",
"_path",
".",
"$",
"core",
",",
"$",
"this",
"->",
"_httpTransport",
")",
";",
"}"
] | Create a new Solr4Service_Core instance for the passed core
@param $core string - The name of the core
@return Solr4Service_Core | [
"Create",
"a",
"new",
"Solr4Service_Core",
"instance",
"for",
"the",
"passed",
"core"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Services/SolrService.php#L83-L87 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getIndexName | public function getIndexName()
{
$name = $this->sanitiseClassName(get_class($this), '-');
$indexParts = [$name];
if ($indexPrefix = Environment::getEnv('SS_SOLR_INDEX_PREFIX')) {
array_unshift($indexParts, $indexPrefix);
}
if ($indexSuffix = Environment::getEnv('SS_SOLR_INDEX_SUFFIX')) {
$indexParts[] = $indexSuffix;
}
return implode($indexParts);
} | php | public function getIndexName()
{
$name = $this->sanitiseClassName(get_class($this), '-');
$indexParts = [$name];
if ($indexPrefix = Environment::getEnv('SS_SOLR_INDEX_PREFIX')) {
array_unshift($indexParts, $indexPrefix);
}
if ($indexSuffix = Environment::getEnv('SS_SOLR_INDEX_SUFFIX')) {
$indexParts[] = $indexSuffix;
}
return implode($indexParts);
} | [
"public",
"function",
"getIndexName",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"sanitiseClassName",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"'-'",
")",
";",
"$",
"indexParts",
"=",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"$",
"indexPrefix",
"=",
"Environment",
"::",
"getEnv",
"(",
"'SS_SOLR_INDEX_PREFIX'",
")",
")",
"{",
"array_unshift",
"(",
"$",
"indexParts",
",",
"$",
"indexPrefix",
")",
";",
"}",
"if",
"(",
"$",
"indexSuffix",
"=",
"Environment",
"::",
"getEnv",
"(",
"'SS_SOLR_INDEX_SUFFIX'",
")",
")",
"{",
"$",
"indexParts",
"[",
"]",
"=",
"$",
"indexSuffix",
";",
"}",
"return",
"implode",
"(",
"$",
"indexParts",
")",
";",
"}"
] | Helper for returning the correct index name. Supports prefixing and
suffixing
@return string | [
"Helper",
"for",
"returning",
"the",
"correct",
"index",
"name",
".",
"Supports",
"prefixing",
"and",
"suffixing"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L112-L127 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.addAnalyzer | public function addAnalyzer($field, $type, $params)
{
$fullFields = $this->fieldData($field);
if ($fullFields) {
foreach ($fullFields as $fullField => $spec) {
if (!isset($this->analyzerFields[$fullField])) {
$this->analyzerFields[$fullField] = array();
}
$this->analyzerFields[$fullField][$type] = $params;
}
}
} | php | public function addAnalyzer($field, $type, $params)
{
$fullFields = $this->fieldData($field);
if ($fullFields) {
foreach ($fullFields as $fullField => $spec) {
if (!isset($this->analyzerFields[$fullField])) {
$this->analyzerFields[$fullField] = array();
}
$this->analyzerFields[$fullField][$type] = $params;
}
}
} | [
"public",
"function",
"addAnalyzer",
"(",
"$",
"field",
",",
"$",
"type",
",",
"$",
"params",
")",
"{",
"$",
"fullFields",
"=",
"$",
"this",
"->",
"fieldData",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"fullFields",
")",
"{",
"foreach",
"(",
"$",
"fullFields",
"as",
"$",
"fullField",
"=>",
"$",
"spec",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"analyzerFields",
"[",
"$",
"fullField",
"]",
")",
")",
"{",
"$",
"this",
"->",
"analyzerFields",
"[",
"$",
"fullField",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"analyzerFields",
"[",
"$",
"fullField",
"]",
"[",
"$",
"type",
"]",
"=",
"$",
"params",
";",
"}",
"}",
"}"
] | Index-time analyzer which is applied to a specific field.
Can be used to remove HTML tags, apply stemming, etc.
@see http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.WhitespaceTokenizerFactory
@param string $field
@param string $type
@param array $params parameters for the analyzer, usually at least a "class" | [
"Index",
"-",
"time",
"analyzer",
"which",
"is",
"applied",
"to",
"a",
"specific",
"field",
".",
"Can",
"be",
"used",
"to",
"remove",
"HTML",
"tags",
"apply",
"stemming",
"etc",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L144-L155 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getCopyDestinations | protected function getCopyDestinations()
{
$copyFields = $this->config()->copy_fields;
if ($copyFields) {
return $copyFields;
}
// Fallback to default field
$df = $this->getDefaultField();
return array($df);
} | php | protected function getCopyDestinations()
{
$copyFields = $this->config()->copy_fields;
if ($copyFields) {
return $copyFields;
}
// Fallback to default field
$df = $this->getDefaultField();
return array($df);
} | [
"protected",
"function",
"getCopyDestinations",
"(",
")",
"{",
"$",
"copyFields",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"copy_fields",
";",
"if",
"(",
"$",
"copyFields",
")",
"{",
"return",
"$",
"copyFields",
";",
"}",
"// Fallback to default field",
"$",
"df",
"=",
"$",
"this",
"->",
"getDefaultField",
"(",
")",
";",
"return",
"array",
"(",
"$",
"df",
")",
";",
"}"
] | Get list of fields each text field should be copied into.
This will fallback to the default field if omitted.
@return array | [
"Get",
"list",
"of",
"fields",
"each",
"text",
"field",
"should",
"be",
"copied",
"into",
".",
"This",
"will",
"fallback",
"to",
"the",
"default",
"field",
"if",
"omitted",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L173-L182 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getCollatedSuggestion | protected function getCollatedSuggestion($collation = '')
{
if (is_string($collation)) {
return $collation;
}
if (is_object($collation)) {
if (isset($collation->misspellingsAndCorrections)) {
foreach ($collation->misspellingsAndCorrections as $key => $value) {
return $value;
}
}
}
return '';
} | php | protected function getCollatedSuggestion($collation = '')
{
if (is_string($collation)) {
return $collation;
}
if (is_object($collation)) {
if (isset($collation->misspellingsAndCorrections)) {
foreach ($collation->misspellingsAndCorrections as $key => $value) {
return $value;
}
}
}
return '';
} | [
"protected",
"function",
"getCollatedSuggestion",
"(",
"$",
"collation",
"=",
"''",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"collation",
")",
")",
"{",
"return",
"$",
"collation",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"collation",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"collation",
"->",
"misspellingsAndCorrections",
")",
")",
"{",
"foreach",
"(",
"$",
"collation",
"->",
"misspellingsAndCorrections",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"''",
";",
"}"
] | Extract first suggestion text from collated values
@param mixed $collation
@return string | [
"Extract",
"first",
"suggestion",
"text",
"from",
"collated",
"values"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L233-L246 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getNiceSuggestion | protected function getNiceSuggestion($collation = '')
{
$collationParts = explode(' ', $collation);
// Remove advanced query params from the beginning of each collation part.
foreach ($collationParts as $key => &$part) {
$part = ltrim($part, '+');
}
return implode(' ', $collationParts);
} | php | protected function getNiceSuggestion($collation = '')
{
$collationParts = explode(' ', $collation);
// Remove advanced query params from the beginning of each collation part.
foreach ($collationParts as $key => &$part) {
$part = ltrim($part, '+');
}
return implode(' ', $collationParts);
} | [
"protected",
"function",
"getNiceSuggestion",
"(",
"$",
"collation",
"=",
"''",
")",
"{",
"$",
"collationParts",
"=",
"explode",
"(",
"' '",
",",
"$",
"collation",
")",
";",
"// Remove advanced query params from the beginning of each collation part.",
"foreach",
"(",
"$",
"collationParts",
"as",
"$",
"key",
"=>",
"&",
"$",
"part",
")",
"{",
"$",
"part",
"=",
"ltrim",
"(",
"$",
"part",
",",
"'+'",
")",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"collationParts",
")",
";",
"}"
] | Extract a human friendly spelling suggestion from a Solr spellcheck collation string.
@param string $collation
@return String | [
"Extract",
"a",
"human",
"friendly",
"spelling",
"suggestion",
"from",
"a",
"Solr",
"spellcheck",
"collation",
"string",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L253-L263 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.addStoredField | public function addStoredField($field, $forceType = null, $extraOptions = array())
{
$options = array_merge($extraOptions, array('stored' => 'true'));
$this->addFulltextField($field, $forceType, $options);
} | php | public function addStoredField($field, $forceType = null, $extraOptions = array())
{
$options = array_merge($extraOptions, array('stored' => 'true'));
$this->addFulltextField($field, $forceType, $options);
} | [
"public",
"function",
"addStoredField",
"(",
"$",
"field",
",",
"$",
"forceType",
"=",
"null",
",",
"$",
"extraOptions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"extraOptions",
",",
"array",
"(",
"'stored'",
"=>",
"'true'",
")",
")",
";",
"$",
"this",
"->",
"addFulltextField",
"(",
"$",
"field",
",",
"$",
"forceType",
",",
"$",
"options",
")",
";",
"}"
] | Add a field that should be stored
@param string $field The field to add
@param string $forceType The type to force this field as (required in some cases, when not
detectable from metadata)
@param array $extraOptions Dependent on search implementation | [
"Add",
"a",
"field",
"that",
"should",
"be",
"stored"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L285-L289 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.addBoostedField | public function addBoostedField($field, $forceType = null, $extraOptions = array(), $boost = 2)
{
$options = array_merge($extraOptions, array('boost' => $boost));
$this->addFulltextField($field, $forceType, $options);
} | php | public function addBoostedField($field, $forceType = null, $extraOptions = array(), $boost = 2)
{
$options = array_merge($extraOptions, array('boost' => $boost));
$this->addFulltextField($field, $forceType, $options);
} | [
"public",
"function",
"addBoostedField",
"(",
"$",
"field",
",",
"$",
"forceType",
"=",
"null",
",",
"$",
"extraOptions",
"=",
"array",
"(",
")",
",",
"$",
"boost",
"=",
"2",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"extraOptions",
",",
"array",
"(",
"'boost'",
"=>",
"$",
"boost",
")",
")",
";",
"$",
"this",
"->",
"addFulltextField",
"(",
"$",
"field",
",",
"$",
"forceType",
",",
"$",
"options",
")",
";",
"}"
] | Add a fulltext field with a boosted value
@param string $field The field to add
@param string $forceType The type to force this field as (required in some cases, when not
detectable from metadata)
@param array $extraOptions Dependent on search implementation
@param float $boost Numeric boosting value (defaults to 2) | [
"Add",
"a",
"fulltext",
"field",
"with",
"a",
"boosted",
"value"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L300-L304 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.setFieldBoosting | public function setFieldBoosting($field, $level)
{
if (!isset($this->fulltextFields[$field])) {
throw new \InvalidArgumentException("No fulltext field $field exists on " . $this->getIndexName());
}
if ($level === null) {
unset($this->boostedFields[$field]);
} else {
$this->boostedFields[$field] = $level;
}
} | php | public function setFieldBoosting($field, $level)
{
if (!isset($this->fulltextFields[$field])) {
throw new \InvalidArgumentException("No fulltext field $field exists on " . $this->getIndexName());
}
if ($level === null) {
unset($this->boostedFields[$field]);
} else {
$this->boostedFields[$field] = $level;
}
} | [
"public",
"function",
"setFieldBoosting",
"(",
"$",
"field",
",",
"$",
"level",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fulltextFields",
"[",
"$",
"field",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"No fulltext field $field exists on \"",
".",
"$",
"this",
"->",
"getIndexName",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"level",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"boostedFields",
"[",
"$",
"field",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"boostedFields",
"[",
"$",
"field",
"]",
"=",
"$",
"level",
";",
"}",
"}"
] | Set the default boosting level for a specific field.
Will control the default value for qf param (Query Fields), but will not
override a query-specific value.
Fields must be added before having a field boosting specified
@param string $field Full field key (Model_Field)
@param float|null $level Numeric boosting value. Set to null to clear boost | [
"Set",
"the",
"default",
"boosting",
"level",
"for",
"a",
"specific",
"field",
".",
"Will",
"control",
"the",
"default",
"value",
"for",
"qf",
"param",
"(",
"Query",
"Fields",
")",
"but",
"will",
"not",
"override",
"a",
"query",
"-",
"specific",
"value",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L336-L346 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getQueryFields | public function getQueryFields()
{
// Not necessary to specify this unless boosting
if (empty($this->boostedFields)) {
return null;
}
$queryFields = array();
foreach ($this->boostedFields as $fieldName => $boost) {
$queryFields[] = $fieldName . '^' . $boost;
}
// If any fields are queried, we must always include the default field, otherwise it will be excluded
$df = $this->getDefaultField();
if ($queryFields && !isset($this->boostedFields[$df])) {
$queryFields[] = $df;
}
return $queryFields;
} | php | public function getQueryFields()
{
// Not necessary to specify this unless boosting
if (empty($this->boostedFields)) {
return null;
}
$queryFields = array();
foreach ($this->boostedFields as $fieldName => $boost) {
$queryFields[] = $fieldName . '^' . $boost;
}
// If any fields are queried, we must always include the default field, otherwise it will be excluded
$df = $this->getDefaultField();
if ($queryFields && !isset($this->boostedFields[$df])) {
$queryFields[] = $df;
}
return $queryFields;
} | [
"public",
"function",
"getQueryFields",
"(",
")",
"{",
"// Not necessary to specify this unless boosting",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"boostedFields",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"queryFields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"boostedFields",
"as",
"$",
"fieldName",
"=>",
"$",
"boost",
")",
"{",
"$",
"queryFields",
"[",
"]",
"=",
"$",
"fieldName",
".",
"'^'",
".",
"$",
"boost",
";",
"}",
"// If any fields are queried, we must always include the default field, otherwise it will be excluded",
"$",
"df",
"=",
"$",
"this",
"->",
"getDefaultField",
"(",
")",
";",
"if",
"(",
"$",
"queryFields",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"boostedFields",
"[",
"$",
"df",
"]",
")",
")",
"{",
"$",
"queryFields",
"[",
"]",
"=",
"$",
"df",
";",
"}",
"return",
"$",
"queryFields",
";",
"}"
] | Determine the best default value for the 'qf' parameter
@return array|null List of query fields, or null if not specified | [
"Determine",
"the",
"best",
"default",
"value",
"for",
"the",
"qf",
"parameter"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L363-L381 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.toXmlTag | protected function toXmlTag($tag, $attrs, $content = null)
{
$xml = "<$tag ";
if ($attrs) {
$attrStrs = array();
foreach ($attrs as $attrName => $attrVal) {
$attrStrs[] = "$attrName='$attrVal'";
}
$xml .= $attrStrs ? implode(' ', $attrStrs) : '';
}
$xml .= $content ? ">$content</$tag>" : '/>';
return $xml;
} | php | protected function toXmlTag($tag, $attrs, $content = null)
{
$xml = "<$tag ";
if ($attrs) {
$attrStrs = array();
foreach ($attrs as $attrName => $attrVal) {
$attrStrs[] = "$attrName='$attrVal'";
}
$xml .= $attrStrs ? implode(' ', $attrStrs) : '';
}
$xml .= $content ? ">$content</$tag>" : '/>';
return $xml;
} | [
"protected",
"function",
"toXmlTag",
"(",
"$",
"tag",
",",
"$",
"attrs",
",",
"$",
"content",
"=",
"null",
")",
"{",
"$",
"xml",
"=",
"\"<$tag \"",
";",
"if",
"(",
"$",
"attrs",
")",
"{",
"$",
"attrStrs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"attrs",
"as",
"$",
"attrName",
"=>",
"$",
"attrVal",
")",
"{",
"$",
"attrStrs",
"[",
"]",
"=",
"\"$attrName='$attrVal'\"",
";",
"}",
"$",
"xml",
".=",
"$",
"attrStrs",
"?",
"implode",
"(",
"' '",
",",
"$",
"attrStrs",
")",
":",
"''",
";",
"}",
"$",
"xml",
".=",
"$",
"content",
"?",
"\">$content</$tag>\"",
":",
"'/>'",
";",
"return",
"$",
"xml",
";",
"}"
] | Convert definition to XML tag
@param string $tag
@param string $attrs Map of attributes
@param string $content Inner content
@return String XML tag | [
"Convert",
"definition",
"to",
"XML",
"tag"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L440-L452 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getCopyFieldDefinitions | public function getCopyFieldDefinitions()
{
$xml = array();
// Default copy fields
foreach ($this->getCopyDestinations() as $copyTo) {
foreach ($this->fulltextFields as $name => $field) {
$xml[] = "<copyField source='{$name}' dest='{$copyTo}' />";
}
}
// Explicit copy fields
foreach ($this->copyFields as $source => $fields) {
foreach ($fields as $fieldAttrs) {
$xml[] = $this->toXmlTag('copyField', $fieldAttrs);
}
}
return implode("\n\t", $xml);
} | php | public function getCopyFieldDefinitions()
{
$xml = array();
// Default copy fields
foreach ($this->getCopyDestinations() as $copyTo) {
foreach ($this->fulltextFields as $name => $field) {
$xml[] = "<copyField source='{$name}' dest='{$copyTo}' />";
}
}
// Explicit copy fields
foreach ($this->copyFields as $source => $fields) {
foreach ($fields as $fieldAttrs) {
$xml[] = $this->toXmlTag('copyField', $fieldAttrs);
}
}
return implode("\n\t", $xml);
} | [
"public",
"function",
"getCopyFieldDefinitions",
"(",
")",
"{",
"$",
"xml",
"=",
"array",
"(",
")",
";",
"// Default copy fields",
"foreach",
"(",
"$",
"this",
"->",
"getCopyDestinations",
"(",
")",
"as",
"$",
"copyTo",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fulltextFields",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"$",
"xml",
"[",
"]",
"=",
"\"<copyField source='{$name}' dest='{$copyTo}' />\"",
";",
"}",
"}",
"// Explicit copy fields",
"foreach",
"(",
"$",
"this",
"->",
"copyFields",
"as",
"$",
"source",
"=>",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldAttrs",
")",
"{",
"$",
"xml",
"[",
"]",
"=",
"$",
"this",
"->",
"toXmlTag",
"(",
"'copyField'",
",",
"$",
"fieldAttrs",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"\"\\n\\t\"",
",",
"$",
"xml",
")",
";",
"}"
] | Generate XML for copy field definitions
@return string | [
"Generate",
"XML",
"for",
"copy",
"field",
"definitions"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L474-L493 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.classIs | protected function classIs($class, $base)
{
if (is_array($base)) {
foreach ($base as $nextBase) {
if ($this->classIs($class, $nextBase)) {
return true;
}
}
return false;
}
// Check single origin
return $class === $base || is_subclass_of($class, $base);
} | php | protected function classIs($class, $base)
{
if (is_array($base)) {
foreach ($base as $nextBase) {
if ($this->classIs($class, $nextBase)) {
return true;
}
}
return false;
}
// Check single origin
return $class === $base || is_subclass_of($class, $base);
} | [
"protected",
"function",
"classIs",
"(",
"$",
"class",
",",
"$",
"base",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"base",
")",
")",
"{",
"foreach",
"(",
"$",
"base",
"as",
"$",
"nextBase",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classIs",
"(",
"$",
"class",
",",
"$",
"nextBase",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"// Check single origin",
"return",
"$",
"class",
"===",
"$",
"base",
"||",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"base",
")",
";",
"}"
] | Determine if the given object is one of the given type
@param string $class
@param array|string $base Class or list of base classes
@return bool | [
"Determine",
"if",
"the",
"given",
"object",
"is",
"one",
"of",
"the",
"given",
"type"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L502-L515 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.clearObsoleteClasses | public function clearObsoleteClasses($classes)
{
if (empty($classes)) {
return false;
}
// Delete all records which do not match the necessary classname rules
$conditions = array();
foreach ($classes as $class => $options) {
if ($options['include_children']) {
$conditions[] = "ClassHierarchy:{$class}";
} else {
$conditions[] = "ClassName:{$class}";
}
}
// Delete records which don't match any of these conditions in this index
$deleteQuery = "-(" . implode(' ', $conditions) . ")";
$this
->getService()
->deleteByQuery($deleteQuery);
return true;
} | php | public function clearObsoleteClasses($classes)
{
if (empty($classes)) {
return false;
}
// Delete all records which do not match the necessary classname rules
$conditions = array();
foreach ($classes as $class => $options) {
if ($options['include_children']) {
$conditions[] = "ClassHierarchy:{$class}";
} else {
$conditions[] = "ClassName:{$class}";
}
}
// Delete records which don't match any of these conditions in this index
$deleteQuery = "-(" . implode(' ', $conditions) . ")";
$this
->getService()
->deleteByQuery($deleteQuery);
return true;
} | [
"public",
"function",
"clearObsoleteClasses",
"(",
"$",
"classes",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"classes",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Delete all records which do not match the necessary classname rules",
"$",
"conditions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
"=>",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"options",
"[",
"'include_children'",
"]",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"ClassHierarchy:{$class}\"",
";",
"}",
"else",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"ClassName:{$class}\"",
";",
"}",
"}",
"// Delete records which don't match any of these conditions in this index",
"$",
"deleteQuery",
"=",
"\"-(\"",
".",
"implode",
"(",
"' '",
",",
"$",
"conditions",
")",
".",
"\")\"",
";",
"$",
"this",
"->",
"getService",
"(",
")",
"->",
"deleteByQuery",
"(",
"$",
"deleteQuery",
")",
";",
"return",
"true",
";",
"}"
] | Clear all records which do not match the given classname whitelist.
Can also be used to trim an index when reducing to a narrower set of classes.
Ignores current state / variant.
@param array $classes List of non-obsolete classes in the same format as SolrIndex::getClasses()
@return bool Flag if successful
@throws \Apache_Solr_HttpTransportException | [
"Clear",
"all",
"records",
"which",
"do",
"not",
"match",
"the",
"given",
"classname",
"whitelist",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L651-L673 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.applySearchVariants | protected function applySearchVariants(SearchQuery $query)
{
$classes = count($query->classes) ? $query->classes : $this->getClasses();
/** @var SearchVariant_Caller $variantCaller */
$variantCaller = SearchVariant::withCommon($classes);
$variantCaller->call('alterQuery', $query, $this);
} | php | protected function applySearchVariants(SearchQuery $query)
{
$classes = count($query->classes) ? $query->classes : $this->getClasses();
/** @var SearchVariant_Caller $variantCaller */
$variantCaller = SearchVariant::withCommon($classes);
$variantCaller->call('alterQuery', $query, $this);
} | [
"protected",
"function",
"applySearchVariants",
"(",
"SearchQuery",
"$",
"query",
")",
"{",
"$",
"classes",
"=",
"count",
"(",
"$",
"query",
"->",
"classes",
")",
"?",
"$",
"query",
"->",
"classes",
":",
"$",
"this",
"->",
"getClasses",
"(",
")",
";",
"/** @var SearchVariant_Caller $variantCaller */",
"$",
"variantCaller",
"=",
"SearchVariant",
"::",
"withCommon",
"(",
"$",
"classes",
")",
";",
"$",
"variantCaller",
"->",
"call",
"(",
"'alterQuery'",
",",
"$",
"query",
",",
"$",
"this",
")",
";",
"}"
] | With a common set of variants that are relevant to at least one class in the list (from either the query or
the current index), allow them to alter the query to add their variant column conditions.
@param SearchQuery $query | [
"With",
"a",
"common",
"set",
"of",
"variants",
"that",
"are",
"relevant",
"to",
"at",
"least",
"one",
"class",
"in",
"the",
"list",
"(",
"from",
"either",
"the",
"query",
"or",
"the",
"current",
"index",
")",
"allow",
"them",
"to",
"alter",
"the",
"query",
"to",
"add",
"their",
"variant",
"column",
"conditions",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L861-L868 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getQueryComponent | protected function getQueryComponent(SearchQuery $searchQuery, &$hlq = array())
{
$q = array();
foreach ($searchQuery->search as $search) {
$text = $search['text'];
preg_match_all('/"[^"]*"|\S+/', $text, $parts);
$fuzzy = $search['fuzzy'] ? '~' : '';
foreach ($parts[0] as $part) {
$fields = (isset($search['fields'])) ? $search['fields'] : array();
if (isset($search['boost'])) {
$fields = array_merge($fields, array_keys($search['boost']));
}
if ($fields) {
$searchq = array();
foreach ($fields as $field) {
// Escape namespace separators in class names
$field = $this->sanitiseClassName($field);
$boost = (isset($search['boost'][$field])) ? '^' . $search['boost'][$field] : '';
$searchq[] = "{$field}:" . $part . $fuzzy . $boost;
}
$q[] = '+(' . implode(' OR ', $searchq) . ')';
} else {
$q[] = '+' . $part . $fuzzy;
}
$hlq[] = $part;
}
}
return $q;
} | php | protected function getQueryComponent(SearchQuery $searchQuery, &$hlq = array())
{
$q = array();
foreach ($searchQuery->search as $search) {
$text = $search['text'];
preg_match_all('/"[^"]*"|\S+/', $text, $parts);
$fuzzy = $search['fuzzy'] ? '~' : '';
foreach ($parts[0] as $part) {
$fields = (isset($search['fields'])) ? $search['fields'] : array();
if (isset($search['boost'])) {
$fields = array_merge($fields, array_keys($search['boost']));
}
if ($fields) {
$searchq = array();
foreach ($fields as $field) {
// Escape namespace separators in class names
$field = $this->sanitiseClassName($field);
$boost = (isset($search['boost'][$field])) ? '^' . $search['boost'][$field] : '';
$searchq[] = "{$field}:" . $part . $fuzzy . $boost;
}
$q[] = '+(' . implode(' OR ', $searchq) . ')';
} else {
$q[] = '+' . $part . $fuzzy;
}
$hlq[] = $part;
}
}
return $q;
} | [
"protected",
"function",
"getQueryComponent",
"(",
"SearchQuery",
"$",
"searchQuery",
",",
"&",
"$",
"hlq",
"=",
"array",
"(",
")",
")",
"{",
"$",
"q",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"searchQuery",
"->",
"search",
"as",
"$",
"search",
")",
"{",
"$",
"text",
"=",
"$",
"search",
"[",
"'text'",
"]",
";",
"preg_match_all",
"(",
"'/\"[^\"]*\"|\\S+/'",
",",
"$",
"text",
",",
"$",
"parts",
")",
";",
"$",
"fuzzy",
"=",
"$",
"search",
"[",
"'fuzzy'",
"]",
"?",
"'~'",
":",
"''",
";",
"foreach",
"(",
"$",
"parts",
"[",
"0",
"]",
"as",
"$",
"part",
")",
"{",
"$",
"fields",
"=",
"(",
"isset",
"(",
"$",
"search",
"[",
"'fields'",
"]",
")",
")",
"?",
"$",
"search",
"[",
"'fields'",
"]",
":",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"search",
"[",
"'boost'",
"]",
")",
")",
"{",
"$",
"fields",
"=",
"array_merge",
"(",
"$",
"fields",
",",
"array_keys",
"(",
"$",
"search",
"[",
"'boost'",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"fields",
")",
"{",
"$",
"searchq",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"// Escape namespace separators in class names",
"$",
"field",
"=",
"$",
"this",
"->",
"sanitiseClassName",
"(",
"$",
"field",
")",
";",
"$",
"boost",
"=",
"(",
"isset",
"(",
"$",
"search",
"[",
"'boost'",
"]",
"[",
"$",
"field",
"]",
")",
")",
"?",
"'^'",
".",
"$",
"search",
"[",
"'boost'",
"]",
"[",
"$",
"field",
"]",
":",
"''",
";",
"$",
"searchq",
"[",
"]",
"=",
"\"{$field}:\"",
".",
"$",
"part",
".",
"$",
"fuzzy",
".",
"$",
"boost",
";",
"}",
"$",
"q",
"[",
"]",
"=",
"'+('",
".",
"implode",
"(",
"' OR '",
",",
"$",
"searchq",
")",
".",
"')'",
";",
"}",
"else",
"{",
"$",
"q",
"[",
"]",
"=",
"'+'",
".",
"$",
"part",
".",
"$",
"fuzzy",
";",
"}",
"$",
"hlq",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"}",
"return",
"$",
"q",
";",
"}"
] | Get the query (q) component for this search
@param SearchQuery $searchQuery
@param array &$hlq Highlight query returned by reference
@return array | [
"Get",
"the",
"query",
"(",
"q",
")",
"component",
"for",
"this",
"search"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L889-L920 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getRequireFiltersComponent | protected function getRequireFiltersComponent(SearchQuery $searchQuery)
{
$fq = array();
foreach ($searchQuery->require as $field => $values) {
$requireq = array();
foreach ($values as $value) {
if ($value === SearchQuery::$missing) {
$requireq[] = "(*:* -{$field}:[* TO *])";
} elseif ($value === SearchQuery::$present) {
$requireq[] = "{$field}:[* TO *]";
} elseif ($value instanceof SearchQuery_Range) {
$start = $value->start;
if ($start === null) {
$start = '*';
}
$end = $value->end;
if ($end === null) {
$end = '*';
}
$requireq[] = "$field:[$start TO $end]";
} else {
$requireq[] = $field . ':"' . $value . '"';
}
}
$fq[] = '+(' . implode(' ', $requireq) . ')';
}
return $fq;
} | php | protected function getRequireFiltersComponent(SearchQuery $searchQuery)
{
$fq = array();
foreach ($searchQuery->require as $field => $values) {
$requireq = array();
foreach ($values as $value) {
if ($value === SearchQuery::$missing) {
$requireq[] = "(*:* -{$field}:[* TO *])";
} elseif ($value === SearchQuery::$present) {
$requireq[] = "{$field}:[* TO *]";
} elseif ($value instanceof SearchQuery_Range) {
$start = $value->start;
if ($start === null) {
$start = '*';
}
$end = $value->end;
if ($end === null) {
$end = '*';
}
$requireq[] = "$field:[$start TO $end]";
} else {
$requireq[] = $field . ':"' . $value . '"';
}
}
$fq[] = '+(' . implode(' ', $requireq) . ')';
}
return $fq;
} | [
"protected",
"function",
"getRequireFiltersComponent",
"(",
"SearchQuery",
"$",
"searchQuery",
")",
"{",
"$",
"fq",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"searchQuery",
"->",
"require",
"as",
"$",
"field",
"=>",
"$",
"values",
")",
"{",
"$",
"requireq",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"SearchQuery",
"::",
"$",
"missing",
")",
"{",
"$",
"requireq",
"[",
"]",
"=",
"\"(*:* -{$field}:[* TO *])\"",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"SearchQuery",
"::",
"$",
"present",
")",
"{",
"$",
"requireq",
"[",
"]",
"=",
"\"{$field}:[* TO *]\"",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"SearchQuery_Range",
")",
"{",
"$",
"start",
"=",
"$",
"value",
"->",
"start",
";",
"if",
"(",
"$",
"start",
"===",
"null",
")",
"{",
"$",
"start",
"=",
"'*'",
";",
"}",
"$",
"end",
"=",
"$",
"value",
"->",
"end",
";",
"if",
"(",
"$",
"end",
"===",
"null",
")",
"{",
"$",
"end",
"=",
"'*'",
";",
"}",
"$",
"requireq",
"[",
"]",
"=",
"\"$field:[$start TO $end]\"",
";",
"}",
"else",
"{",
"$",
"requireq",
"[",
"]",
"=",
"$",
"field",
".",
"':\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"}",
"}",
"$",
"fq",
"[",
"]",
"=",
"'+('",
".",
"implode",
"(",
"' '",
",",
"$",
"requireq",
")",
".",
"')'",
";",
"}",
"return",
"$",
"fq",
";",
"}"
] | Parse all require constraints for inclusion in a filter query
@param SearchQuery $searchQuery
@return array List of parsed string values for each require | [
"Parse",
"all",
"require",
"constraints",
"for",
"inclusion",
"in",
"a",
"filter",
"query"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L928-L957 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getExcludeFiltersComponent | protected function getExcludeFiltersComponent(SearchQuery $searchQuery)
{
$fq = array();
foreach ($searchQuery->exclude as $field => $values) {
// Handle namespaced class names
$field = $this->sanitiseClassName($field);
$excludeq = [];
$missing = false;
foreach ($values as $value) {
if ($value === SearchQuery::$missing) {
$missing = true;
} elseif ($value === SearchQuery::$present) {
$excludeq[] = "{$field}:[* TO *]";
} elseif ($value instanceof SearchQuery_Range) {
$start = $value->start;
if ($start === null) {
$start = '*';
}
$end = $value->end;
if ($end === null) {
$end = '*';
}
$excludeq[] = "$field:[$start TO $end]";
} else {
$excludeq[] = $field . ':"' . $value . '"';
}
}
$fq[] = ($missing ? "+{$field}:[* TO *] " : '') . '-(' . implode(' ', $excludeq) . ')';
}
return $fq;
} | php | protected function getExcludeFiltersComponent(SearchQuery $searchQuery)
{
$fq = array();
foreach ($searchQuery->exclude as $field => $values) {
// Handle namespaced class names
$field = $this->sanitiseClassName($field);
$excludeq = [];
$missing = false;
foreach ($values as $value) {
if ($value === SearchQuery::$missing) {
$missing = true;
} elseif ($value === SearchQuery::$present) {
$excludeq[] = "{$field}:[* TO *]";
} elseif ($value instanceof SearchQuery_Range) {
$start = $value->start;
if ($start === null) {
$start = '*';
}
$end = $value->end;
if ($end === null) {
$end = '*';
}
$excludeq[] = "$field:[$start TO $end]";
} else {
$excludeq[] = $field . ':"' . $value . '"';
}
}
$fq[] = ($missing ? "+{$field}:[* TO *] " : '') . '-(' . implode(' ', $excludeq) . ')';
}
return $fq;
} | [
"protected",
"function",
"getExcludeFiltersComponent",
"(",
"SearchQuery",
"$",
"searchQuery",
")",
"{",
"$",
"fq",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"searchQuery",
"->",
"exclude",
"as",
"$",
"field",
"=>",
"$",
"values",
")",
"{",
"// Handle namespaced class names",
"$",
"field",
"=",
"$",
"this",
"->",
"sanitiseClassName",
"(",
"$",
"field",
")",
";",
"$",
"excludeq",
"=",
"[",
"]",
";",
"$",
"missing",
"=",
"false",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"SearchQuery",
"::",
"$",
"missing",
")",
"{",
"$",
"missing",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"SearchQuery",
"::",
"$",
"present",
")",
"{",
"$",
"excludeq",
"[",
"]",
"=",
"\"{$field}:[* TO *]\"",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"SearchQuery_Range",
")",
"{",
"$",
"start",
"=",
"$",
"value",
"->",
"start",
";",
"if",
"(",
"$",
"start",
"===",
"null",
")",
"{",
"$",
"start",
"=",
"'*'",
";",
"}",
"$",
"end",
"=",
"$",
"value",
"->",
"end",
";",
"if",
"(",
"$",
"end",
"===",
"null",
")",
"{",
"$",
"end",
"=",
"'*'",
";",
"}",
"$",
"excludeq",
"[",
"]",
"=",
"\"$field:[$start TO $end]\"",
";",
"}",
"else",
"{",
"$",
"excludeq",
"[",
"]",
"=",
"$",
"field",
".",
"':\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"}",
"}",
"$",
"fq",
"[",
"]",
"=",
"(",
"$",
"missing",
"?",
"\"+{$field}:[* TO *] \"",
":",
"''",
")",
".",
"'-('",
".",
"implode",
"(",
"' '",
",",
"$",
"excludeq",
")",
".",
"')'",
";",
"}",
"return",
"$",
"fq",
";",
"}"
] | Parse all exclude constraints for inclusion in a filter query
@param SearchQuery $searchQuery
@return array List of parsed string values for each exclusion | [
"Parse",
"all",
"exclude",
"constraints",
"for",
"inclusion",
"in",
"a",
"filter",
"query"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L965-L998 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.getFiltersComponent | public function getFiltersComponent(SearchQuery $searchQuery)
{
$criteriaComponent = $this->getCriteriaComponent($searchQuery);
$components = array_merge(
$this->getRequireFiltersComponent($searchQuery),
$this->getExcludeFiltersComponent($searchQuery)
);
if ($criteriaComponent !== null) {
$components[] = $criteriaComponent;
}
return $components;
} | php | public function getFiltersComponent(SearchQuery $searchQuery)
{
$criteriaComponent = $this->getCriteriaComponent($searchQuery);
$components = array_merge(
$this->getRequireFiltersComponent($searchQuery),
$this->getExcludeFiltersComponent($searchQuery)
);
if ($criteriaComponent !== null) {
$components[] = $criteriaComponent;
}
return $components;
} | [
"public",
"function",
"getFiltersComponent",
"(",
"SearchQuery",
"$",
"searchQuery",
")",
"{",
"$",
"criteriaComponent",
"=",
"$",
"this",
"->",
"getCriteriaComponent",
"(",
"$",
"searchQuery",
")",
";",
"$",
"components",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getRequireFiltersComponent",
"(",
"$",
"searchQuery",
")",
",",
"$",
"this",
"->",
"getExcludeFiltersComponent",
"(",
"$",
"searchQuery",
")",
")",
";",
"if",
"(",
"$",
"criteriaComponent",
"!==",
"null",
")",
"{",
"$",
"components",
"[",
"]",
"=",
"$",
"criteriaComponent",
";",
"}",
"return",
"$",
"components",
";",
"}"
] | Get all filter conditions for this search
@param SearchQuery $searchQuery
@return array
@throws \Exception | [
"Get",
"all",
"filter",
"conditions",
"for",
"this",
"search"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L1037-L1051 |
silverstripe/silverstripe-fulltextsearch | src/Solr/SolrIndex.php | SolrIndex.uploadConfig | public function uploadConfig($store)
{
// Upload the config files for this index
$store->uploadString(
$this->getIndexName(),
'schema.xml',
(string)$this->generateSchema()
);
// Upload additional files
foreach (glob($this->getExtrasPath() . '/*') as $file) {
if (is_file($file)) {
$store->uploadFile($this->getIndexName(), $file);
}
}
} | php | public function uploadConfig($store)
{
// Upload the config files for this index
$store->uploadString(
$this->getIndexName(),
'schema.xml',
(string)$this->generateSchema()
);
// Upload additional files
foreach (glob($this->getExtrasPath() . '/*') as $file) {
if (is_file($file)) {
$store->uploadFile($this->getIndexName(), $file);
}
}
} | [
"public",
"function",
"uploadConfig",
"(",
"$",
"store",
")",
"{",
"// Upload the config files for this index",
"$",
"store",
"->",
"uploadString",
"(",
"$",
"this",
"->",
"getIndexName",
"(",
")",
",",
"'schema.xml'",
",",
"(",
"string",
")",
"$",
"this",
"->",
"generateSchema",
"(",
")",
")",
";",
"// Upload additional files",
"foreach",
"(",
"glob",
"(",
"$",
"this",
"->",
"getExtrasPath",
"(",
")",
".",
"'/*'",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"$",
"store",
"->",
"uploadFile",
"(",
"$",
"this",
"->",
"getIndexName",
"(",
")",
",",
"$",
"file",
")",
";",
"}",
"}",
"}"
] | Upload config for this index to the given store
@param SolrConfigStore $store | [
"Upload",
"config",
"for",
"this",
"index",
"to",
"the",
"given",
"store"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/SolrIndex.php#L1077-L1092 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariantSubsites.php | SearchVariantSubsites.alterQuery | public function alterQuery($query, $index)
{
if ($this->isFieldFiltered('_subsite', $query) || !$this->appliesToEnvironment()) {
return;
}
$subsite = $this->currentState();
$query->addFilter('_subsite', [$subsite, SearchQuery::$missing]);
} | php | public function alterQuery($query, $index)
{
if ($this->isFieldFiltered('_subsite', $query) || !$this->appliesToEnvironment()) {
return;
}
$subsite = $this->currentState();
$query->addFilter('_subsite', [$subsite, SearchQuery::$missing]);
} | [
"public",
"function",
"alterQuery",
"(",
"$",
"query",
",",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFieldFiltered",
"(",
"'_subsite'",
",",
"$",
"query",
")",
"||",
"!",
"$",
"this",
"->",
"appliesToEnvironment",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"subsite",
"=",
"$",
"this",
"->",
"currentState",
"(",
")",
";",
"$",
"query",
"->",
"addFilter",
"(",
"'_subsite'",
",",
"[",
"$",
"subsite",
",",
"SearchQuery",
"::",
"$",
"missing",
"]",
")",
";",
"}"
] | This field has been altered to allow a user to obtain search results for a particular subsite
When attempting to do this in project code, SearchVariantSubsites kicks and overwrites any filter you've applied
This fix prevents the module from doing this if a filter is applied on the index or the query, or if a field is
being excluded specifically before being executed.
A pull request has been raised for this issue. Once accepted this forked module can be deleted and the parent
project should be used instead.
@param SearchQuery $query
@param SearchIndex $index | [
"This",
"field",
"has",
"been",
"altered",
"to",
"allow",
"a",
"user",
"to",
"obtain",
"search",
"results",
"for",
"a",
"particular",
"subsite",
"When",
"attempting",
"to",
"do",
"this",
"in",
"project",
"code",
"SearchVariantSubsites",
"kicks",
"and",
"overwrites",
"any",
"filter",
"you",
"ve",
"applied",
"This",
"fix",
"prevents",
"the",
"module",
"from",
"doing",
"this",
"if",
"a",
"filter",
"is",
"applied",
"on",
"the",
"index",
"or",
"the",
"query",
"or",
"if",
"a",
"field",
"is",
"being",
"excluded",
"specifically",
"before",
"being",
"executed",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariantSubsites.php#L108-L116 |
silverstripe/silverstripe-fulltextsearch | src/Search/Variants/SearchVariantSubsites.php | SearchVariantSubsites.extractManipulationWriteState | public function extractManipulationWriteState(&$writes)
{
$self = get_class($this);
$tableName = DataObject::getSchema()->tableName(Subsite::class);
$query = SQLSelect::create('"ID"', '"' . $tableName . '"');
$subsites = array_merge(['0'], $query->execute()->column());
foreach ($writes as $key => $write) {
$applies = $this->appliesTo($write['class'], true);
if (!$applies) {
continue;
}
if (isset($write['fields'][SiteTree::class . ':SubsiteID'])) {
$subsitesForWrite = [$write['fields'][SiteTree::class . ':SubsiteID']];
} elseif (isset($write['fields'][File::class . ':SubsiteID'])
&& (int) $write['fields'][File::class . ':SubsiteID'] !== 0
) {
// files in subsite 0 should be in all subsites as they are global
$subsitesForWrite = [$write['fields'][File::class . ':SubsiteID']];
} else {
$subsitesForWrite = $subsites;
}
$next = [];
foreach ($write['statefulids'] as $i => $statefulid) {
foreach ($subsitesForWrite as $subsiteID) {
$next[] = [
'id' => $statefulid['id'],
'state' => array_merge(
$statefulid['state'],
[$self => (string) $subsiteID]
),
];
}
}
$writes[$key]['statefulids'] = $next;
}
} | php | public function extractManipulationWriteState(&$writes)
{
$self = get_class($this);
$tableName = DataObject::getSchema()->tableName(Subsite::class);
$query = SQLSelect::create('"ID"', '"' . $tableName . '"');
$subsites = array_merge(['0'], $query->execute()->column());
foreach ($writes as $key => $write) {
$applies = $this->appliesTo($write['class'], true);
if (!$applies) {
continue;
}
if (isset($write['fields'][SiteTree::class . ':SubsiteID'])) {
$subsitesForWrite = [$write['fields'][SiteTree::class . ':SubsiteID']];
} elseif (isset($write['fields'][File::class . ':SubsiteID'])
&& (int) $write['fields'][File::class . ':SubsiteID'] !== 0
) {
// files in subsite 0 should be in all subsites as they are global
$subsitesForWrite = [$write['fields'][File::class . ':SubsiteID']];
} else {
$subsitesForWrite = $subsites;
}
$next = [];
foreach ($write['statefulids'] as $i => $statefulid) {
foreach ($subsitesForWrite as $subsiteID) {
$next[] = [
'id' => $statefulid['id'],
'state' => array_merge(
$statefulid['state'],
[$self => (string) $subsiteID]
),
];
}
}
$writes[$key]['statefulids'] = $next;
}
} | [
"public",
"function",
"extractManipulationWriteState",
"(",
"&",
"$",
"writes",
")",
"{",
"$",
"self",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"tableName",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableName",
"(",
"Subsite",
"::",
"class",
")",
";",
"$",
"query",
"=",
"SQLSelect",
"::",
"create",
"(",
"'\"ID\"'",
",",
"'\"'",
".",
"$",
"tableName",
".",
"'\"'",
")",
";",
"$",
"subsites",
"=",
"array_merge",
"(",
"[",
"'0'",
"]",
",",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"column",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"writes",
"as",
"$",
"key",
"=>",
"$",
"write",
")",
"{",
"$",
"applies",
"=",
"$",
"this",
"->",
"appliesTo",
"(",
"$",
"write",
"[",
"'class'",
"]",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"applies",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"write",
"[",
"'fields'",
"]",
"[",
"SiteTree",
"::",
"class",
".",
"':SubsiteID'",
"]",
")",
")",
"{",
"$",
"subsitesForWrite",
"=",
"[",
"$",
"write",
"[",
"'fields'",
"]",
"[",
"SiteTree",
"::",
"class",
".",
"':SubsiteID'",
"]",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"write",
"[",
"'fields'",
"]",
"[",
"File",
"::",
"class",
".",
"':SubsiteID'",
"]",
")",
"&&",
"(",
"int",
")",
"$",
"write",
"[",
"'fields'",
"]",
"[",
"File",
"::",
"class",
".",
"':SubsiteID'",
"]",
"!==",
"0",
")",
"{",
"// files in subsite 0 should be in all subsites as they are global",
"$",
"subsitesForWrite",
"=",
"[",
"$",
"write",
"[",
"'fields'",
"]",
"[",
"File",
"::",
"class",
".",
"':SubsiteID'",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"subsitesForWrite",
"=",
"$",
"subsites",
";",
"}",
"$",
"next",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"write",
"[",
"'statefulids'",
"]",
"as",
"$",
"i",
"=>",
"$",
"statefulid",
")",
"{",
"foreach",
"(",
"$",
"subsitesForWrite",
"as",
"$",
"subsiteID",
")",
"{",
"$",
"next",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"statefulid",
"[",
"'id'",
"]",
",",
"'state'",
"=>",
"array_merge",
"(",
"$",
"statefulid",
"[",
"'state'",
"]",
",",
"[",
"$",
"self",
"=>",
"(",
"string",
")",
"$",
"subsiteID",
"]",
")",
",",
"]",
";",
"}",
"}",
"$",
"writes",
"[",
"$",
"key",
"]",
"[",
"'statefulids'",
"]",
"=",
"$",
"next",
";",
"}",
"}"
] | We need _really_ complicated logic to find just the changed subsites (because we use versions there's no explicit
deletes, just new versions with different members) so just always use all of them | [
"We",
"need",
"_really_",
"complicated",
"logic",
"to",
"find",
"just",
"the",
"changed",
"subsites",
"(",
"because",
"we",
"use",
"versions",
"there",
"s",
"no",
"explicit",
"deletes",
"just",
"new",
"versions",
"with",
"different",
"members",
")",
"so",
"just",
"always",
"use",
"all",
"of",
"them"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Variants/SearchVariantSubsites.php#L122-L160 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.fieldData | public function fieldData($field, $forceType = null, $extraOptions = [])
{
$fullfield = str_replace(".", "_", $field);
$sources = $this->getClasses();
foreach ($sources as $source => $options) {
$sources[$source]['base'] = DataObject::getSchema()->baseDataClass($source);
$sources[$source]['lookup_chain'] = [];
}
$found = [];
if (strpos($field, '.') !== false) {
$lookups = explode(".", $field);
$field = array_pop($lookups);
foreach ($lookups as $lookup) {
$next = [];
foreach ($sources as $source => $baseOptions) {
$source = $this->getSourceName($source);
foreach (SearchIntrospection::hierarchy($source, $baseOptions['include_children']) as $dataclass) {
$class = null;
$options = $baseOptions;
$singleton = singleton($dataclass);
$schema = DataObject::getSchema();
$className = $singleton->getClassName();
if ($hasOne = $schema->hasOneComponent($className, $lookup)) {
// we only want to include base class for relation, omit classes that inherited the relation
$relationList = Config::inst()->get($dataclass, 'has_one', Config::UNINHERITED);
$relationList = (!is_null($relationList)) ? $relationList : [];
if (!array_key_exists($lookup, $relationList)) {
continue;
}
$class = $hasOne;
$options['lookup_chain'][] = array(
'call' => 'method', 'method' => $lookup,
'through' => 'has_one', 'class' => $dataclass, 'otherclass' => $class, 'foreignkey' => "{$lookup}ID"
);
} elseif ($hasMany = $schema->hasManyComponent($className, $lookup)) {
// we only want to include base class for relation, omit classes that inherited the relation
$relationList = Config::inst()->get($dataclass, 'has_many', Config::UNINHERITED);
$relationList = (!is_null($relationList)) ? $relationList : [];
if (!array_key_exists($lookup, $relationList)) {
continue;
}
$class = $hasMany;
$options['multi_valued'] = true;
$options['lookup_chain'][] = array(
'call' => 'method', 'method' => $lookup,
'through' => 'has_many', 'class' => $dataclass, 'otherclass' => $class, 'foreignkey' => $schema->getRemoteJoinField($className, $lookup, 'has_many')
);
} elseif ($manyMany = $schema->manyManyComponent($className, $lookup)) {
// we only want to include base class for relation, omit classes that inherited the relation
$relationList = Config::inst()->get($dataclass, 'many_many', Config::UNINHERITED);
$relationList = (!is_null($relationList)) ? $relationList : [];
if (!array_key_exists($lookup, $relationList)) {
continue;
}
$class = $manyMany['childClass'];
$options['multi_valued'] = true;
$options['lookup_chain'][] = array(
'call' => 'method',
'method' => $lookup,
'through' => 'many_many',
'class' => $dataclass,
'otherclass' => $class,
'details' => $manyMany,
);
}
if (is_string($class) && $class) {
if (!isset($options['origin'])) {
$options['origin'] = $dataclass;
}
// we add suffix here to prevent the relation to be overwritten by other instances
// all sources lookups must clean the source name before reading it via getSourceName()
$next[$class . self::config()->get('class_delimiter') . $dataclass] = $options;
}
}
}
if (!$next) {
return $next;
} // Early out to avoid excessive empty looping
$sources = $next;
}
}
foreach ($sources as $class => $options) {
$class = $this->getSourceName($class);
$dataclasses = SearchIntrospection::hierarchy($class, $options['include_children']);
while (count($dataclasses)) {
$dataclass = array_shift($dataclasses);
$type = null;
$fieldoptions = $options;
$fields = DataObject::getSchema()->databaseFields($class);
if (isset($fields[$field])) {
$type = $fields[$field];
$fieldoptions['lookup_chain'][] = array('call' => 'property', 'property' => $field);
} else {
$singleton = singleton($dataclass);
if ($singleton->hasMethod("get$field") || $singleton->hasField($field)) {
$type = $singleton->castingClass($field);
if (!$type) {
$type = 'String';
}
if ($singleton->hasMethod("get$field")) {
$fieldoptions['lookup_chain'][] = array('call' => 'method', 'method' => "get$field");
} else {
$fieldoptions['lookup_chain'][] = array('call' => 'property', 'property' => $field);
}
}
}
if ($type) {
// Don't search through child classes of a class we matched on. TODO: Should we?
$dataclasses = array_diff($dataclasses, array_values(ClassInfo::subclassesFor($dataclass)));
// Trim arguments off the type string
if (preg_match('/^(\w+)\(/', $type, $match)) {
$type = $match[1];
}
// Get the origin
$origin = isset($fieldoptions['origin']) ? $fieldoptions['origin'] : $dataclass;
$found["{$origin}_{$fullfield}"] = array(
'name' => "{$origin}_{$fullfield}",
'field' => $field,
'fullfield' => $fullfield,
'base' => $fieldoptions['base'],
'origin' => $origin,
'class' => $dataclass,
'lookup_chain' => $fieldoptions['lookup_chain'],
'type' => $forceType ? $forceType : $type,
'multi_valued' => isset($fieldoptions['multi_valued']) ? true : false,
'extra_options' => $extraOptions
);
}
}
}
return $found;
} | php | public function fieldData($field, $forceType = null, $extraOptions = [])
{
$fullfield = str_replace(".", "_", $field);
$sources = $this->getClasses();
foreach ($sources as $source => $options) {
$sources[$source]['base'] = DataObject::getSchema()->baseDataClass($source);
$sources[$source]['lookup_chain'] = [];
}
$found = [];
if (strpos($field, '.') !== false) {
$lookups = explode(".", $field);
$field = array_pop($lookups);
foreach ($lookups as $lookup) {
$next = [];
foreach ($sources as $source => $baseOptions) {
$source = $this->getSourceName($source);
foreach (SearchIntrospection::hierarchy($source, $baseOptions['include_children']) as $dataclass) {
$class = null;
$options = $baseOptions;
$singleton = singleton($dataclass);
$schema = DataObject::getSchema();
$className = $singleton->getClassName();
if ($hasOne = $schema->hasOneComponent($className, $lookup)) {
// we only want to include base class for relation, omit classes that inherited the relation
$relationList = Config::inst()->get($dataclass, 'has_one', Config::UNINHERITED);
$relationList = (!is_null($relationList)) ? $relationList : [];
if (!array_key_exists($lookup, $relationList)) {
continue;
}
$class = $hasOne;
$options['lookup_chain'][] = array(
'call' => 'method', 'method' => $lookup,
'through' => 'has_one', 'class' => $dataclass, 'otherclass' => $class, 'foreignkey' => "{$lookup}ID"
);
} elseif ($hasMany = $schema->hasManyComponent($className, $lookup)) {
// we only want to include base class for relation, omit classes that inherited the relation
$relationList = Config::inst()->get($dataclass, 'has_many', Config::UNINHERITED);
$relationList = (!is_null($relationList)) ? $relationList : [];
if (!array_key_exists($lookup, $relationList)) {
continue;
}
$class = $hasMany;
$options['multi_valued'] = true;
$options['lookup_chain'][] = array(
'call' => 'method', 'method' => $lookup,
'through' => 'has_many', 'class' => $dataclass, 'otherclass' => $class, 'foreignkey' => $schema->getRemoteJoinField($className, $lookup, 'has_many')
);
} elseif ($manyMany = $schema->manyManyComponent($className, $lookup)) {
// we only want to include base class for relation, omit classes that inherited the relation
$relationList = Config::inst()->get($dataclass, 'many_many', Config::UNINHERITED);
$relationList = (!is_null($relationList)) ? $relationList : [];
if (!array_key_exists($lookup, $relationList)) {
continue;
}
$class = $manyMany['childClass'];
$options['multi_valued'] = true;
$options['lookup_chain'][] = array(
'call' => 'method',
'method' => $lookup,
'through' => 'many_many',
'class' => $dataclass,
'otherclass' => $class,
'details' => $manyMany,
);
}
if (is_string($class) && $class) {
if (!isset($options['origin'])) {
$options['origin'] = $dataclass;
}
// we add suffix here to prevent the relation to be overwritten by other instances
// all sources lookups must clean the source name before reading it via getSourceName()
$next[$class . self::config()->get('class_delimiter') . $dataclass] = $options;
}
}
}
if (!$next) {
return $next;
} // Early out to avoid excessive empty looping
$sources = $next;
}
}
foreach ($sources as $class => $options) {
$class = $this->getSourceName($class);
$dataclasses = SearchIntrospection::hierarchy($class, $options['include_children']);
while (count($dataclasses)) {
$dataclass = array_shift($dataclasses);
$type = null;
$fieldoptions = $options;
$fields = DataObject::getSchema()->databaseFields($class);
if (isset($fields[$field])) {
$type = $fields[$field];
$fieldoptions['lookup_chain'][] = array('call' => 'property', 'property' => $field);
} else {
$singleton = singleton($dataclass);
if ($singleton->hasMethod("get$field") || $singleton->hasField($field)) {
$type = $singleton->castingClass($field);
if (!$type) {
$type = 'String';
}
if ($singleton->hasMethod("get$field")) {
$fieldoptions['lookup_chain'][] = array('call' => 'method', 'method' => "get$field");
} else {
$fieldoptions['lookup_chain'][] = array('call' => 'property', 'property' => $field);
}
}
}
if ($type) {
// Don't search through child classes of a class we matched on. TODO: Should we?
$dataclasses = array_diff($dataclasses, array_values(ClassInfo::subclassesFor($dataclass)));
// Trim arguments off the type string
if (preg_match('/^(\w+)\(/', $type, $match)) {
$type = $match[1];
}
// Get the origin
$origin = isset($fieldoptions['origin']) ? $fieldoptions['origin'] : $dataclass;
$found["{$origin}_{$fullfield}"] = array(
'name' => "{$origin}_{$fullfield}",
'field' => $field,
'fullfield' => $fullfield,
'base' => $fieldoptions['base'],
'origin' => $origin,
'class' => $dataclass,
'lookup_chain' => $fieldoptions['lookup_chain'],
'type' => $forceType ? $forceType : $type,
'multi_valued' => isset($fieldoptions['multi_valued']) ? true : false,
'extra_options' => $extraOptions
);
}
}
}
return $found;
} | [
"public",
"function",
"fieldData",
"(",
"$",
"field",
",",
"$",
"forceType",
"=",
"null",
",",
"$",
"extraOptions",
"=",
"[",
"]",
")",
"{",
"$",
"fullfield",
"=",
"str_replace",
"(",
"\".\"",
",",
"\"_\"",
",",
"$",
"field",
")",
";",
"$",
"sources",
"=",
"$",
"this",
"->",
"getClasses",
"(",
")",
";",
"foreach",
"(",
"$",
"sources",
"as",
"$",
"source",
"=>",
"$",
"options",
")",
"{",
"$",
"sources",
"[",
"$",
"source",
"]",
"[",
"'base'",
"]",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"baseDataClass",
"(",
"$",
"source",
")",
";",
"$",
"sources",
"[",
"$",
"source",
"]",
"[",
"'lookup_chain'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"found",
"=",
"[",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"lookups",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"field",
")",
";",
"$",
"field",
"=",
"array_pop",
"(",
"$",
"lookups",
")",
";",
"foreach",
"(",
"$",
"lookups",
"as",
"$",
"lookup",
")",
"{",
"$",
"next",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sources",
"as",
"$",
"source",
"=>",
"$",
"baseOptions",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"getSourceName",
"(",
"$",
"source",
")",
";",
"foreach",
"(",
"SearchIntrospection",
"::",
"hierarchy",
"(",
"$",
"source",
",",
"$",
"baseOptions",
"[",
"'include_children'",
"]",
")",
"as",
"$",
"dataclass",
")",
"{",
"$",
"class",
"=",
"null",
";",
"$",
"options",
"=",
"$",
"baseOptions",
";",
"$",
"singleton",
"=",
"singleton",
"(",
"$",
"dataclass",
")",
";",
"$",
"schema",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
";",
"$",
"className",
"=",
"$",
"singleton",
"->",
"getClassName",
"(",
")",
";",
"if",
"(",
"$",
"hasOne",
"=",
"$",
"schema",
"->",
"hasOneComponent",
"(",
"$",
"className",
",",
"$",
"lookup",
")",
")",
"{",
"// we only want to include base class for relation, omit classes that inherited the relation",
"$",
"relationList",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"dataclass",
",",
"'has_one'",
",",
"Config",
"::",
"UNINHERITED",
")",
";",
"$",
"relationList",
"=",
"(",
"!",
"is_null",
"(",
"$",
"relationList",
")",
")",
"?",
"$",
"relationList",
":",
"[",
"]",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"lookup",
",",
"$",
"relationList",
")",
")",
"{",
"continue",
";",
"}",
"$",
"class",
"=",
"$",
"hasOne",
";",
"$",
"options",
"[",
"'lookup_chain'",
"]",
"[",
"]",
"=",
"array",
"(",
"'call'",
"=>",
"'method'",
",",
"'method'",
"=>",
"$",
"lookup",
",",
"'through'",
"=>",
"'has_one'",
",",
"'class'",
"=>",
"$",
"dataclass",
",",
"'otherclass'",
"=>",
"$",
"class",
",",
"'foreignkey'",
"=>",
"\"{$lookup}ID\"",
")",
";",
"}",
"elseif",
"(",
"$",
"hasMany",
"=",
"$",
"schema",
"->",
"hasManyComponent",
"(",
"$",
"className",
",",
"$",
"lookup",
")",
")",
"{",
"// we only want to include base class for relation, omit classes that inherited the relation",
"$",
"relationList",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"dataclass",
",",
"'has_many'",
",",
"Config",
"::",
"UNINHERITED",
")",
";",
"$",
"relationList",
"=",
"(",
"!",
"is_null",
"(",
"$",
"relationList",
")",
")",
"?",
"$",
"relationList",
":",
"[",
"]",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"lookup",
",",
"$",
"relationList",
")",
")",
"{",
"continue",
";",
"}",
"$",
"class",
"=",
"$",
"hasMany",
";",
"$",
"options",
"[",
"'multi_valued'",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"'lookup_chain'",
"]",
"[",
"]",
"=",
"array",
"(",
"'call'",
"=>",
"'method'",
",",
"'method'",
"=>",
"$",
"lookup",
",",
"'through'",
"=>",
"'has_many'",
",",
"'class'",
"=>",
"$",
"dataclass",
",",
"'otherclass'",
"=>",
"$",
"class",
",",
"'foreignkey'",
"=>",
"$",
"schema",
"->",
"getRemoteJoinField",
"(",
"$",
"className",
",",
"$",
"lookup",
",",
"'has_many'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"manyMany",
"=",
"$",
"schema",
"->",
"manyManyComponent",
"(",
"$",
"className",
",",
"$",
"lookup",
")",
")",
"{",
"// we only want to include base class for relation, omit classes that inherited the relation",
"$",
"relationList",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"dataclass",
",",
"'many_many'",
",",
"Config",
"::",
"UNINHERITED",
")",
";",
"$",
"relationList",
"=",
"(",
"!",
"is_null",
"(",
"$",
"relationList",
")",
")",
"?",
"$",
"relationList",
":",
"[",
"]",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"lookup",
",",
"$",
"relationList",
")",
")",
"{",
"continue",
";",
"}",
"$",
"class",
"=",
"$",
"manyMany",
"[",
"'childClass'",
"]",
";",
"$",
"options",
"[",
"'multi_valued'",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"'lookup_chain'",
"]",
"[",
"]",
"=",
"array",
"(",
"'call'",
"=>",
"'method'",
",",
"'method'",
"=>",
"$",
"lookup",
",",
"'through'",
"=>",
"'many_many'",
",",
"'class'",
"=>",
"$",
"dataclass",
",",
"'otherclass'",
"=>",
"$",
"class",
",",
"'details'",
"=>",
"$",
"manyMany",
",",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
"&&",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'origin'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'origin'",
"]",
"=",
"$",
"dataclass",
";",
"}",
"// we add suffix here to prevent the relation to be overwritten by other instances",
"// all sources lookups must clean the source name before reading it via getSourceName()",
"$",
"next",
"[",
"$",
"class",
".",
"self",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'class_delimiter'",
")",
".",
"$",
"dataclass",
"]",
"=",
"$",
"options",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"next",
")",
"{",
"return",
"$",
"next",
";",
"}",
"// Early out to avoid excessive empty looping",
"$",
"sources",
"=",
"$",
"next",
";",
"}",
"}",
"foreach",
"(",
"$",
"sources",
"as",
"$",
"class",
"=>",
"$",
"options",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"getSourceName",
"(",
"$",
"class",
")",
";",
"$",
"dataclasses",
"=",
"SearchIntrospection",
"::",
"hierarchy",
"(",
"$",
"class",
",",
"$",
"options",
"[",
"'include_children'",
"]",
")",
";",
"while",
"(",
"count",
"(",
"$",
"dataclasses",
")",
")",
"{",
"$",
"dataclass",
"=",
"array_shift",
"(",
"$",
"dataclasses",
")",
";",
"$",
"type",
"=",
"null",
";",
"$",
"fieldoptions",
"=",
"$",
"options",
";",
"$",
"fields",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"databaseFields",
"(",
"$",
"class",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"fields",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"fields",
"[",
"$",
"field",
"]",
";",
"$",
"fieldoptions",
"[",
"'lookup_chain'",
"]",
"[",
"]",
"=",
"array",
"(",
"'call'",
"=>",
"'property'",
",",
"'property'",
"=>",
"$",
"field",
")",
";",
"}",
"else",
"{",
"$",
"singleton",
"=",
"singleton",
"(",
"$",
"dataclass",
")",
";",
"if",
"(",
"$",
"singleton",
"->",
"hasMethod",
"(",
"\"get$field\"",
")",
"||",
"$",
"singleton",
"->",
"hasField",
"(",
"$",
"field",
")",
")",
"{",
"$",
"type",
"=",
"$",
"singleton",
"->",
"castingClass",
"(",
"$",
"field",
")",
";",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"'String'",
";",
"}",
"if",
"(",
"$",
"singleton",
"->",
"hasMethod",
"(",
"\"get$field\"",
")",
")",
"{",
"$",
"fieldoptions",
"[",
"'lookup_chain'",
"]",
"[",
"]",
"=",
"array",
"(",
"'call'",
"=>",
"'method'",
",",
"'method'",
"=>",
"\"get$field\"",
")",
";",
"}",
"else",
"{",
"$",
"fieldoptions",
"[",
"'lookup_chain'",
"]",
"[",
"]",
"=",
"array",
"(",
"'call'",
"=>",
"'property'",
",",
"'property'",
"=>",
"$",
"field",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"type",
")",
"{",
"// Don't search through child classes of a class we matched on. TODO: Should we?",
"$",
"dataclasses",
"=",
"array_diff",
"(",
"$",
"dataclasses",
",",
"array_values",
"(",
"ClassInfo",
"::",
"subclassesFor",
"(",
"$",
"dataclass",
")",
")",
")",
";",
"// Trim arguments off the type string",
"if",
"(",
"preg_match",
"(",
"'/^(\\w+)\\(/'",
",",
"$",
"type",
",",
"$",
"match",
")",
")",
"{",
"$",
"type",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"// Get the origin",
"$",
"origin",
"=",
"isset",
"(",
"$",
"fieldoptions",
"[",
"'origin'",
"]",
")",
"?",
"$",
"fieldoptions",
"[",
"'origin'",
"]",
":",
"$",
"dataclass",
";",
"$",
"found",
"[",
"\"{$origin}_{$fullfield}\"",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"\"{$origin}_{$fullfield}\"",
",",
"'field'",
"=>",
"$",
"field",
",",
"'fullfield'",
"=>",
"$",
"fullfield",
",",
"'base'",
"=>",
"$",
"fieldoptions",
"[",
"'base'",
"]",
",",
"'origin'",
"=>",
"$",
"origin",
",",
"'class'",
"=>",
"$",
"dataclass",
",",
"'lookup_chain'",
"=>",
"$",
"fieldoptions",
"[",
"'lookup_chain'",
"]",
",",
"'type'",
"=>",
"$",
"forceType",
"?",
"$",
"forceType",
":",
"$",
"type",
",",
"'multi_valued'",
"=>",
"isset",
"(",
"$",
"fieldoptions",
"[",
"'multi_valued'",
"]",
")",
"?",
"true",
":",
"false",
",",
"'extra_options'",
"=>",
"$",
"extraOptions",
")",
";",
"}",
"}",
"}",
"return",
"$",
"found",
";",
"}"
] | Examines the classes this index is built on to try and find defined fields in the class hierarchy
for those classes.
Looks for db and viewable-data fields, although can't necessarily find type for viewable-data fields.
If multiple classes have a relation with the same name all of these will be included in the search index
Note that only classes that have the relations uninherited (defined in them) will be listed
this is because inherited relations do not need to be processed by index explicitly | [
"Examines",
"the",
"classes",
"this",
"index",
"is",
"built",
"on",
"to",
"try",
"and",
"find",
"defined",
"fields",
"in",
"the",
"class",
"hierarchy",
"for",
"those",
"classes",
".",
"Looks",
"for",
"db",
"and",
"viewable",
"-",
"data",
"fields",
"although",
"can",
"t",
"necessarily",
"find",
"type",
"for",
"viewable",
"-",
"data",
"fields",
".",
"If",
"multiple",
"classes",
"have",
"a",
"relation",
"with",
"the",
"same",
"name",
"all",
"of",
"these",
"will",
"be",
"included",
"in",
"the",
"search",
"index",
"Note",
"that",
"only",
"classes",
"that",
"have",
"the",
"relations",
"uninherited",
"(",
"defined",
"in",
"them",
")",
"will",
"be",
"listed",
"this",
"is",
"because",
"inherited",
"relations",
"do",
"not",
"need",
"to",
"be",
"processed",
"by",
"index",
"explicitly"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L103-L256 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.addClass | public function addClass($class, $options = array())
{
if ($this->fulltextFields || $this->filterFields || $this->sortFields) {
throw new Exception('Can\'t add class to Index after fields have already been added');
}
$options = array_merge(array(
'include_children' => true
), $options);
$this->classes[$class] = $options;
} | php | public function addClass($class, $options = array())
{
if ($this->fulltextFields || $this->filterFields || $this->sortFields) {
throw new Exception('Can\'t add class to Index after fields have already been added');
}
$options = array_merge(array(
'include_children' => true
), $options);
$this->classes[$class] = $options;
} | [
"public",
"function",
"addClass",
"(",
"$",
"class",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fulltextFields",
"||",
"$",
"this",
"->",
"filterFields",
"||",
"$",
"this",
"->",
"sortFields",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Can\\'t add class to Index after fields have already been added'",
")",
";",
"}",
"$",
"options",
"=",
"array_merge",
"(",
"array",
"(",
"'include_children'",
"=>",
"true",
")",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"classes",
"[",
"$",
"class",
"]",
"=",
"$",
"options",
";",
"}"
] | Add a DataObject subclass whose instances should be included in this index
Can only be called when addFulltextField, addFilterField, addSortField and addAllFulltextFields have not
yet been called for this index instance
@throws Exception
@param string $class - The class to include
@param array $options - TODO: Remove | [
"Add",
"a",
"DataObject",
"subclass",
"whose",
"instances",
"should",
"be",
"included",
"in",
"this",
"index"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L280-L291 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.addFulltextField | public function addFulltextField($field, $forceType = null, $extraOptions = array())
{
$this->fulltextFields = array_merge($this->fulltextFields, $this->fieldData($field, $forceType, $extraOptions));
} | php | public function addFulltextField($field, $forceType = null, $extraOptions = array())
{
$this->fulltextFields = array_merge($this->fulltextFields, $this->fieldData($field, $forceType, $extraOptions));
} | [
"public",
"function",
"addFulltextField",
"(",
"$",
"field",
",",
"$",
"forceType",
"=",
"null",
",",
"$",
"extraOptions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"fulltextFields",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"fulltextFields",
",",
"$",
"this",
"->",
"fieldData",
"(",
"$",
"field",
",",
"$",
"forceType",
",",
"$",
"extraOptions",
")",
")",
";",
"}"
] | Add a field that should be fulltext searchable
@param string $field - The field to add
@param string $forceType - The type to force this field as (required in some cases, when not detectable from metadata)
@param string $extraOptions - Dependent on search implementation | [
"Add",
"a",
"field",
"that",
"should",
"be",
"fulltext",
"searchable"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L307-L310 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.addFilterField | public function addFilterField($field, $forceType = null, $extraOptions = array())
{
$this->filterFields = array_merge($this->filterFields, $this->fieldData($field, $forceType, $extraOptions));
} | php | public function addFilterField($field, $forceType = null, $extraOptions = array())
{
$this->filterFields = array_merge($this->filterFields, $this->fieldData($field, $forceType, $extraOptions));
} | [
"public",
"function",
"addFilterField",
"(",
"$",
"field",
",",
"$",
"forceType",
"=",
"null",
",",
"$",
"extraOptions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"filterFields",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"filterFields",
",",
"$",
"this",
"->",
"fieldData",
"(",
"$",
"field",
",",
"$",
"forceType",
",",
"$",
"extraOptions",
")",
")",
";",
"}"
] | Add a field that should be filterable
@param string $field - The field to add
@param string $forceType - The type to force this field as (required in some cases, when not detectable from metadata)
@param string $extraOptions - Dependent on search implementation | [
"Add",
"a",
"field",
"that",
"should",
"be",
"filterable"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L323-L326 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.addSortField | public function addSortField($field, $forceType = null, $extraOptions = array())
{
$this->sortFields = array_merge($this->sortFields, $this->fieldData($field, $forceType, $extraOptions));
} | php | public function addSortField($field, $forceType = null, $extraOptions = array())
{
$this->sortFields = array_merge($this->sortFields, $this->fieldData($field, $forceType, $extraOptions));
} | [
"public",
"function",
"addSortField",
"(",
"$",
"field",
",",
"$",
"forceType",
"=",
"null",
",",
"$",
"extraOptions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"sortFields",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"sortFields",
",",
"$",
"this",
"->",
"fieldData",
"(",
"$",
"field",
",",
"$",
"forceType",
",",
"$",
"extraOptions",
")",
")",
";",
"}"
] | Add a field that should be sortable
@param string $field - The field to add
@param string $forceType - The type to force this field as (required in some cases, when not detectable from metadata)
@param string $extraOptions - Dependent on search implementation | [
"Add",
"a",
"field",
"that",
"should",
"be",
"sortable"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L339-L342 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.addAllFulltextFields | public function addAllFulltextFields($includeSubclasses = true)
{
foreach ($this->getClasses() as $class => $options) {
$classHierarchy = SearchIntrospection::hierarchy($class, $includeSubclasses, true);
foreach ($classHierarchy as $dataClass) {
$fields = DataObject::getSchema()->databaseFields($dataClass);
foreach ($fields as $field => $type) {
list($type, $args) = ClassInfo::parse_class_spec($type);
/** @var DBField $object */
$object = Injector::inst()->get($type, false, ['Name' => 'test']);
if ($object instanceof DBString) {
$this->addFulltextField($field);
}
}
}
}
} | php | public function addAllFulltextFields($includeSubclasses = true)
{
foreach ($this->getClasses() as $class => $options) {
$classHierarchy = SearchIntrospection::hierarchy($class, $includeSubclasses, true);
foreach ($classHierarchy as $dataClass) {
$fields = DataObject::getSchema()->databaseFields($dataClass);
foreach ($fields as $field => $type) {
list($type, $args) = ClassInfo::parse_class_spec($type);
/** @var DBField $object */
$object = Injector::inst()->get($type, false, ['Name' => 'test']);
if ($object instanceof DBString) {
$this->addFulltextField($field);
}
}
}
}
} | [
"public",
"function",
"addAllFulltextFields",
"(",
"$",
"includeSubclasses",
"=",
"true",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getClasses",
"(",
")",
"as",
"$",
"class",
"=>",
"$",
"options",
")",
"{",
"$",
"classHierarchy",
"=",
"SearchIntrospection",
"::",
"hierarchy",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"classHierarchy",
"as",
"$",
"dataClass",
")",
"{",
"$",
"fields",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"databaseFields",
"(",
"$",
"dataClass",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"type",
")",
"{",
"list",
"(",
"$",
"type",
",",
"$",
"args",
")",
"=",
"ClassInfo",
"::",
"parse_class_spec",
"(",
"$",
"type",
")",
";",
"/** @var DBField $object */",
"$",
"object",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"type",
",",
"false",
",",
"[",
"'Name'",
"=>",
"'test'",
"]",
")",
";",
"if",
"(",
"$",
"object",
"instanceof",
"DBString",
")",
"{",
"$",
"this",
"->",
"addFulltextField",
"(",
"$",
"field",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Add all database-backed text fields as fulltext searchable fields.
For every class included in the index, examines those classes and all subclasses looking for "Text" database
fields (Varchar, Text, HTMLText, etc) and adds them all as fulltext searchable fields. | [
"Add",
"all",
"database",
"-",
"backed",
"text",
"fields",
"as",
"fulltext",
"searchable",
"fields",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L355-L374 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.variantStateExcluded | public function variantStateExcluded($state)
{
foreach ($this->excludedVariantStates as $excludedstate) {
$matches = true;
foreach ($excludedstate as $variant => $variantstate) {
if (!isset($state[$variant]) || $state[$variant] != $variantstate) {
$matches = false;
break;
}
}
if ($matches) {
return true;
}
}
} | php | public function variantStateExcluded($state)
{
foreach ($this->excludedVariantStates as $excludedstate) {
$matches = true;
foreach ($excludedstate as $variant => $variantstate) {
if (!isset($state[$variant]) || $state[$variant] != $variantstate) {
$matches = false;
break;
}
}
if ($matches) {
return true;
}
}
} | [
"public",
"function",
"variantStateExcluded",
"(",
"$",
"state",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"excludedVariantStates",
"as",
"$",
"excludedstate",
")",
"{",
"$",
"matches",
"=",
"true",
";",
"foreach",
"(",
"$",
"excludedstate",
"as",
"$",
"variant",
"=>",
"$",
"variantstate",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"state",
"[",
"$",
"variant",
"]",
")",
"||",
"$",
"state",
"[",
"$",
"variant",
"]",
"!=",
"$",
"variantstate",
")",
"{",
"$",
"matches",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"matches",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}"
] | Returns true if some variant state should be ignored | [
"Returns",
"true",
"if",
"some",
"variant",
"state",
"should",
"be",
"ignored"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L393-L409 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.getDerivedFields | public function getDerivedFields()
{
if ($this->derivedFields === null) {
$this->derivedFields = array();
foreach ($this->getFieldsIterator() as $name => $field) {
if (count($field['lookup_chain']) < 2) {
continue;
}
$key = sha1($field['base'] . serialize($field['lookup_chain']));
$fieldname = "{$field['class']}:{$field['field']}";
if (isset($this->derivedFields[$key])) {
$this->derivedFields[$key]['fields'][$fieldname] = $fieldname;
SearchIntrospection::add_unique_by_ancestor($this->derivedFields['classes'], $field['class']);
} else {
$chain = array_reverse($field['lookup_chain']);
array_shift($chain);
$this->derivedFields[$key] = array(
'base' => $field['base'],
'fields' => array($fieldname => $fieldname),
'classes' => array($field['class']),
'chain' => $chain
);
}
}
}
return $this->derivedFields;
} | php | public function getDerivedFields()
{
if ($this->derivedFields === null) {
$this->derivedFields = array();
foreach ($this->getFieldsIterator() as $name => $field) {
if (count($field['lookup_chain']) < 2) {
continue;
}
$key = sha1($field['base'] . serialize($field['lookup_chain']));
$fieldname = "{$field['class']}:{$field['field']}";
if (isset($this->derivedFields[$key])) {
$this->derivedFields[$key]['fields'][$fieldname] = $fieldname;
SearchIntrospection::add_unique_by_ancestor($this->derivedFields['classes'], $field['class']);
} else {
$chain = array_reverse($field['lookup_chain']);
array_shift($chain);
$this->derivedFields[$key] = array(
'base' => $field['base'],
'fields' => array($fieldname => $fieldname),
'classes' => array($field['class']),
'chain' => $chain
);
}
}
}
return $this->derivedFields;
} | [
"public",
"function",
"getDerivedFields",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"derivedFields",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"derivedFields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFieldsIterator",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"field",
"[",
"'lookup_chain'",
"]",
")",
"<",
"2",
")",
"{",
"continue",
";",
"}",
"$",
"key",
"=",
"sha1",
"(",
"$",
"field",
"[",
"'base'",
"]",
".",
"serialize",
"(",
"$",
"field",
"[",
"'lookup_chain'",
"]",
")",
")",
";",
"$",
"fieldname",
"=",
"\"{$field['class']}:{$field['field']}\"",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"derivedFields",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"derivedFields",
"[",
"$",
"key",
"]",
"[",
"'fields'",
"]",
"[",
"$",
"fieldname",
"]",
"=",
"$",
"fieldname",
";",
"SearchIntrospection",
"::",
"add_unique_by_ancestor",
"(",
"$",
"this",
"->",
"derivedFields",
"[",
"'classes'",
"]",
",",
"$",
"field",
"[",
"'class'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"chain",
"=",
"array_reverse",
"(",
"$",
"field",
"[",
"'lookup_chain'",
"]",
")",
";",
"array_shift",
"(",
"$",
"chain",
")",
";",
"$",
"this",
"->",
"derivedFields",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"'base'",
"=>",
"$",
"field",
"[",
"'base'",
"]",
",",
"'fields'",
"=>",
"array",
"(",
"$",
"fieldname",
"=>",
"$",
"fieldname",
")",
",",
"'classes'",
"=>",
"array",
"(",
"$",
"field",
"[",
"'class'",
"]",
")",
",",
"'chain'",
"=>",
"$",
"chain",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"derivedFields",
";",
"}"
] | Returns an array where each member is all the fields and the classes that are at the end of some
specific lookup chain from one of the base classes | [
"Returns",
"an",
"array",
"where",
"each",
"member",
"is",
"all",
"the",
"fields",
"and",
"the",
"classes",
"that",
"are",
"at",
"the",
"end",
"of",
"some",
"specific",
"lookup",
"chain",
"from",
"one",
"of",
"the",
"base",
"classes"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L431-L462 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.getDocumentIDForState | public function getDocumentIDForState($base, $id, $state)
{
ksort($state);
$parts = array('id' => $id, 'base' => $base, 'state' => json_encode($state));
return implode('-', array_values($parts));
} | php | public function getDocumentIDForState($base, $id, $state)
{
ksort($state);
$parts = array('id' => $id, 'base' => $base, 'state' => json_encode($state));
return implode('-', array_values($parts));
} | [
"public",
"function",
"getDocumentIDForState",
"(",
"$",
"base",
",",
"$",
"id",
",",
"$",
"state",
")",
"{",
"ksort",
"(",
"$",
"state",
")",
";",
"$",
"parts",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'base'",
"=>",
"$",
"base",
",",
"'state'",
"=>",
"json_encode",
"(",
"$",
"state",
")",
")",
";",
"return",
"implode",
"(",
"'-'",
",",
"array_values",
"(",
"$",
"parts",
")",
")",
";",
"}"
] | Get the "document ID" (a database & variant unique id) given some "Base" class, DataObject ID and state array
@param string $base - The base class of the object
@param integer $id - The ID of the object
@param array $state - The variant state of the object
@return string - The document ID as a string | [
"Get",
"the",
"document",
"ID",
"(",
"a",
"database",
"&",
"variant",
"unique",
"id",
")",
"given",
"some",
"Base",
"class",
"DataObject",
"ID",
"and",
"state",
"array"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L472-L477 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.getDocumentID | public function getDocumentID($object, $base, $includesubs)
{
return $this->getDocumentIDForState($base, $object->ID, SearchVariant::current_state($base, $includesubs));
} | php | public function getDocumentID($object, $base, $includesubs)
{
return $this->getDocumentIDForState($base, $object->ID, SearchVariant::current_state($base, $includesubs));
} | [
"public",
"function",
"getDocumentID",
"(",
"$",
"object",
",",
"$",
"base",
",",
"$",
"includesubs",
")",
"{",
"return",
"$",
"this",
"->",
"getDocumentIDForState",
"(",
"$",
"base",
",",
"$",
"object",
"->",
"ID",
",",
"SearchVariant",
"::",
"current_state",
"(",
"$",
"base",
",",
"$",
"includesubs",
")",
")",
";",
"}"
] | Get the "document ID" (a database & variant unique id) given some "Base" class and DataObject
@param DataObject $object - The object
@param string $base - The base class of the object
@param boolean $includesubs - TODO: Probably going away
@return string - The document ID as a string | [
"Get",
"the",
"document",
"ID",
"(",
"a",
"database",
"&",
"variant",
"unique",
"id",
")",
"given",
"some",
"Base",
"class",
"and",
"DataObject"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L487-L490 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex._getFieldValue | protected function _getFieldValue($object, $field)
{
$errorHandler = function ($no, $str) {
throw new Exception('HTML Parse Error: ' . $str);
};
set_error_handler($errorHandler, E_ALL);
try {
foreach ($field['lookup_chain'] as $step) {
// Just fail if we've fallen off the end of the chain
if (!$object) {
return null;
}
// If we're looking up this step on an array or SS_List, do the step on every item, merge result
if (is_array($object) || $object instanceof SS_List) {
$next = array();
foreach ($object as $item) {
if ($step['call'] == 'method') {
$method = $step['method'];
$item = $item->$method();
} else {
$property = $step['property'];
$item = $item->$property;
}
if ($item instanceof SS_List) {
$next = array_merge($next, $item->toArray());
} elseif (is_array($item)) {
$next = array_merge($next, $item);
} else {
$next[] = $item;
}
}
$object = $next;
} else {
// Otherwise, just call
if ($step['call'] == 'method') {
$method = $step['method'];
$object = $object->$method();
} elseif ($step['call'] == 'variant') {
$variants = SearchVariant::variants();
$variant = $variants[$step['variant']];
$method = $step['method'];
$object = $variant->$method($object);
} else {
$property = $step['property'];
$object = $object->$property;
}
}
}
} catch (Exception $e) {
static::warn($e);
$object = null;
}
restore_error_handler();
return $object;
} | php | protected function _getFieldValue($object, $field)
{
$errorHandler = function ($no, $str) {
throw new Exception('HTML Parse Error: ' . $str);
};
set_error_handler($errorHandler, E_ALL);
try {
foreach ($field['lookup_chain'] as $step) {
// Just fail if we've fallen off the end of the chain
if (!$object) {
return null;
}
// If we're looking up this step on an array or SS_List, do the step on every item, merge result
if (is_array($object) || $object instanceof SS_List) {
$next = array();
foreach ($object as $item) {
if ($step['call'] == 'method') {
$method = $step['method'];
$item = $item->$method();
} else {
$property = $step['property'];
$item = $item->$property;
}
if ($item instanceof SS_List) {
$next = array_merge($next, $item->toArray());
} elseif (is_array($item)) {
$next = array_merge($next, $item);
} else {
$next[] = $item;
}
}
$object = $next;
} else {
// Otherwise, just call
if ($step['call'] == 'method') {
$method = $step['method'];
$object = $object->$method();
} elseif ($step['call'] == 'variant') {
$variants = SearchVariant::variants();
$variant = $variants[$step['variant']];
$method = $step['method'];
$object = $variant->$method($object);
} else {
$property = $step['property'];
$object = $object->$property;
}
}
}
} catch (Exception $e) {
static::warn($e);
$object = null;
}
restore_error_handler();
return $object;
} | [
"protected",
"function",
"_getFieldValue",
"(",
"$",
"object",
",",
"$",
"field",
")",
"{",
"$",
"errorHandler",
"=",
"function",
"(",
"$",
"no",
",",
"$",
"str",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'HTML Parse Error: '",
".",
"$",
"str",
")",
";",
"}",
";",
"set_error_handler",
"(",
"$",
"errorHandler",
",",
"E_ALL",
")",
";",
"try",
"{",
"foreach",
"(",
"$",
"field",
"[",
"'lookup_chain'",
"]",
"as",
"$",
"step",
")",
"{",
"// Just fail if we've fallen off the end of the chain",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"return",
"null",
";",
"}",
"// If we're looking up this step on an array or SS_List, do the step on every item, merge result",
"if",
"(",
"is_array",
"(",
"$",
"object",
")",
"||",
"$",
"object",
"instanceof",
"SS_List",
")",
"{",
"$",
"next",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"object",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"step",
"[",
"'call'",
"]",
"==",
"'method'",
")",
"{",
"$",
"method",
"=",
"$",
"step",
"[",
"'method'",
"]",
";",
"$",
"item",
"=",
"$",
"item",
"->",
"$",
"method",
"(",
")",
";",
"}",
"else",
"{",
"$",
"property",
"=",
"$",
"step",
"[",
"'property'",
"]",
";",
"$",
"item",
"=",
"$",
"item",
"->",
"$",
"property",
";",
"}",
"if",
"(",
"$",
"item",
"instanceof",
"SS_List",
")",
"{",
"$",
"next",
"=",
"array_merge",
"(",
"$",
"next",
",",
"$",
"item",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"$",
"next",
"=",
"array_merge",
"(",
"$",
"next",
",",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"next",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"$",
"object",
"=",
"$",
"next",
";",
"}",
"else",
"{",
"// Otherwise, just call",
"if",
"(",
"$",
"step",
"[",
"'call'",
"]",
"==",
"'method'",
")",
"{",
"$",
"method",
"=",
"$",
"step",
"[",
"'method'",
"]",
";",
"$",
"object",
"=",
"$",
"object",
"->",
"$",
"method",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"step",
"[",
"'call'",
"]",
"==",
"'variant'",
")",
"{",
"$",
"variants",
"=",
"SearchVariant",
"::",
"variants",
"(",
")",
";",
"$",
"variant",
"=",
"$",
"variants",
"[",
"$",
"step",
"[",
"'variant'",
"]",
"]",
";",
"$",
"method",
"=",
"$",
"step",
"[",
"'method'",
"]",
";",
"$",
"object",
"=",
"$",
"variant",
"->",
"$",
"method",
"(",
"$",
"object",
")",
";",
"}",
"else",
"{",
"$",
"property",
"=",
"$",
"step",
"[",
"'property'",
"]",
";",
"$",
"object",
"=",
"$",
"object",
"->",
"$",
"property",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"static",
"::",
"warn",
"(",
"$",
"e",
")",
";",
"$",
"object",
"=",
"null",
";",
"}",
"restore_error_handler",
"(",
")",
";",
"return",
"$",
"object",
";",
"}"
] | Given an object and a field definition (as returned by fieldData) get the current value of that field on that object
@param DataObject $object - The object to get the value from
@param array $field - The field definition to use
@return mixed - The value of the field, or null if we couldn't look it up for some reason | [
"Given",
"an",
"object",
"and",
"a",
"field",
"definition",
"(",
"as",
"returned",
"by",
"fieldData",
")",
"get",
"the",
"current",
"value",
"of",
"that",
"field",
"on",
"that",
"object"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L499-L559 |
silverstripe/silverstripe-fulltextsearch | src/Search/Indexes/SearchIndex.php | SearchIndex.getDirtyIDs | public function getDirtyIDs($class, $id, $statefulids, $fields)
{
$dirty = array();
// First, if this object is directly contained in the index, add it
foreach ($this->classes as $searchclass => $options) {
if ($searchclass == $class || ($options['include_children'] && is_subclass_of($class, $searchclass))) {
$base = DataObject::getSchema()->baseDataClass($searchclass);
$dirty[$base] = array();
foreach ($statefulids as $statefulid) {
$key = serialize($statefulid);
$dirty[$base][$key] = $statefulid;
}
}
}
$current = SearchVariant::current_state();
// Then, for every derived field
foreach ($this->getDerivedFields() as $derivation) {
// If the this object is a subclass of any of the classes we want a field from
if (!SearchIntrospection::is_subclass_of($class, $derivation['classes'])) {
continue;
}
if (!array_intersect_key($fields, $derivation['fields'])) {
continue;
}
foreach (SearchVariant::reindex_states($class, false) as $state) {
SearchVariant::activate_state($state);
$ids = array($id);
foreach ($derivation['chain'] as $step) {
// Use TableName for queries
$tableName = DataObject::getSchema()->tableName($step['class']);
if ($step['through'] == 'has_one') {
$sql = new SQLSelect('"ID"', '"' . $tableName . '"', '"' . $step['foreignkey'] . '" IN (' . implode(',', $ids) . ')');
singleton($step['class'])->extend('augmentSQL', $sql);
$ids = $sql->execute()->column();
} elseif ($step['through'] == 'has_many') {
// Use TableName for queries
$otherTableName = DataObject::getSchema()->tableName($step['otherclass']);
$sql = new SQLSelect('"' . $tableName . '"."ID"', '"' . $tableName . '"', '"' . $otherTableName . '"."ID" IN (' . implode(',', $ids) . ')');
$sql->addInnerJoin($otherTableName, '"' . $tableName . '"."ID" = "' . $otherTableName . '"."' . $step['foreignkey'] . '"');
singleton($step['class'])->extend('augmentSQL', $sql);
$ids = $sql->execute()->column();
}
if (empty($ids)) {
break;
}
}
SearchVariant::activate_state($current);
if ($ids) {
$base = $derivation['base'];
if (!isset($dirty[$base])) {
$dirty[$base] = array();
}
foreach ($ids as $rid) {
$statefulid = array('id' => $rid, 'state' => $state);
$key = serialize($statefulid);
$dirty[$base][$key] = $statefulid;
}
}
}
}
return $dirty;
} | php | public function getDirtyIDs($class, $id, $statefulids, $fields)
{
$dirty = array();
// First, if this object is directly contained in the index, add it
foreach ($this->classes as $searchclass => $options) {
if ($searchclass == $class || ($options['include_children'] && is_subclass_of($class, $searchclass))) {
$base = DataObject::getSchema()->baseDataClass($searchclass);
$dirty[$base] = array();
foreach ($statefulids as $statefulid) {
$key = serialize($statefulid);
$dirty[$base][$key] = $statefulid;
}
}
}
$current = SearchVariant::current_state();
// Then, for every derived field
foreach ($this->getDerivedFields() as $derivation) {
// If the this object is a subclass of any of the classes we want a field from
if (!SearchIntrospection::is_subclass_of($class, $derivation['classes'])) {
continue;
}
if (!array_intersect_key($fields, $derivation['fields'])) {
continue;
}
foreach (SearchVariant::reindex_states($class, false) as $state) {
SearchVariant::activate_state($state);
$ids = array($id);
foreach ($derivation['chain'] as $step) {
// Use TableName for queries
$tableName = DataObject::getSchema()->tableName($step['class']);
if ($step['through'] == 'has_one') {
$sql = new SQLSelect('"ID"', '"' . $tableName . '"', '"' . $step['foreignkey'] . '" IN (' . implode(',', $ids) . ')');
singleton($step['class'])->extend('augmentSQL', $sql);
$ids = $sql->execute()->column();
} elseif ($step['through'] == 'has_many') {
// Use TableName for queries
$otherTableName = DataObject::getSchema()->tableName($step['otherclass']);
$sql = new SQLSelect('"' . $tableName . '"."ID"', '"' . $tableName . '"', '"' . $otherTableName . '"."ID" IN (' . implode(',', $ids) . ')');
$sql->addInnerJoin($otherTableName, '"' . $tableName . '"."ID" = "' . $otherTableName . '"."' . $step['foreignkey'] . '"');
singleton($step['class'])->extend('augmentSQL', $sql);
$ids = $sql->execute()->column();
}
if (empty($ids)) {
break;
}
}
SearchVariant::activate_state($current);
if ($ids) {
$base = $derivation['base'];
if (!isset($dirty[$base])) {
$dirty[$base] = array();
}
foreach ($ids as $rid) {
$statefulid = array('id' => $rid, 'state' => $state);
$key = serialize($statefulid);
$dirty[$base][$key] = $statefulid;
}
}
}
}
return $dirty;
} | [
"public",
"function",
"getDirtyIDs",
"(",
"$",
"class",
",",
"$",
"id",
",",
"$",
"statefulids",
",",
"$",
"fields",
")",
"{",
"$",
"dirty",
"=",
"array",
"(",
")",
";",
"// First, if this object is directly contained in the index, add it",
"foreach",
"(",
"$",
"this",
"->",
"classes",
"as",
"$",
"searchclass",
"=>",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"searchclass",
"==",
"$",
"class",
"||",
"(",
"$",
"options",
"[",
"'include_children'",
"]",
"&&",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"searchclass",
")",
")",
")",
"{",
"$",
"base",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"baseDataClass",
"(",
"$",
"searchclass",
")",
";",
"$",
"dirty",
"[",
"$",
"base",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"statefulids",
"as",
"$",
"statefulid",
")",
"{",
"$",
"key",
"=",
"serialize",
"(",
"$",
"statefulid",
")",
";",
"$",
"dirty",
"[",
"$",
"base",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"statefulid",
";",
"}",
"}",
"}",
"$",
"current",
"=",
"SearchVariant",
"::",
"current_state",
"(",
")",
";",
"// Then, for every derived field",
"foreach",
"(",
"$",
"this",
"->",
"getDerivedFields",
"(",
")",
"as",
"$",
"derivation",
")",
"{",
"// If the this object is a subclass of any of the classes we want a field from",
"if",
"(",
"!",
"SearchIntrospection",
"::",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"derivation",
"[",
"'classes'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"array_intersect_key",
"(",
"$",
"fields",
",",
"$",
"derivation",
"[",
"'fields'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"SearchVariant",
"::",
"reindex_states",
"(",
"$",
"class",
",",
"false",
")",
"as",
"$",
"state",
")",
"{",
"SearchVariant",
"::",
"activate_state",
"(",
"$",
"state",
")",
";",
"$",
"ids",
"=",
"array",
"(",
"$",
"id",
")",
";",
"foreach",
"(",
"$",
"derivation",
"[",
"'chain'",
"]",
"as",
"$",
"step",
")",
"{",
"// Use TableName for queries",
"$",
"tableName",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableName",
"(",
"$",
"step",
"[",
"'class'",
"]",
")",
";",
"if",
"(",
"$",
"step",
"[",
"'through'",
"]",
"==",
"'has_one'",
")",
"{",
"$",
"sql",
"=",
"new",
"SQLSelect",
"(",
"'\"ID\"'",
",",
"'\"'",
".",
"$",
"tableName",
".",
"'\"'",
",",
"'\"'",
".",
"$",
"step",
"[",
"'foreignkey'",
"]",
".",
"'\" IN ('",
".",
"implode",
"(",
"','",
",",
"$",
"ids",
")",
".",
"')'",
")",
";",
"singleton",
"(",
"$",
"step",
"[",
"'class'",
"]",
")",
"->",
"extend",
"(",
"'augmentSQL'",
",",
"$",
"sql",
")",
";",
"$",
"ids",
"=",
"$",
"sql",
"->",
"execute",
"(",
")",
"->",
"column",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"step",
"[",
"'through'",
"]",
"==",
"'has_many'",
")",
"{",
"// Use TableName for queries",
"$",
"otherTableName",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableName",
"(",
"$",
"step",
"[",
"'otherclass'",
"]",
")",
";",
"$",
"sql",
"=",
"new",
"SQLSelect",
"(",
"'\"'",
".",
"$",
"tableName",
".",
"'\".\"ID\"'",
",",
"'\"'",
".",
"$",
"tableName",
".",
"'\"'",
",",
"'\"'",
".",
"$",
"otherTableName",
".",
"'\".\"ID\" IN ('",
".",
"implode",
"(",
"','",
",",
"$",
"ids",
")",
".",
"')'",
")",
";",
"$",
"sql",
"->",
"addInnerJoin",
"(",
"$",
"otherTableName",
",",
"'\"'",
".",
"$",
"tableName",
".",
"'\".\"ID\" = \"'",
".",
"$",
"otherTableName",
".",
"'\".\"'",
".",
"$",
"step",
"[",
"'foreignkey'",
"]",
".",
"'\"'",
")",
";",
"singleton",
"(",
"$",
"step",
"[",
"'class'",
"]",
")",
"->",
"extend",
"(",
"'augmentSQL'",
",",
"$",
"sql",
")",
";",
"$",
"ids",
"=",
"$",
"sql",
"->",
"execute",
"(",
")",
"->",
"column",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"break",
";",
"}",
"}",
"SearchVariant",
"::",
"activate_state",
"(",
"$",
"current",
")",
";",
"if",
"(",
"$",
"ids",
")",
"{",
"$",
"base",
"=",
"$",
"derivation",
"[",
"'base'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"dirty",
"[",
"$",
"base",
"]",
")",
")",
"{",
"$",
"dirty",
"[",
"$",
"base",
"]",
"=",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"rid",
")",
"{",
"$",
"statefulid",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"rid",
",",
"'state'",
"=>",
"$",
"state",
")",
";",
"$",
"key",
"=",
"serialize",
"(",
"$",
"statefulid",
")",
";",
"$",
"dirty",
"[",
"$",
"base",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"statefulid",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"dirty",
";",
"}"
] | Given a class, object id, set of stateful ids and a list of changed fields (in a special format),
return what statefulids need updating in this index
Internal function used by SearchUpdater.
@param string $class
@param int $id
@param array $statefulids
@param array $fields
@return array | [
"Given",
"a",
"class",
"object",
"id",
"set",
"of",
"stateful",
"ids",
"and",
"a",
"list",
"of",
"changed",
"fields",
"(",
"in",
"a",
"special",
"format",
")",
"return",
"what",
"statefulids",
"need",
"updating",
"in",
"this",
"index"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Indexes/SearchIndex.php#L583-L660 |
silverstripe/silverstripe-fulltextsearch | src/Search/Updaters/SearchUpdater.php | SearchUpdater.handle_manipulation | public static function handle_manipulation($manipulation)
{
if (!static::config()->get('enabled')) {
return;
}
// First, extract any state that is in the manipulation itself
foreach ($manipulation as $table => $details) {
if (!isset($manipulation[$table]['class'])) {
$manipulation[$table]['class'] = DataObject::getSchema()->tableClass($table);
}
$manipulation[$table]['state'] = array();
}
SearchVariant::call('extractManipulationState', $manipulation);
// Then combine the manipulation back into object field sets
$writes = array();
foreach ($manipulation as $table => $details) {
if (!isset($details['id'])) {
continue;
}
$id = $details['id'];
$state = $details['state'];
$class = $details['class'];
$command = $details['command'];
$fields = isset($details['fields']) ? $details['fields'] : array();
$base = DataObject::getSchema()->baseDataClass($class);
$key = "$id:$base:" . serialize($state);
$statefulids = array(array('id' => $id, 'state' => $state));
// Is this the first table for this particular object? Then add an item to $writes
if (!isset($writes[$key])) {
$writes[$key] = array(
'base' => $base,
'class' => $class,
'id' => $id,
'statefulids' => $statefulids,
'command' => $command,
'fields' => array()
);
} elseif (is_subclass_of($class, $writes[$key]['class'])) {
// Otherwise update the class label if it's more specific than the currently recorded one
$writes[$key]['class'] = $class;
}
// Update the fields
foreach ($fields as $field => $value) {
$writes[$key]['fields']["$class:$field"] = $value;
}
}
// Trim non-delete records without fields
foreach (array_keys($writes) as $key) {
if ($writes[$key]['command'] !== 'delete' && empty($writes[$key]['fields'])) {
unset($writes[$key]);
}
}
// Then extract any state that is needed for the writes
SearchVariant::call('extractManipulationWriteState', $writes);
// Submit all of these writes to the search processor
static::process_writes($writes);
} | php | public static function handle_manipulation($manipulation)
{
if (!static::config()->get('enabled')) {
return;
}
// First, extract any state that is in the manipulation itself
foreach ($manipulation as $table => $details) {
if (!isset($manipulation[$table]['class'])) {
$manipulation[$table]['class'] = DataObject::getSchema()->tableClass($table);
}
$manipulation[$table]['state'] = array();
}
SearchVariant::call('extractManipulationState', $manipulation);
// Then combine the manipulation back into object field sets
$writes = array();
foreach ($manipulation as $table => $details) {
if (!isset($details['id'])) {
continue;
}
$id = $details['id'];
$state = $details['state'];
$class = $details['class'];
$command = $details['command'];
$fields = isset($details['fields']) ? $details['fields'] : array();
$base = DataObject::getSchema()->baseDataClass($class);
$key = "$id:$base:" . serialize($state);
$statefulids = array(array('id' => $id, 'state' => $state));
// Is this the first table for this particular object? Then add an item to $writes
if (!isset($writes[$key])) {
$writes[$key] = array(
'base' => $base,
'class' => $class,
'id' => $id,
'statefulids' => $statefulids,
'command' => $command,
'fields' => array()
);
} elseif (is_subclass_of($class, $writes[$key]['class'])) {
// Otherwise update the class label if it's more specific than the currently recorded one
$writes[$key]['class'] = $class;
}
// Update the fields
foreach ($fields as $field => $value) {
$writes[$key]['fields']["$class:$field"] = $value;
}
}
// Trim non-delete records without fields
foreach (array_keys($writes) as $key) {
if ($writes[$key]['command'] !== 'delete' && empty($writes[$key]['fields'])) {
unset($writes[$key]);
}
}
// Then extract any state that is needed for the writes
SearchVariant::call('extractManipulationWriteState', $writes);
// Submit all of these writes to the search processor
static::process_writes($writes);
} | [
"public",
"static",
"function",
"handle_manipulation",
"(",
"$",
"manipulation",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'enabled'",
")",
")",
"{",
"return",
";",
"}",
"// First, extract any state that is in the manipulation itself",
"foreach",
"(",
"$",
"manipulation",
"as",
"$",
"table",
"=>",
"$",
"details",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"manipulation",
"[",
"$",
"table",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"manipulation",
"[",
"$",
"table",
"]",
"[",
"'class'",
"]",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableClass",
"(",
"$",
"table",
")",
";",
"}",
"$",
"manipulation",
"[",
"$",
"table",
"]",
"[",
"'state'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"SearchVariant",
"::",
"call",
"(",
"'extractManipulationState'",
",",
"$",
"manipulation",
")",
";",
"// Then combine the manipulation back into object field sets",
"$",
"writes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"manipulation",
"as",
"$",
"table",
"=>",
"$",
"details",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"details",
"[",
"'id'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"id",
"=",
"$",
"details",
"[",
"'id'",
"]",
";",
"$",
"state",
"=",
"$",
"details",
"[",
"'state'",
"]",
";",
"$",
"class",
"=",
"$",
"details",
"[",
"'class'",
"]",
";",
"$",
"command",
"=",
"$",
"details",
"[",
"'command'",
"]",
";",
"$",
"fields",
"=",
"isset",
"(",
"$",
"details",
"[",
"'fields'",
"]",
")",
"?",
"$",
"details",
"[",
"'fields'",
"]",
":",
"array",
"(",
")",
";",
"$",
"base",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"baseDataClass",
"(",
"$",
"class",
")",
";",
"$",
"key",
"=",
"\"$id:$base:\"",
".",
"serialize",
"(",
"$",
"state",
")",
";",
"$",
"statefulids",
"=",
"array",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'state'",
"=>",
"$",
"state",
")",
")",
";",
"// Is this the first table for this particular object? Then add an item to $writes",
"if",
"(",
"!",
"isset",
"(",
"$",
"writes",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"writes",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"'base'",
"=>",
"$",
"base",
",",
"'class'",
"=>",
"$",
"class",
",",
"'id'",
"=>",
"$",
"id",
",",
"'statefulids'",
"=>",
"$",
"statefulids",
",",
"'command'",
"=>",
"$",
"command",
",",
"'fields'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"writes",
"[",
"$",
"key",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"// Otherwise update the class label if it's more specific than the currently recorded one",
"$",
"writes",
"[",
"$",
"key",
"]",
"[",
"'class'",
"]",
"=",
"$",
"class",
";",
"}",
"// Update the fields",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"writes",
"[",
"$",
"key",
"]",
"[",
"'fields'",
"]",
"[",
"\"$class:$field\"",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"// Trim non-delete records without fields",
"foreach",
"(",
"array_keys",
"(",
"$",
"writes",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"writes",
"[",
"$",
"key",
"]",
"[",
"'command'",
"]",
"!==",
"'delete'",
"&&",
"empty",
"(",
"$",
"writes",
"[",
"$",
"key",
"]",
"[",
"'fields'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"writes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"// Then extract any state that is needed for the writes",
"SearchVariant",
"::",
"call",
"(",
"'extractManipulationWriteState'",
",",
"$",
"writes",
")",
";",
"// Submit all of these writes to the search processor",
"static",
"::",
"process_writes",
"(",
"$",
"writes",
")",
";",
"}"
] | Called by the ProxyDBExtension database connector with every manipulation made against the database.
Check every index to see what objects need re-inserting into what indexes to keep the index fresh,
but doesn't actually do it yet.
TODO: This is pretty sensitive to the format of manipulation that DataObject::write produces. Specifically,
it expects the actual class of the object to be present as a table, regardless of if any fields changed in that table
(so a class => array( 'fields' => array() ) item), in order to find the actual class for a set of table manipulations | [
"Called",
"by",
"the",
"ProxyDBExtension",
"database",
"connector",
"with",
"every",
"manipulation",
"made",
"against",
"the",
"database",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Updaters/SearchUpdater.php#L62-L133 |
silverstripe/silverstripe-fulltextsearch | src/Search/Updaters/SearchUpdater.php | SearchUpdater.process_writes | public static function process_writes($writes)
{
foreach ($writes as $write) {
// For every index
foreach (FullTextSearch::get_indexes() as $index => $instance) {
// If that index as a field from this class
if (SearchIntrospection::is_subclass_of($write['class'], $instance->dependancyList)) {
// Get the dirty IDs
$dirtyids = $instance->getDirtyIDs($write['class'], $write['id'], $write['statefulids'], $write['fields']);
// Then add then then to the global list to deal with later
foreach ($dirtyids as $dirtyclass => $ids) {
if ($ids) {
if (!self::$processor) {
self::$processor = Injector::inst()->create(SearchUpdateImmediateProcessor::class);
}
self::$processor->addDirtyIDs($dirtyclass, $ids, $index);
}
}
}
}
}
// If we do have some work to do register the shutdown function to actually do the work
if (self::$processor && !self::$registered && self::config()->get('flush_on_shutdown')) {
register_shutdown_function(array(SearchUpdater::class, "flush_dirty_indexes"));
self::$registered = true;
}
} | php | public static function process_writes($writes)
{
foreach ($writes as $write) {
// For every index
foreach (FullTextSearch::get_indexes() as $index => $instance) {
// If that index as a field from this class
if (SearchIntrospection::is_subclass_of($write['class'], $instance->dependancyList)) {
// Get the dirty IDs
$dirtyids = $instance->getDirtyIDs($write['class'], $write['id'], $write['statefulids'], $write['fields']);
// Then add then then to the global list to deal with later
foreach ($dirtyids as $dirtyclass => $ids) {
if ($ids) {
if (!self::$processor) {
self::$processor = Injector::inst()->create(SearchUpdateImmediateProcessor::class);
}
self::$processor->addDirtyIDs($dirtyclass, $ids, $index);
}
}
}
}
}
// If we do have some work to do register the shutdown function to actually do the work
if (self::$processor && !self::$registered && self::config()->get('flush_on_shutdown')) {
register_shutdown_function(array(SearchUpdater::class, "flush_dirty_indexes"));
self::$registered = true;
}
} | [
"public",
"static",
"function",
"process_writes",
"(",
"$",
"writes",
")",
"{",
"foreach",
"(",
"$",
"writes",
"as",
"$",
"write",
")",
"{",
"// For every index",
"foreach",
"(",
"FullTextSearch",
"::",
"get_indexes",
"(",
")",
"as",
"$",
"index",
"=>",
"$",
"instance",
")",
"{",
"// If that index as a field from this class",
"if",
"(",
"SearchIntrospection",
"::",
"is_subclass_of",
"(",
"$",
"write",
"[",
"'class'",
"]",
",",
"$",
"instance",
"->",
"dependancyList",
")",
")",
"{",
"// Get the dirty IDs",
"$",
"dirtyids",
"=",
"$",
"instance",
"->",
"getDirtyIDs",
"(",
"$",
"write",
"[",
"'class'",
"]",
",",
"$",
"write",
"[",
"'id'",
"]",
",",
"$",
"write",
"[",
"'statefulids'",
"]",
",",
"$",
"write",
"[",
"'fields'",
"]",
")",
";",
"// Then add then then to the global list to deal with later",
"foreach",
"(",
"$",
"dirtyids",
"as",
"$",
"dirtyclass",
"=>",
"$",
"ids",
")",
"{",
"if",
"(",
"$",
"ids",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"processor",
")",
"{",
"self",
"::",
"$",
"processor",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"SearchUpdateImmediateProcessor",
"::",
"class",
")",
";",
"}",
"self",
"::",
"$",
"processor",
"->",
"addDirtyIDs",
"(",
"$",
"dirtyclass",
",",
"$",
"ids",
",",
"$",
"index",
")",
";",
"}",
"}",
"}",
"}",
"}",
"// If we do have some work to do register the shutdown function to actually do the work",
"if",
"(",
"self",
"::",
"$",
"processor",
"&&",
"!",
"self",
"::",
"$",
"registered",
"&&",
"self",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'flush_on_shutdown'",
")",
")",
"{",
"register_shutdown_function",
"(",
"array",
"(",
"SearchUpdater",
"::",
"class",
",",
"\"flush_dirty_indexes\"",
")",
")",
";",
"self",
"::",
"$",
"registered",
"=",
"true",
";",
"}",
"}"
] | Send updates to the current search processor for execution
@param array $writes | [
"Send",
"updates",
"to",
"the",
"current",
"search",
"processor",
"for",
"execution"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Updaters/SearchUpdater.php#L140-L168 |
silverstripe/silverstripe-fulltextsearch | src/Search/SearchIntrospection.php | SearchIntrospection.is_subclass_of | public static function is_subclass_of($class, $of)
{
$ancestry = isset(self::$ancestry[$class]) ? self::$ancestry[$class] : (self::$ancestry[$class] = ClassInfo::ancestry($class));
return is_array($of) ? (bool)array_intersect($of, $ancestry) : array_key_exists($of, $ancestry);
} | php | public static function is_subclass_of($class, $of)
{
$ancestry = isset(self::$ancestry[$class]) ? self::$ancestry[$class] : (self::$ancestry[$class] = ClassInfo::ancestry($class));
return is_array($of) ? (bool)array_intersect($of, $ancestry) : array_key_exists($of, $ancestry);
} | [
"public",
"static",
"function",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"of",
")",
"{",
"$",
"ancestry",
"=",
"isset",
"(",
"self",
"::",
"$",
"ancestry",
"[",
"$",
"class",
"]",
")",
"?",
"self",
"::",
"$",
"ancestry",
"[",
"$",
"class",
"]",
":",
"(",
"self",
"::",
"$",
"ancestry",
"[",
"$",
"class",
"]",
"=",
"ClassInfo",
"::",
"ancestry",
"(",
"$",
"class",
")",
")",
";",
"return",
"is_array",
"(",
"$",
"of",
")",
"?",
"(",
"bool",
")",
"array_intersect",
"(",
"$",
"of",
",",
"$",
"ancestry",
")",
":",
"array_key_exists",
"(",
"$",
"of",
",",
"$",
"ancestry",
")",
";",
"}"
] | Check if class is subclass of (a) the class in $of, or (b) any of the classes in the array $of
@static
@param $class
@param $of
@return bool | [
"Check",
"if",
"class",
"is",
"subclass",
"of",
"(",
"a",
")",
"the",
"class",
"in",
"$of",
"or",
"(",
"b",
")",
"any",
"of",
"the",
"classes",
"in",
"the",
"array",
"$of"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/SearchIntrospection.php#L21-L25 |
silverstripe/silverstripe-fulltextsearch | src/Search/SearchIntrospection.php | SearchIntrospection.hierarchy | public static function hierarchy($class, $includeSubclasses = true, $dataOnly = false)
{
$key = "$class!" . ($includeSubclasses ? 'sc' : 'an') . '!' . ($dataOnly ? 'do' : 'al');
if (!isset(self::$hierarchy[$key])) {
$classes = array_values(ClassInfo::ancestry($class));
if ($includeSubclasses) {
$classes = array_unique(array_merge($classes, array_values(ClassInfo::subclassesFor($class))));
}
$idx = array_search(DataObject::class, $classes);
if ($idx !== false) {
array_splice($classes, 0, $idx+1);
}
if ($dataOnly) {
foreach ($classes as $i => $class) {
if (!DataObject::getSchema()->classHasTable($class)) {
unset($classes[$i]);
}
}
}
self::$hierarchy[$key] = $classes;
}
return self::$hierarchy[$key];
} | php | public static function hierarchy($class, $includeSubclasses = true, $dataOnly = false)
{
$key = "$class!" . ($includeSubclasses ? 'sc' : 'an') . '!' . ($dataOnly ? 'do' : 'al');
if (!isset(self::$hierarchy[$key])) {
$classes = array_values(ClassInfo::ancestry($class));
if ($includeSubclasses) {
$classes = array_unique(array_merge($classes, array_values(ClassInfo::subclassesFor($class))));
}
$idx = array_search(DataObject::class, $classes);
if ($idx !== false) {
array_splice($classes, 0, $idx+1);
}
if ($dataOnly) {
foreach ($classes as $i => $class) {
if (!DataObject::getSchema()->classHasTable($class)) {
unset($classes[$i]);
}
}
}
self::$hierarchy[$key] = $classes;
}
return self::$hierarchy[$key];
} | [
"public",
"static",
"function",
"hierarchy",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
"=",
"true",
",",
"$",
"dataOnly",
"=",
"false",
")",
"{",
"$",
"key",
"=",
"\"$class!\"",
".",
"(",
"$",
"includeSubclasses",
"?",
"'sc'",
":",
"'an'",
")",
".",
"'!'",
".",
"(",
"$",
"dataOnly",
"?",
"'do'",
":",
"'al'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"hierarchy",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"classes",
"=",
"array_values",
"(",
"ClassInfo",
"::",
"ancestry",
"(",
"$",
"class",
")",
")",
";",
"if",
"(",
"$",
"includeSubclasses",
")",
"{",
"$",
"classes",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"classes",
",",
"array_values",
"(",
"ClassInfo",
"::",
"subclassesFor",
"(",
"$",
"class",
")",
")",
")",
")",
";",
"}",
"$",
"idx",
"=",
"array_search",
"(",
"DataObject",
"::",
"class",
",",
"$",
"classes",
")",
";",
"if",
"(",
"$",
"idx",
"!==",
"false",
")",
"{",
"array_splice",
"(",
"$",
"classes",
",",
"0",
",",
"$",
"idx",
"+",
"1",
")",
";",
"}",
"if",
"(",
"$",
"dataOnly",
")",
"{",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"i",
"=>",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"classHasTable",
"(",
"$",
"class",
")",
")",
"{",
"unset",
"(",
"$",
"classes",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"}",
"self",
"::",
"$",
"hierarchy",
"[",
"$",
"key",
"]",
"=",
"$",
"classes",
";",
"}",
"return",
"self",
"::",
"$",
"hierarchy",
"[",
"$",
"key",
"]",
";",
"}"
] | Get all the classes involved in a DataObject hierarchy - both super and optionally subclasses
@static
@param string $class - The class to query
@param bool $includeSubclasses - True to return subclasses as well as super classes
@param bool $dataOnly - True to only return classes that have tables
@return array - Integer keys, String values as classes sorted by depth (most super first) | [
"Get",
"all",
"the",
"classes",
"involved",
"in",
"a",
"DataObject",
"hierarchy",
"-",
"both",
"super",
"and",
"optionally",
"subclasses"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/SearchIntrospection.php#L38-L65 |
silverstripe/silverstripe-fulltextsearch | src/Search/SearchIntrospection.php | SearchIntrospection.add_unique_by_ancestor | public static function add_unique_by_ancestor(&$list, $class)
{
// If class already has parent in list, just ignore
if (self::is_subclass_of($class, $list)) {
return;
}
// Strip out any subclasses of $class already in the list
$children = ClassInfo::subclassesFor($class);
$list = array_diff($list, $children);
// Then add the class in
$list[] = $class;
} | php | public static function add_unique_by_ancestor(&$list, $class)
{
// If class already has parent in list, just ignore
if (self::is_subclass_of($class, $list)) {
return;
}
// Strip out any subclasses of $class already in the list
$children = ClassInfo::subclassesFor($class);
$list = array_diff($list, $children);
// Then add the class in
$list[] = $class;
} | [
"public",
"static",
"function",
"add_unique_by_ancestor",
"(",
"&",
"$",
"list",
",",
"$",
"class",
")",
"{",
"// If class already has parent in list, just ignore",
"if",
"(",
"self",
"::",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"list",
")",
")",
"{",
"return",
";",
"}",
"// Strip out any subclasses of $class already in the list",
"$",
"children",
"=",
"ClassInfo",
"::",
"subclassesFor",
"(",
"$",
"class",
")",
";",
"$",
"list",
"=",
"array_diff",
"(",
"$",
"list",
",",
"$",
"children",
")",
";",
"// Then add the class in",
"$",
"list",
"[",
"]",
"=",
"$",
"class",
";",
"}"
] | Add classes to list, keeping only the parent when parent & child are both in list after add | [
"Add",
"classes",
"to",
"list",
"keeping",
"only",
"the",
"parent",
"when",
"parent",
"&",
"child",
"are",
"both",
"in",
"list",
"after",
"add"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/SearchIntrospection.php#L70-L83 |
silverstripe/silverstripe-fulltextsearch | src/Search/SearchIntrospection.php | SearchIntrospection.has_extension | public static function has_extension($class, $extension, $includeSubclasses = true)
{
foreach (self::hierarchy($class, $includeSubclasses) as $relatedclass) {
if ($relatedclass::has_extension($extension)) {
return true;
}
}
return false;
} | php | public static function has_extension($class, $extension, $includeSubclasses = true)
{
foreach (self::hierarchy($class, $includeSubclasses) as $relatedclass) {
if ($relatedclass::has_extension($extension)) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"has_extension",
"(",
"$",
"class",
",",
"$",
"extension",
",",
"$",
"includeSubclasses",
"=",
"true",
")",
"{",
"foreach",
"(",
"self",
"::",
"hierarchy",
"(",
"$",
"class",
",",
"$",
"includeSubclasses",
")",
"as",
"$",
"relatedclass",
")",
"{",
"if",
"(",
"$",
"relatedclass",
"::",
"has_extension",
"(",
"$",
"extension",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Does this class, it's parent (or optionally one of it's children) have the passed extension attached? | [
"Does",
"this",
"class",
"it",
"s",
"parent",
"(",
"or",
"optionally",
"one",
"of",
"it",
"s",
"children",
")",
"have",
"the",
"passed",
"extension",
"attached?"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/SearchIntrospection.php#L88-L96 |
silverstripe/silverstripe-fulltextsearch | src/Search/Criteria/SearchCriteria.php | SearchCriteria.create | public static function create(
$target,
$value = null,
$comparison = null,
AbstractSearchQueryWriter $searchQueryWriter = null
) {
return new SearchCriteria($target, $value, $comparison, $searchQueryWriter);
} | php | public static function create(
$target,
$value = null,
$comparison = null,
AbstractSearchQueryWriter $searchQueryWriter = null
) {
return new SearchCriteria($target, $value, $comparison, $searchQueryWriter);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"target",
",",
"$",
"value",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
",",
"AbstractSearchQueryWriter",
"$",
"searchQueryWriter",
"=",
"null",
")",
"{",
"return",
"new",
"SearchCriteria",
"(",
"$",
"target",
",",
"$",
"value",
",",
"$",
"comparison",
",",
"$",
"searchQueryWriter",
")",
";",
"}"
] | Static create method provided so that you can perform method chaining.
@param $target
@param null $value
@param null $comparison
@param AbstractSearchQueryWriter $searchQueryWriter
@return SearchCriteria | [
"Static",
"create",
"method",
"provided",
"so",
"that",
"you",
"can",
"perform",
"method",
"chaining",
"."
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Criteria/SearchCriteria.php#L76-L83 |
silverstripe/silverstripe-fulltextsearch | src/Solr/Tasks/Solr_BuildTask.php | Solr_BuildTask.run | public function run($request)
{
$name = get_class($this);
$verbose = $request->getVar('verbose');
// Set new logger
$logger = $this
->getLoggerFactory()
->getOutputLogger($name, $verbose);
$this->setLogger($logger);
} | php | public function run($request)
{
$name = get_class($this);
$verbose = $request->getVar('verbose');
// Set new logger
$logger = $this
->getLoggerFactory()
->getOutputLogger($name, $verbose);
$this->setLogger($logger);
} | [
"public",
"function",
"run",
"(",
"$",
"request",
")",
"{",
"$",
"name",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"verbose",
"=",
"$",
"request",
"->",
"getVar",
"(",
"'verbose'",
")",
";",
"// Set new logger",
"$",
"logger",
"=",
"$",
"this",
"->",
"getLoggerFactory",
"(",
")",
"->",
"getOutputLogger",
"(",
"$",
"name",
",",
"$",
"verbose",
")",
";",
"$",
"this",
"->",
"setLogger",
"(",
"$",
"logger",
")",
";",
"}"
] | Setup task
@param HTTPRequest $request | [
"Setup",
"task"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Solr/Tasks/Solr_BuildTask.php#L58-L68 |
silverstripe/silverstripe-fulltextsearch | src/Search/FullTextSearch.php | FullTextSearch.get_indexes | public static function get_indexes($class = null, $rebuild = false)
{
if ($rebuild) {
self::$all_indexes = null;
self::$indexes_by_subclass = array();
}
if (!$class) {
if (self::$all_indexes === null) {
// Get declared indexes, or otherwise default to all subclasses of SearchIndex
$classes = Config::inst()->get(__CLASS__, 'indexes')
?: ClassInfo::subclassesFor(SearchIndex::class);
$hidden = array();
$candidates = array();
foreach ($classes as $class) {
// Check if this index is disabled
$hides = $class::config()->hide_ancestor;
if ($hides) {
$hidden[] = $hides;
}
// Check if this index is abstract
$ref = new ReflectionClass($class);
if (!$ref->isInstantiable()) {
continue;
}
$candidates[] = $class;
}
if ($hidden) {
$candidates = array_diff($candidates, $hidden);
}
// Create all indexes
$concrete = array();
foreach ($candidates as $class) {
$concrete[$class] = singleton($class);
}
self::$all_indexes = $concrete;
}
return self::$all_indexes;
} else {
if (!isset(self::$indexes_by_subclass[$class])) {
$all = self::get_indexes();
$valid = array();
foreach ($all as $indexclass => $instance) {
if (is_subclass_of($indexclass, $class)) {
$valid[$indexclass] = $instance;
}
}
self::$indexes_by_subclass[$class] = $valid;
}
return self::$indexes_by_subclass[$class];
}
} | php | public static function get_indexes($class = null, $rebuild = false)
{
if ($rebuild) {
self::$all_indexes = null;
self::$indexes_by_subclass = array();
}
if (!$class) {
if (self::$all_indexes === null) {
// Get declared indexes, or otherwise default to all subclasses of SearchIndex
$classes = Config::inst()->get(__CLASS__, 'indexes')
?: ClassInfo::subclassesFor(SearchIndex::class);
$hidden = array();
$candidates = array();
foreach ($classes as $class) {
// Check if this index is disabled
$hides = $class::config()->hide_ancestor;
if ($hides) {
$hidden[] = $hides;
}
// Check if this index is abstract
$ref = new ReflectionClass($class);
if (!$ref->isInstantiable()) {
continue;
}
$candidates[] = $class;
}
if ($hidden) {
$candidates = array_diff($candidates, $hidden);
}
// Create all indexes
$concrete = array();
foreach ($candidates as $class) {
$concrete[$class] = singleton($class);
}
self::$all_indexes = $concrete;
}
return self::$all_indexes;
} else {
if (!isset(self::$indexes_by_subclass[$class])) {
$all = self::get_indexes();
$valid = array();
foreach ($all as $indexclass => $instance) {
if (is_subclass_of($indexclass, $class)) {
$valid[$indexclass] = $instance;
}
}
self::$indexes_by_subclass[$class] = $valid;
}
return self::$indexes_by_subclass[$class];
}
} | [
"public",
"static",
"function",
"get_indexes",
"(",
"$",
"class",
"=",
"null",
",",
"$",
"rebuild",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"rebuild",
")",
"{",
"self",
"::",
"$",
"all_indexes",
"=",
"null",
";",
"self",
"::",
"$",
"indexes_by_subclass",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"all_indexes",
"===",
"null",
")",
"{",
"// Get declared indexes, or otherwise default to all subclasses of SearchIndex",
"$",
"classes",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"__CLASS__",
",",
"'indexes'",
")",
"?",
":",
"ClassInfo",
"::",
"subclassesFor",
"(",
"SearchIndex",
"::",
"class",
")",
";",
"$",
"hidden",
"=",
"array",
"(",
")",
";",
"$",
"candidates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"// Check if this index is disabled",
"$",
"hides",
"=",
"$",
"class",
"::",
"config",
"(",
")",
"->",
"hide_ancestor",
";",
"if",
"(",
"$",
"hides",
")",
"{",
"$",
"hidden",
"[",
"]",
"=",
"$",
"hides",
";",
"}",
"// Check if this index is abstract",
"$",
"ref",
"=",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"$",
"ref",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"candidates",
"[",
"]",
"=",
"$",
"class",
";",
"}",
"if",
"(",
"$",
"hidden",
")",
"{",
"$",
"candidates",
"=",
"array_diff",
"(",
"$",
"candidates",
",",
"$",
"hidden",
")",
";",
"}",
"// Create all indexes",
"$",
"concrete",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"candidates",
"as",
"$",
"class",
")",
"{",
"$",
"concrete",
"[",
"$",
"class",
"]",
"=",
"singleton",
"(",
"$",
"class",
")",
";",
"}",
"self",
"::",
"$",
"all_indexes",
"=",
"$",
"concrete",
";",
"}",
"return",
"self",
"::",
"$",
"all_indexes",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"indexes_by_subclass",
"[",
"$",
"class",
"]",
")",
")",
"{",
"$",
"all",
"=",
"self",
"::",
"get_indexes",
"(",
")",
";",
"$",
"valid",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"all",
"as",
"$",
"indexclass",
"=>",
"$",
"instance",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"indexclass",
",",
"$",
"class",
")",
")",
"{",
"$",
"valid",
"[",
"$",
"indexclass",
"]",
"=",
"$",
"instance",
";",
"}",
"}",
"self",
"::",
"$",
"indexes_by_subclass",
"[",
"$",
"class",
"]",
"=",
"$",
"valid",
";",
"}",
"return",
"self",
"::",
"$",
"indexes_by_subclass",
"[",
"$",
"class",
"]",
";",
"}",
"}"
] | Get all the instantiable search indexes (so all the user created indexes, but not the connector or library level
abstract indexes). Can optionally be filtered to only return indexes that are subclasses of some class
@static
@param string $class - Class name to filter indexes by, so that all returned indexes are subclasses of provided
class
@param bool $rebuild - If true, don't use cached values | [
"Get",
"all",
"the",
"instantiable",
"search",
"indexes",
"(",
"so",
"all",
"the",
"user",
"created",
"indexes",
"but",
"not",
"the",
"connector",
"or",
"library",
"level",
"abstract",
"indexes",
")",
".",
"Can",
"optionally",
"be",
"filtered",
"to",
"only",
"return",
"indexes",
"that",
"are",
"subclasses",
"of",
"some",
"class"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/FullTextSearch.php#L38-L99 |
silverstripe/silverstripe-fulltextsearch | src/Search/FullTextSearch.php | FullTextSearch.force_index_list | public static function force_index_list()
{
$indexes = func_get_args();
// No arguments = back to automatic
if (!$indexes) {
self::get_indexes(null, true);
return;
}
// Arguments can be a single array
if (is_array($indexes[0])) {
$indexes = $indexes[0];
}
// Reset to empty first
self::$all_indexes = array();
self::$indexes_by_subclass = array();
// And parse out alternative type combos for arguments and add to allIndexes
foreach ($indexes as $class => $index) {
if (is_string($index)) {
$class = $index;
$index = singleton($class);
}
if (is_numeric($class)) {
$class = get_class($index);
}
self::$all_indexes[$class] = $index;
}
} | php | public static function force_index_list()
{
$indexes = func_get_args();
// No arguments = back to automatic
if (!$indexes) {
self::get_indexes(null, true);
return;
}
// Arguments can be a single array
if (is_array($indexes[0])) {
$indexes = $indexes[0];
}
// Reset to empty first
self::$all_indexes = array();
self::$indexes_by_subclass = array();
// And parse out alternative type combos for arguments and add to allIndexes
foreach ($indexes as $class => $index) {
if (is_string($index)) {
$class = $index;
$index = singleton($class);
}
if (is_numeric($class)) {
$class = get_class($index);
}
self::$all_indexes[$class] = $index;
}
} | [
"public",
"static",
"function",
"force_index_list",
"(",
")",
"{",
"$",
"indexes",
"=",
"func_get_args",
"(",
")",
";",
"// No arguments = back to automatic",
"if",
"(",
"!",
"$",
"indexes",
")",
"{",
"self",
"::",
"get_indexes",
"(",
"null",
",",
"true",
")",
";",
"return",
";",
"}",
"// Arguments can be a single array",
"if",
"(",
"is_array",
"(",
"$",
"indexes",
"[",
"0",
"]",
")",
")",
"{",
"$",
"indexes",
"=",
"$",
"indexes",
"[",
"0",
"]",
";",
"}",
"// Reset to empty first",
"self",
"::",
"$",
"all_indexes",
"=",
"array",
"(",
")",
";",
"self",
"::",
"$",
"indexes_by_subclass",
"=",
"array",
"(",
")",
";",
"// And parse out alternative type combos for arguments and add to allIndexes",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"class",
"=>",
"$",
"index",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"index",
")",
")",
"{",
"$",
"class",
"=",
"$",
"index",
";",
"$",
"index",
"=",
"singleton",
"(",
"$",
"class",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"index",
")",
";",
"}",
"self",
"::",
"$",
"all_indexes",
"[",
"$",
"class",
"]",
"=",
"$",
"index",
";",
"}",
"}"
] | Sometimes, like when in tests, you want to restrain the actual indexes to a subset
Call with one argument - an array of class names, index instances or classname => indexinstance pairs (can be
mixed).
Alternatively call with multiple arguments, each of which is a class name or index instance
From then on, fulltext search system will only see those indexes passed in this most recent call.
Passing in no arguments resets back to automatic index list
Alternatively you can use `FullTextSearch.indexes` to configure a list of indexes via config. | [
"Sometimes",
"like",
"when",
"in",
"tests",
"you",
"want",
"to",
"restrain",
"the",
"actual",
"indexes",
"to",
"a",
"subset"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/FullTextSearch.php#L114-L145 |
silverstripe/silverstripe-fulltextsearch | src/Utils/Logging/MonologFactory.php | MonologFactory.getStreamHandler | protected function getStreamHandler(FormatterInterface $formatter, $stream, $level = Logger::DEBUG, $bubble = true)
{
// Unless cli, force output to php://output
$stream = Director::is_cli() ? $stream : 'php://output';
$handler = Injector::inst()->createWithArgs(
StreamHandler::class,
array($stream, $level, $bubble)
);
$handler->setFormatter($formatter);
return $handler;
} | php | protected function getStreamHandler(FormatterInterface $formatter, $stream, $level = Logger::DEBUG, $bubble = true)
{
// Unless cli, force output to php://output
$stream = Director::is_cli() ? $stream : 'php://output';
$handler = Injector::inst()->createWithArgs(
StreamHandler::class,
array($stream, $level, $bubble)
);
$handler->setFormatter($formatter);
return $handler;
} | [
"protected",
"function",
"getStreamHandler",
"(",
"FormatterInterface",
"$",
"formatter",
",",
"$",
"stream",
",",
"$",
"level",
"=",
"Logger",
"::",
"DEBUG",
",",
"$",
"bubble",
"=",
"true",
")",
"{",
"// Unless cli, force output to php://output",
"$",
"stream",
"=",
"Director",
"::",
"is_cli",
"(",
")",
"?",
"$",
"stream",
":",
"'php://output'",
";",
"$",
"handler",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"createWithArgs",
"(",
"StreamHandler",
"::",
"class",
",",
"array",
"(",
"$",
"stream",
",",
"$",
"level",
",",
"$",
"bubble",
")",
")",
";",
"$",
"handler",
"->",
"setFormatter",
"(",
"$",
"formatter",
")",
";",
"return",
"$",
"handler",
";",
"}"
] | Generate a handler for the given stream
@param FormatterInterface $formatter
@param string $stream Name of preferred stream
@param int $level
@param bool $bubble
@return HandlerInterface | [
"Generate",
"a",
"handler",
"for",
"the",
"given",
"stream"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Utils/Logging/MonologFactory.php#L53-L63 |
silverstripe/silverstripe-fulltextsearch | src/Utils/Logging/MonologFactory.php | MonologFactory.getFormatter | protected function getFormatter()
{
// Get formatter
$format = LineFormatter::SIMPLE_FORMAT;
if (!Director::is_cli()) {
$format = "<p>$format</p>";
}
return Injector::inst()->createWithArgs(
LineFormatter::class,
array($format)
);
} | php | protected function getFormatter()
{
// Get formatter
$format = LineFormatter::SIMPLE_FORMAT;
if (!Director::is_cli()) {
$format = "<p>$format</p>";
}
return Injector::inst()->createWithArgs(
LineFormatter::class,
array($format)
);
} | [
"protected",
"function",
"getFormatter",
"(",
")",
"{",
"// Get formatter",
"$",
"format",
"=",
"LineFormatter",
"::",
"SIMPLE_FORMAT",
";",
"if",
"(",
"!",
"Director",
"::",
"is_cli",
"(",
")",
")",
"{",
"$",
"format",
"=",
"\"<p>$format</p>\"",
";",
"}",
"return",
"Injector",
"::",
"inst",
"(",
")",
"->",
"createWithArgs",
"(",
"LineFormatter",
"::",
"class",
",",
"array",
"(",
"$",
"format",
")",
")",
";",
"}"
] | Gets a formatter for standard output
@return FormatterInterface | [
"Gets",
"a",
"formatter",
"for",
"standard",
"output"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Utils/Logging/MonologFactory.php#L70-L81 |
silverstripe/silverstripe-fulltextsearch | src/Search/Processors/SearchUpdateProcessor.php | SearchUpdateProcessor.prepareIndexes | protected function prepareIndexes()
{
$originalState = SearchVariant::current_state();
$dirtyIndexes = array();
$dirty = $this->getSource();
$indexes = FullTextSearch::get_indexes();
foreach ($dirty as $base => $statefulids) {
if (!$statefulids) {
continue;
}
foreach ($statefulids as $statefulid) {
$state = $statefulid['state'];
$ids = $statefulid['ids'];
SearchVariant::activate_state($state);
// Ensure that indexes for all new / updated objects are included
$objs = DataObject::get($base)->byIDs(array_keys($ids));
foreach ($objs as $obj) {
foreach ($ids[$obj->ID] as $index) {
if (!$indexes[$index]->variantStateExcluded($state)) {
$indexes[$index]->add($obj);
$dirtyIndexes[$index] = $indexes[$index];
}
}
unset($ids[$obj->ID]);
}
// Generate list of records that do not exist and should be removed
foreach ($ids as $id => $fromindexes) {
foreach ($fromindexes as $index) {
if (!$indexes[$index]->variantStateExcluded($state)) {
$indexes[$index]->delete($base, $id, $state);
$dirtyIndexes[$index] = $indexes[$index];
}
}
}
}
}
SearchVariant::activate_state($originalState);
return $dirtyIndexes;
} | php | protected function prepareIndexes()
{
$originalState = SearchVariant::current_state();
$dirtyIndexes = array();
$dirty = $this->getSource();
$indexes = FullTextSearch::get_indexes();
foreach ($dirty as $base => $statefulids) {
if (!$statefulids) {
continue;
}
foreach ($statefulids as $statefulid) {
$state = $statefulid['state'];
$ids = $statefulid['ids'];
SearchVariant::activate_state($state);
// Ensure that indexes for all new / updated objects are included
$objs = DataObject::get($base)->byIDs(array_keys($ids));
foreach ($objs as $obj) {
foreach ($ids[$obj->ID] as $index) {
if (!$indexes[$index]->variantStateExcluded($state)) {
$indexes[$index]->add($obj);
$dirtyIndexes[$index] = $indexes[$index];
}
}
unset($ids[$obj->ID]);
}
// Generate list of records that do not exist and should be removed
foreach ($ids as $id => $fromindexes) {
foreach ($fromindexes as $index) {
if (!$indexes[$index]->variantStateExcluded($state)) {
$indexes[$index]->delete($base, $id, $state);
$dirtyIndexes[$index] = $indexes[$index];
}
}
}
}
}
SearchVariant::activate_state($originalState);
return $dirtyIndexes;
} | [
"protected",
"function",
"prepareIndexes",
"(",
")",
"{",
"$",
"originalState",
"=",
"SearchVariant",
"::",
"current_state",
"(",
")",
";",
"$",
"dirtyIndexes",
"=",
"array",
"(",
")",
";",
"$",
"dirty",
"=",
"$",
"this",
"->",
"getSource",
"(",
")",
";",
"$",
"indexes",
"=",
"FullTextSearch",
"::",
"get_indexes",
"(",
")",
";",
"foreach",
"(",
"$",
"dirty",
"as",
"$",
"base",
"=>",
"$",
"statefulids",
")",
"{",
"if",
"(",
"!",
"$",
"statefulids",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"statefulids",
"as",
"$",
"statefulid",
")",
"{",
"$",
"state",
"=",
"$",
"statefulid",
"[",
"'state'",
"]",
";",
"$",
"ids",
"=",
"$",
"statefulid",
"[",
"'ids'",
"]",
";",
"SearchVariant",
"::",
"activate_state",
"(",
"$",
"state",
")",
";",
"// Ensure that indexes for all new / updated objects are included",
"$",
"objs",
"=",
"DataObject",
"::",
"get",
"(",
"$",
"base",
")",
"->",
"byIDs",
"(",
"array_keys",
"(",
"$",
"ids",
")",
")",
";",
"foreach",
"(",
"$",
"objs",
"as",
"$",
"obj",
")",
"{",
"foreach",
"(",
"$",
"ids",
"[",
"$",
"obj",
"->",
"ID",
"]",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"$",
"indexes",
"[",
"$",
"index",
"]",
"->",
"variantStateExcluded",
"(",
"$",
"state",
")",
")",
"{",
"$",
"indexes",
"[",
"$",
"index",
"]",
"->",
"add",
"(",
"$",
"obj",
")",
";",
"$",
"dirtyIndexes",
"[",
"$",
"index",
"]",
"=",
"$",
"indexes",
"[",
"$",
"index",
"]",
";",
"}",
"}",
"unset",
"(",
"$",
"ids",
"[",
"$",
"obj",
"->",
"ID",
"]",
")",
";",
"}",
"// Generate list of records that do not exist and should be removed",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
"=>",
"$",
"fromindexes",
")",
"{",
"foreach",
"(",
"$",
"fromindexes",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"$",
"indexes",
"[",
"$",
"index",
"]",
"->",
"variantStateExcluded",
"(",
"$",
"state",
")",
")",
"{",
"$",
"indexes",
"[",
"$",
"index",
"]",
"->",
"delete",
"(",
"$",
"base",
",",
"$",
"id",
",",
"$",
"state",
")",
";",
"$",
"dirtyIndexes",
"[",
"$",
"index",
"]",
"=",
"$",
"indexes",
"[",
"$",
"index",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"SearchVariant",
"::",
"activate_state",
"(",
"$",
"originalState",
")",
";",
"return",
"$",
"dirtyIndexes",
";",
"}"
] | Generates the list of indexes to process for the dirty items
@return array | [
"Generates",
"the",
"list",
"of",
"indexes",
"to",
"process",
"for",
"the",
"dirty",
"items"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Processors/SearchUpdateProcessor.php#L68-L111 |
silverstripe/silverstripe-fulltextsearch | src/Search/Processors/SearchUpdateProcessor.php | SearchUpdateProcessor.process | public function process()
{
// Generate and commit all instances
$indexes = $this->prepareIndexes();
foreach ($indexes as $index) {
if (!$this->commitIndex($index)) {
return false;
}
}
return true;
} | php | public function process()
{
// Generate and commit all instances
$indexes = $this->prepareIndexes();
foreach ($indexes as $index) {
if (!$this->commitIndex($index)) {
return false;
}
}
return true;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"// Generate and commit all instances",
"$",
"indexes",
"=",
"$",
"this",
"->",
"prepareIndexes",
"(",
")",
";",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"commitIndex",
"(",
"$",
"index",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Process all indexes, returning true if successful
@return bool Flag indicating success | [
"Process",
"all",
"indexes",
"returning",
"true",
"if",
"successful"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Processors/SearchUpdateProcessor.php#L139-L149 |
silverstripe/silverstripe-fulltextsearch | src/Search/Processors/SearchUpdateCommitJobProcessor.php | SearchUpdateCommitJobProcessor.queue | public static function queue($dirty = true, $startAfter = null)
{
$commit = Injector::inst()->create(__CLASS__);
$id = singleton(QueuedJobService::class)->queueJob($commit, $startAfter);
if ($dirty) {
$indexes = FullTextSearch::get_indexes();
static::$dirty_indexes = array_keys($indexes);
}
return $id;
} | php | public static function queue($dirty = true, $startAfter = null)
{
$commit = Injector::inst()->create(__CLASS__);
$id = singleton(QueuedJobService::class)->queueJob($commit, $startAfter);
if ($dirty) {
$indexes = FullTextSearch::get_indexes();
static::$dirty_indexes = array_keys($indexes);
}
return $id;
} | [
"public",
"static",
"function",
"queue",
"(",
"$",
"dirty",
"=",
"true",
",",
"$",
"startAfter",
"=",
"null",
")",
"{",
"$",
"commit",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"__CLASS__",
")",
";",
"$",
"id",
"=",
"singleton",
"(",
"QueuedJobService",
"::",
"class",
")",
"->",
"queueJob",
"(",
"$",
"commit",
",",
"$",
"startAfter",
")",
";",
"if",
"(",
"$",
"dirty",
")",
"{",
"$",
"indexes",
"=",
"FullTextSearch",
"::",
"get_indexes",
"(",
")",
";",
"static",
"::",
"$",
"dirty_indexes",
"=",
"array_keys",
"(",
"$",
"indexes",
")",
";",
"}",
"return",
"$",
"id",
";",
"}"
] | This method is invoked once indexes with dirty ids have been updapted and a commit is necessary
@param boolean $dirty Marks all indexes as dirty by default. Set to false if there are known comitted and
clean indexes
@param string $startAfter Start date
@return int The ID of the next queuedjob to run. This could be a new one or an existing one. | [
"This",
"method",
"is",
"invoked",
"once",
"indexes",
"with",
"dirty",
"ids",
"have",
"been",
"updapted",
"and",
"a",
"commit",
"is",
"necessary"
] | train | https://github.com/silverstripe/silverstripe-fulltextsearch/blob/d6a119ce202f1af0112fb0ed046d578fe878aeb4/src/Search/Processors/SearchUpdateCommitJobProcessor.php#L93-L103 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.