[TikiWiki-commits] [Git][tikiwiki/tiki][master] [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 <6969d185751aa_2c511e906186e@gitlab-sidekiq-low-urgency-cpu-bound-v2-56f8d96476-7d6sl.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
96b88794 by Victor Emanouilov at 2026-01-16T07:49:46+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/96b887949dd92d1567b0a182eb0ab6aae5e5cf84

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/96b887949dd92d1567b0a182eb0ab6aae5e5cf84
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.