mirror of
https://github.com/getgrav/grav.git
synced 2025-11-05 04:45:53 +01:00
Flex search() optimizations
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
- `text`, `url`, `hidden`, `commalist`: 2048
|
- `text`, `url`, `hidden`, `commalist`: 2048
|
||||||
- `text` (multiline), `textarea`: 65536
|
- `text` (multiline), `textarea`: 65536
|
||||||
3. [](#bugfix)
|
3. [](#bugfix)
|
||||||
* Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218).
|
* Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218)
|
||||||
* Fix for multi-lang issues with Security Report
|
* Fix for multi-lang issues with Security Report
|
||||||
|
|
||||||
# v1.7.31
|
# v1.7.31
|
||||||
|
|||||||
@@ -147,6 +147,10 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
|
|||||||
*/
|
*/
|
||||||
public function search(string $search, $properties = null, array $options = null)
|
public function search(string $search, $properties = null, array $options = null)
|
||||||
{
|
{
|
||||||
|
$directory = $this->getFlexDirectory();
|
||||||
|
$properties = $directory->getSearchProperties($properties);
|
||||||
|
$options = $directory->getSearchOptions($options);
|
||||||
|
|
||||||
$matching = $this->call('search', [$search, $properties, $options]);
|
$matching = $this->call('search', [$search, $properties, $options]);
|
||||||
$matching = array_filter($matching);
|
$matching = array_filter($matching);
|
||||||
|
|
||||||
|
|||||||
@@ -170,6 +170,44 @@ class FlexDirectory implements FlexDirectoryInterface
|
|||||||
return null === $name ? $this->config : $this->config->get($name, $default);
|
return null === $name ? $this->config : $this->config->get($name, $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|string[]|null
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSearchProperties($properties = null): array
|
||||||
|
{
|
||||||
|
if (null !== $properties) {
|
||||||
|
return (array)$properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
$properties = $this->getConfig('data.search.fields');
|
||||||
|
if (!$properties) {
|
||||||
|
$fields = $this->getConfig('admin.views.list.fields') ?? $this->getConfig('admin.list.fields', []);
|
||||||
|
foreach ($fields as $property => $value) {
|
||||||
|
if (!empty($value['link'])) {
|
||||||
|
$properties[] = $property;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array|null $options
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSearchOptions(array $options = null): array
|
||||||
|
{
|
||||||
|
if (empty($options['merge'])) {
|
||||||
|
return $options ?? (array)$this->getConfig('data.search.options');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($options['merge']);
|
||||||
|
|
||||||
|
return $options + (array)$this->getConfig('data.search.options');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $name
|
* @param string|null $name
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
|||||||
@@ -162,6 +162,10 @@ class FlexIndex extends ObjectIndex implements FlexIndexInterface
|
|||||||
*/
|
*/
|
||||||
public function search(string $search, $properties = null, array $options = null)
|
public function search(string $search, $properties = null, array $options = null)
|
||||||
{
|
{
|
||||||
|
$directory = $this->getFlexDirectory();
|
||||||
|
$properties = $directory->getSearchProperties($properties);
|
||||||
|
$options = $directory->getSearchOptions($options);
|
||||||
|
|
||||||
return $this->__call('search', [$search, $properties, $options]);
|
return $this->__call('search', [$search, $properties, $options]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -287,17 +287,9 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
|
|||||||
*/
|
*/
|
||||||
public function search(string $search, $properties = null, array $options = null): float
|
public function search(string $search, $properties = null, array $options = null): float
|
||||||
{
|
{
|
||||||
$properties = (array)($properties ?? $this->getFlexDirectory()->getConfig('data.search.fields'));
|
$directory = $this->getFlexDirectory();
|
||||||
if (!$properties) {
|
$properties = $directory->getSearchProperties($properties);
|
||||||
$fields = $this->getFlexDirectory()->getConfig('admin.views.list.fields') ?? $this->getFlexDirectory()->getConfig('admin.list.fields', []);
|
$options = $directory->getSearchOptions($options);
|
||||||
foreach ($fields as $property => $value) {
|
|
||||||
if (!empty($value['link'])) {
|
|
||||||
$properties[] = $property;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$options = $options ?? (array)$this->getFlexDirectory()->getConfig('data.search.options');
|
|
||||||
|
|
||||||
$weight = 0;
|
$weight = 0;
|
||||||
foreach ($properties as $property) {
|
foreach ($properties as $property) {
|
||||||
|
|||||||
Reference in New Issue
Block a user