[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX] manticore regex and string/numeric comparisons, add unit tests
"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6969d1b0a5ff2_2c1a68c5829977@gitlab-sidekiq-low-urgency-cpu-bound-v2-56f8d96476-j6v57.mail> |
Victor Emanouilov pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki
Commits:
f1d29c9d by Victor Emanouilov at 2026-01-16T07:50:35+02:00
[FIX] manticore regex and string/numeric comparisons, add unit tests
- - - - -
2 changed files:
- lib/core/Search/Manticore/QueryBuilder.php
- lib/test/core/Search/Manticore/ComplexQueriesTest.php
Changes:
=====================================
lib/core/Search/Manticore/QueryBuilder.php
=====================================
@@ -227,7 +227,9 @@ class QueryBuilder
$field = $this->getField($node);
Index::addSearchedField($node->getField(), 'others');
$value = $this->getQuoted($node, '(?i)^');
- return "REGEX($field, $value)";
+ $key = 'tf_' . uniqid();
+ $this->select[$key] = "REGEX(TO_STRING({$field}), $value)";
+ return "$key = 1";
} elseif ($node instanceof Range) {
$field = $this->getField($node);
Index::addSearchedField($node->getField(), 'others');
@@ -278,7 +280,9 @@ class QueryBuilder
return "{$field} = $value";
} else {
$value = $this->getQuoted($node, '(?i)');
- return "REGEX({$field}, $value)";
+ $key = 'tf_' . uniqid();
+ $this->select[$key] = "REGEX(TO_STRING({$field}), $value)";
+ return "$key = 1";
}
}
Index::addSearchedField($node->getField(), 'others');
@@ -386,9 +390,9 @@ class QueryBuilder
{
$value = $node->getValue($this->factory);
$value = Index::convertJsonTypeValue($value);
- if (is_numeric($value)) {
+ if (is_numeric($value) && empty($prefix)) {
return floatval($value);
- } elseif (is_string($value)) {
+ } elseif (is_string($value) || ! empty($prefix)) {
return $this->pdo_client->quote($prefix . strval($value));
} else {
return $value;
=====================================
lib/test/core/Search/Manticore/ComplexQueriesTest.php
=====================================
@@ -78,6 +78,20 @@ class ComplexQueriesTest extends \PHPUnit\Framework\TestCase
'tracker_field_RevenueLifecycleStatus_text' => $typeFactory->plaintext(''),
]
);
+ $this->index->addDocument(
+ [
+ 'object_type' => $typeFactory->identifier('trackeritem'),
+ 'object_id' => $typeFactory->identifier('100'),
+ 'title' => $typeFactory->plaintext('test item'),
+ 'tracker_id' => $typeFactory->identifier('4'),
+ 'tracker_field_numeric' => $typeFactory->numeric(123),
+ 'tracker_field_identifier' => $typeFactory->identifier('456'),
+ 'tracker_field_multi' => $typeFactory->multivalue(['1', '2', '3']),
+ 'tracker_field_timestamp' => $typeFactory->timestamp(time()),
+ 'tracker_field_sortable' => $typeFactory->sortable('789'),
+ 'tracker_field_text' => $typeFactory->plaintext('Test sentence. Testing sentence.'),
+ ]
+ );
}
protected function tearDown(): void
@@ -174,4 +188,62 @@ class ComplexQueriesTest extends \PHPUnit\Framework\TestCase
$label = array_shift($options);
$this->assertEquals(date('Y-m-d', time() - 86400) . ' (2)', $label);
}
+
+ public function testSearchTrackerFields()
+ {
+ $initQuery = function () {
+ $query = new \Search_Query();
+ \TikiLib::lib('unifiedsearch')->initQuery($query);
+ $query->filterType('trackeritem');
+ return $query;
+ };
+
+ $query = $initQuery();
+ $query->filterIdentifier(123, 'tracker_field_numeric');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterContent(123, 'tracker_field_numeric');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterInitial(12, 'tracker_field_numeric');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterIdentifier('456', 'tracker_field_identifier');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterContent('456', 'tracker_field_identifier');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterInitial('45', 'tracker_field_identifier');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterMultivalue('2', 'tracker_field_multi');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterRange(time() - 1000, time() + 1000, 'tracker_field_timestamp');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterIdentifier('789', 'tracker_field_sortable');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterContent('789', 'tracker_field_sortable');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterInitial('78', 'tracker_field_sortable');
+ $this->assertCount(1, $query->search($this->index));
+
+ $query = $initQuery();
+ $query->filterContent('sentence', 'tracker_field_text');
+ $this->assertCount(1, $query->search($this->index));
+ }
}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/f1d29c9d37da5f7e44c970a01830d2cc08ac58d9
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/f1d29c9d37da5f7e44c970a01830d2cc08ac58d9
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs