[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Object selector: allow searching for tracker items with an exact match...

"Merci Jacob \(@mercihabam\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6992e6c388aa5_3b18590c487a8@gitlab-sidekiq-low-urgency-cpu-bound-v2-7b68dd745d-7hlp8.mail>

Merci Jacob pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
53fa7359 by Merci Jacob at 2026-02-16T09:35:48+00:00
[ENH] Object selector: allow searching for tracker items with an exact match query for item ids. eg - "123" for item123
---
* fix phpcs

* allow exact match with plain item number, but in the meantime lookup into other specified search fields

* [ENH] Object selector: allow searching for tracker items with an exact match query for item ids. eg - item123

See merge request tikiwiki/tiki!9330

- - - - -


2 changed files:

- lib/jquery_tiki/tiki-jquery.js
- lib/search/searchlib-unified.php


Changes:

=====================================
lib/jquery_tiki/tiki-jquery.js
=====================================
@@ -1482,7 +1482,8 @@ $.fn.tiki = function(func) {
         return $.service(controller, action, o);
     };
 
-    $.buildParams = function (query, prefix, suffix) {
+    $.paramsToProcessLength = 0;
+    $.buildParams = function (query, prefix, suffix, _keysNamespace = []) {
         prefix = prefix || '';
         suffix = suffix || '';
 
@@ -1490,12 +1491,33 @@ $.fn.tiki = function(func) {
             return query;
         }
 
-        return $.map(query, function (v, k) {
-            if ($.isPlainObject(v)) {
-                return $.buildParams(v, k + '[', ']');
+        const params = [];
+        $.paramsToProcessLength = $.paramsToProcessLength || Object.keys(query).length;
+
+        for (const [key, value] of Object.entries(query)) {
+            if ($.isPlainObject(value)) {
+                _keysNamespace.push(key);
+                const keyNamespace = _keysNamespace.at(-2);
+                const prefixInner = (keyNamespace ? `${keyNamespace}~`: '') + key + '[';
+
+                $.paramsToProcessLength++;
+
+                params.push(...$.buildParams(value, prefixInner, ']', _keysNamespace));
+            } else if (Array.isArray(value)) {
+                value.forEach(function (av) {
+                    params.push({[`${prefix}${key}${suffix}[]`]: av});
+                });
             } else {
-                return prefix + k + suffix + '=' + encodeURIComponent(v);
+                params.push({[`${prefix}${key}${suffix}`]: value});
+                $.paramsToProcessLength--;
             }
+        }
+
+        if ($.paramsToProcessLength) return params;
+
+        return params.map(function (param) {
+            const k = Object.keys(param)[0];
+            return k + '=' + encodeURIComponent(param[k]);
         }).join('&');
     };
 
@@ -2198,10 +2220,16 @@ $.fn.tiki = function(func) {
                     $textarea.data('use-threshold', 0);
                 }
                 if ($filter.val()) {
-                    if (wildcard === 'y') {
-                        filter[searchField] = '*' + $filter.val() + '*';
+                    const objectIdExactMatch = $filter.val().match(/^(\d+)/);
+                    if (objectIdExactMatch) {
+                        filter.multi = {fields: ['object_id', searchField], value: objectIdExactMatch[1]};
                     } else {
-                        filter[searchField] = $filter.val();
+                        delete filter.multi;
+                        if (wildcard === 'y') {
+                            filter[searchField] = '*' + $filter.val() + '*';
+                        } else {
+                            filter[searchField] = $filter.val();
+                        }
                     }
                 }
                 loadSelectorData(filter, selectorArgs, function (data) {


=====================================
lib/search/searchlib-unified.php
=====================================
@@ -1370,13 +1370,7 @@ class UnifiedSearchLib
         }
 
         if (isset($filter['content']) && $filter['content']) {
-            $o = TikiLib::lib('tiki')->get_preference('unified_default_content', ['contents'], true);
-            if (count($o) == 1 && empty($o[0])) {
-                // Use "contents" field by default, if no default is specified
-                $query->filterContent($filter['content'], ['contents']);
-            } else {
-                $query->filterContent($filter['content'], $o);
-            }
+            $query->filterContent($filter['content'], $this->getFilterContentFields());
         }
 
         if (isset($filter['autocomplete']) && $filter['autocomplete']) {
@@ -1424,6 +1418,27 @@ class UnifiedSearchLib
             unset($filter['exact']);
         }
 
+        if (isset($filter['multi'])) {
+            if (
+                isset($filter['multi']['fields']) && is_array($filter['multi']['fields']) &&
+                    isset($filter['multi']['value'])
+            ) {
+                $fields = $filter['multi']['fields'];
+                $value = $filter['multi']['value'];
+
+                foreach ($fields as $k => $v) {
+                    if ($v === 'content') {
+                        unset($fields[$k]);
+                        $fields = array_merge($fields, $this->getFilterContentFields());
+                    }
+                }
+
+                $query->filterContent($value, $fields);
+            }
+
+            unset($filter['multi']);
+        }
+
         if (
             isset($filter['distance']) && is_array($filter['distance']) &&
                     isset($filter['distance']['distance'], $filter['distance']['lat'], $filter['distance']['lon'])
@@ -1465,6 +1480,16 @@ class UnifiedSearchLib
         return $query;
     }
 
+    private function getFilterContentFields()
+    {
+        $fields = TikiLib::lib('tiki')->get_preference('unified_default_content', ['contents'], true);
+        if (count($fields) == 1 && empty($fields[0])) {
+            $fields = ['contents'];
+        }
+
+        return $fields;
+    }
+
     public function getFacetProvider()
     {
         global $prefs;



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/53fa7359c1a579c69b65fba4cbd989567e17aba3

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/53fa7359c1a579c69b65fba4cbd989567e17aba3
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.