mirror of
https://github.com/processwire/processwire.git
synced 2025-08-14 10:45:54 +02:00
Updates in ProcessPageSearch and InputfieldPageAutocompete for support of new find operators, though additional code may still be necessary but this is a start
This commit is contained in:
@@ -373,7 +373,6 @@ _OUT;
|
||||
public function ___getConfigInputfields() {
|
||||
$inputfields = parent::___getConfigInputfields();
|
||||
|
||||
$recommended = $this->_('Recommended');
|
||||
/** @var InputfieldRadios $field */
|
||||
$field = $this->modules->get('InputfieldRadios');
|
||||
$field->setAttribute('name', 'operator');
|
||||
@@ -381,12 +380,17 @@ _OUT;
|
||||
$field->description = $this->_("The search operator that is used in the API when performing autocomplete matches.");
|
||||
$field->notes = $this->_("If you aren't sure what you want here, leave it set at the default: *=");
|
||||
$field->required = false;
|
||||
$field->addOption('*=', '`*= ` ' . $this->_("Contains phrase or partial word (using fulltext index) - Recommended"));
|
||||
$field->addOption('%=', '`%= ` ' . $this->_("Contains phrase or partial word (using LIKE)") . " - $recommended");
|
||||
$field->addOption('~=', '`~= ` ' . $this->_("Contains all the [full] words, in any order"));
|
||||
$field->addOption('^=', '`^= ` ' . $this->_("Starts with word/phrase"));
|
||||
$field->addOption('$=', '`$= ` ' . $this->_("Ends with word/phrase"));
|
||||
$field->addOption('=', '` = ` ' . $this->_("Equals [exact]"));
|
||||
$operators = Selectors::getOperators(array(
|
||||
'compareType' => Selector::compareTypeFind,
|
||||
'getIndexType' => 'operator',
|
||||
'getValueType' => 'verbose',
|
||||
));
|
||||
foreach($operators as $operator => $info) {
|
||||
if($operator === '#=') continue;
|
||||
$opLabel = str_replace('*', '\*', $operator);
|
||||
$field->addOption($operator, "`$opLabel` **$info[label]** — $info[description]");
|
||||
}
|
||||
$field->addOption('=', "`=` **" . SelectorEqual::getLabel() . "** — " . SelectorEqual::getDescription());
|
||||
$field->attr('value', $this->operator);
|
||||
$field->collapsed = Inputfield::collapsedNo;
|
||||
$inputfields->add($field);
|
||||
|
@@ -159,21 +159,12 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
static public function getOperators() {
|
||||
$f = __FILE__;
|
||||
$anyOrder = __('(in any order)', $f);
|
||||
return array(
|
||||
'=' => __('Equals', $f),
|
||||
'!=' => __('Does not equal', $f),
|
||||
'>' => __('Greater than', $f),
|
||||
'>=' => __('Greater than or equal to', $f),
|
||||
'<' => __('Less than', $f),
|
||||
'<=' => __('Less than or equal to', $f),
|
||||
'*=' => __('Contains phrase or partial word', $f) . '*',
|
||||
'%=' => __('Contains phrase/word using LIKE', $f) . '*',
|
||||
'~=' => __('Contains all the words', $f) . ' ' . $anyOrder,
|
||||
'^=' => __('Starts with', $f) . '*',
|
||||
'$=' => __('Ends with', $f) . '*',
|
||||
);
|
||||
$operators = Selectors::getOperators(array(
|
||||
'getIndexType' => 'operator',
|
||||
'getValueType' => 'label',
|
||||
));
|
||||
unset($operators['#=']); // maybe later
|
||||
return $operators;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +236,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
$lister->initSelector = $initSelector;
|
||||
$lister->defaultSelector = $defaultSelector;
|
||||
$lister->defaultSort = 'relevance';
|
||||
$lister->limit = $this->resultLimit;
|
||||
$lister->set('limit', $this->resultLimit);
|
||||
$lister->preview = false;
|
||||
$lister->columns = $this->getDisplayFields();
|
||||
return $lister->execute();
|
||||
@@ -860,7 +851,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
// deetermine which operator (if any) is present in $q
|
||||
foreach($operators as $operator => $description) {
|
||||
if(strpos($q, $operator) === false) continue;
|
||||
if(!preg_match('/^([^=%$*<>~^:]+)' . $operator . '([^=%$*<>~^:]+)$/', $q, $matches)) continue;
|
||||
if(!preg_match('/^([^=%$*+<>~^:]+)' . $operator . '([^=%$*+<>~^:]+)$/', $q, $matches)) continue;
|
||||
if($operator === '=') $operator = '?'; // operator to be determined on factors search text
|
||||
if($operator === '==') $operator = '=';
|
||||
$type = $sanitizer->name($matches[1]);
|
||||
@@ -875,13 +866,13 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
// operator was not present, only query text was, so use default operator
|
||||
$operator = $this->operator;
|
||||
}
|
||||
$input->get->operator = $operator;
|
||||
$input->get->set('operator', $operator);
|
||||
|
||||
if(strpos($type, '.')) {
|
||||
// type with property/field
|
||||
list($type, $field) = explode('.', $type, 2);
|
||||
$field = $this->wire('sanitizer')->fieldName(trim($field));
|
||||
$input->get->field = $field;
|
||||
$input->get->set('field', $field);
|
||||
} else {
|
||||
$field = '';
|
||||
}
|
||||
@@ -889,12 +880,12 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
if($type == 'pages') {
|
||||
// okay
|
||||
} else if($type == 'trash') {
|
||||
$input->get->trash = 1;
|
||||
$input->get->set('trash', 1);
|
||||
} else if($type) {
|
||||
$template = $type ? $this->wire('templates')->get($type) : '';
|
||||
if($template) {
|
||||
// defined template
|
||||
$input->get->template = $template->name;
|
||||
$input->get->set('template', $template->name);
|
||||
} else {
|
||||
// some other non-page type
|
||||
$redirectUrl = $this->wire('page')->url . 'live/' .
|
||||
@@ -1345,12 +1336,19 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
|
||||
public function getModuleConfigInputfields(array $data) {
|
||||
|
||||
$adminLiveSearchLabel = $this->_('Admin live search');
|
||||
$inputfields = $this->wire(new InputfieldWrapper());
|
||||
$modules = $this->wire('modules');
|
||||
$textFields = array();
|
||||
$allSearchTypes = array('pages', 'trash', 'modules');
|
||||
$textOperators = array('%=', '~=', '*=', '^=', '=');
|
||||
$allOperators = self::getOperators();
|
||||
// $textOperators = array('%=', '~=', '*=', '~*=', '~~=', '~%=', '~|=', '~|*=', '^=', '=');
|
||||
$textOperators = Selectors::getOperators(array(
|
||||
'compareType' => Selector::compareTypeFind,
|
||||
'getIndexType' => 'operator',
|
||||
'getValueType' => 'label',
|
||||
));
|
||||
$textOperators['='] = SelectorEqual::getLabel();
|
||||
unset($textOperators['#=']);
|
||||
|
||||
if(!isset($data['searchTypesOrder'])) $data['searchTypesOrder'] = array();
|
||||
if(!isset($data['noSearchTypes'])) $data['noSearchTypes'] = array();
|
||||
@@ -1377,9 +1375,10 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
$allSearchTypes[$name] = $name;
|
||||
if(!in_array($name, $searchTypesOrder)) $searchTypesOrder[] = $name;
|
||||
}
|
||||
|
||||
|
||||
/** @var InputfieldFieldset $fieldset */
|
||||
$fieldset = $modules->get('InputfieldFieldset');
|
||||
$fieldset->label = $this->_('Admin live search');
|
||||
$fieldset->label = $adminLiveSearchLabel;
|
||||
$fieldset->icon = 'search';
|
||||
$inputfields->add($fieldset);
|
||||
|
||||
@@ -1413,6 +1412,13 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
$f->attr('value', $noSearchTypes);
|
||||
$fieldset->add($f);
|
||||
|
||||
/** @var InputfieldFieldset $fieldset */
|
||||
$fieldset = $modules->get('InputfieldFieldset');
|
||||
$fieldset->label = $adminLiveSearchLabel . ' ' . $this->_('(settings for pages type)');
|
||||
$fieldset->icon = 'search';
|
||||
$fieldset->themeOffset = 'm';
|
||||
$inputfields->add($fieldset);
|
||||
|
||||
$f = $modules->get('InputfieldAsmSelect');
|
||||
$f->attr('name', 'searchFields2');
|
||||
$f->label = $this->_('Page fields to search');
|
||||
@@ -1442,12 +1448,9 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
$f->attr('value', isset($data['operator']) ? $data['operator'] : self::defaultOperator);
|
||||
$f->label = $this->_('Default search operator for single and partial word searches');
|
||||
$f->columnWidth = 50;
|
||||
foreach($textOperators as $operator) {
|
||||
$label = $allOperators[$operator];
|
||||
foreach($textOperators as $operator => $label) {
|
||||
$f->addOption($operator, "$operator $label");
|
||||
}
|
||||
$partialLabel = '*' . $this->_('Indicates support of partial word matches');
|
||||
$f->notes = $partialLabel;
|
||||
$fieldset->append($f);
|
||||
|
||||
$f = $modules->get("InputfieldSelect");
|
||||
@@ -1455,11 +1458,9 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
$f->attr('value', isset($data['operator2']) ? $data['operator2'] : '~=');
|
||||
$f->label = $this->_('Default search operator for multi-word (phrase) searches');
|
||||
$f->columnWidth = 50;
|
||||
foreach($textOperators as $operator) {
|
||||
$label = $allOperators[$operator];
|
||||
foreach($textOperators as $operator => $label) {
|
||||
$f->addOption($operator, "$operator $label");
|
||||
}
|
||||
$f->notes = $partialLabel;
|
||||
$fieldset->append($f);
|
||||
|
||||
// displayField: no longer used, except if user lacks page-lister permission
|
||||
|
@@ -169,6 +169,14 @@ class ProcessPageSearchLive extends Wire {
|
||||
$this->liveSearchDefaults = array_merge($this->liveSearchDefaults, $liveSearch);
|
||||
}
|
||||
|
||||
$findOperators = Selectors::getOperators(array(
|
||||
'compareType' => Selector::compareTypeFind,
|
||||
'getIndexType' => 'none',
|
||||
'getValueType' => 'operator',
|
||||
));
|
||||
|
||||
$this->allowOperators = array_unique(array_merge($this->allowOperators, $findOperators));
|
||||
|
||||
$this->labels = array(
|
||||
'missing-query' => $this->_('No search specified'),
|
||||
'pages' => $this->_('Pages'),
|
||||
@@ -234,6 +242,8 @@ class ProcessPageSearchLive extends Wire {
|
||||
$user = $this->wire('user');
|
||||
/** @var Languages $languages */
|
||||
$languages = $this->wire('languages');
|
||||
/** @var AdminTheme|AdminThemeFramework $adminTheme */
|
||||
$adminTheme = $this->wire()->adminTheme;
|
||||
|
||||
$type = isset($presets['type']) ? $presets['type'] : '';
|
||||
$language = isset($presets['language']) ? $presets['language'] : '';
|
||||
@@ -280,10 +290,13 @@ class ProcessPageSearchLive extends Wire {
|
||||
} else if(strpos($q, '=') !== false) {
|
||||
// regular equals or other w/equals
|
||||
$replaceOperator = '=';
|
||||
if(preg_match('/([%~*^$<>!]{1,2}=)/', $q, $matches)) {
|
||||
$opChars = Selectors::getOperatorChars();
|
||||
if(preg_match('/([' . preg_quote(implode('', $opChars)) . ']{1,3}=)/', $q, $matches)) {
|
||||
if(in_array($matches[1], $this->allowOperators)) {
|
||||
$operator = $matches[1];
|
||||
$replaceOperator = $operator;
|
||||
} else {
|
||||
$q = str_replace($opChars, ' ', $q);
|
||||
}
|
||||
} else {
|
||||
// regular equals, use default operator
|
||||
@@ -362,6 +375,9 @@ class ProcessPageSearchLive extends Wire {
|
||||
$selectors[] = implode('|', $this->defaultPageSearchFields) . $operator . $value;
|
||||
}
|
||||
|
||||
$help = strtolower($q) === 'help';
|
||||
if(!$help && $adminTheme && $q === $adminTheme->getLabel('search-help')) $help = true;
|
||||
|
||||
$liveSearch = array_merge($this->liveSearchDefaults, $presets, array(
|
||||
'type' => $type,
|
||||
'property' => $property,
|
||||
@@ -373,7 +389,7 @@ class ProcessPageSearchLive extends Wire {
|
||||
'language' => $language,
|
||||
'start' => $start,
|
||||
'limit' => $limit,
|
||||
'help' => strtolower($q) === 'help',
|
||||
'help' => $help,
|
||||
));
|
||||
|
||||
if($this->isViewAll) {
|
||||
|
Reference in New Issue
Block a user