6.0.0-beta1
7/7/25

[#10681] Autocompleter in IMP with inconsistent results
Summary Autocompleter in IMP with inconsistent results
Queue Horde Base
Queue Version 4.0.10
Type Bug
State Not A Bug
Priority 1. Low
Owners
Requester michael.groene (at) zel (dot) uni-hannover (dot) de
Created 10/25/2011 (5004 days ago)
Due
Updated 11/16/2011 (4982 days ago)
Assigned
Resolved 11/16/2011 (4982 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
11/16/2011 03:23:21 AM Git Commit Comment #8 Reply to this comment
Changes have been made in Git for this ticket:

Ticket #10681: Fix hook

  1 files changed, 1 insertions(+), 1 deletions(-)
http://git.horde.org/horde-git/-/commit/bc5b08ba9bd5b3a0f85bb81687c44c14deee3e89
11/16/2011 03:12:59 AM Michael Slusarz Comment #7
State ⇒ Not A Bug
Reply to this comment
I expanded the hooks, to filter for that.

Maybe it could be added to the dist?
Modified and added to the hooks example - thanks.
11/16/2011 03:12:20 AM Git Commit Comment #6 Reply to this comment
Changes have been made in Git for this ticket:

Ticket #10681: Only return field names that are searchable

  1 files changed, 6 insertions(+), 1 deletions(-)
http://git.horde.org/horde-git/-/commit/c762653d6c9fd2206f7817d10105bebc4a10efde
11/14/2011 12:07:03 PM michael (dot) groene (at) zel (dot) uni-hannover (dot) de Comment #5 Reply to this comment
Are you sure the hook is running and returning the proper data?
Good hint, I didn't thought about, whether it's returning proper data, 
because it was provided in hooks.dist.

I found out, why I got different results.

When the search_fields-pref was set by the hook, it contained ALL 
fields, not just the fields, marked to be searched in turba's 
backends.php. This lead to too many results, which is why the results 
were not being displayed (max. 100).

I expanded the hooks, to filter for that.

Maybe it could be added to the dist?


This is my complete prefs_init-Hook:

     public function prefs_init($pref, $value, $username, $scope_ob)
     {
         switch ($pref) {
         case 'add_source':
             // Dynamically set the add_source preference.

             // Example: Useful hook when using a Turba source with shares
             // enabled (i.e. the example localsql configuration).
             $value=is_null($username)
             ? $value
             : $GLOBALS['registry']->call('contacts/getDefaultShare');

#           return $value;
         break;

         case 'search_fields':
         case 'search_sources':
             // Dynamically set the search_fields/search_sources preferences.

             // Example #1: Use the list of sources defined in the contacts
             // application (e.g. Turba).

             if (!is_null($username) &&
                 $GLOBALS['registry']->hasMethod('contacts/sources')) {
                 $sources = $GLOBALS['registry']->call('contacts/sources');
                 if ($pref == 'search_fields') {
                     $out = array();
                     foreach (array_keys($sources) as $source) {

#                        $out[$source] = 
array_keys($GLOBALS['registry']->call('contacts/fields', 
array($source)));

                         #reduce to searchable fields
                         $all_fields = 
($GLOBALS['registry']->call('contacts/fields', array($source)));
                         foreach($all_fields as $field=>$details) {
                                 if($details['search']==true)
                                         $out[$source][]=$field;

                         }

                     }
                 } else {
                     $out = array_keys($sources);
                 }

                 $value=json_encode($out);
             }
         break;
         }
         return $value;
     }


This was added to  the foreach:

                         #reduce to searchable fields
                         $all_fields = 
($GLOBALS['registry']->call('contacts/fields', array($source)));
                         foreach($all_fields as $field=>$details) {
                                 if($details['search']==true)
                                         $out[$source][]=$field;



Thanks for advice, can be closed.
11/08/2011 06:38:50 AM Michael Slusarz Comment #4 Reply to this comment
Maybe now it becomes a bit clearer? But I think I will need to 
investigate that issue more exact. Will keep on going.
Are you sure the hook is running and returning the proper data?
11/03/2011 07:30:03 PM michael (dot) groene (at) zel (dot) uni-hannover (dot) de Comment #3 Reply to this comment
I don't understand - what does prefs_init hook have to do with autocomplete?
I try to set "search_sources" to the users addressbooks with the hook 
as posted in the initial posting.
This seems to work correctly, since all available addressbooks for one 
user are listed in the dropdown "selected sources" in the prefs (see 
https://groupware.zel.uni-hannover.de/services/prefs.php?ajaxui=1&app=imp&group=addressbooks).

But for the autocompleter it makes a difference if it is set via hook, 
or I click on "save" which writes the settings in mysql-table 
horde_prefs.
After the selected sources are saved in the DB, the results of the 
autocompleter are much better than without.

Maybe now it becomes a bit clearer? But I think I will need to 
investigate that issue more exact. Will keep on going.
10/27/2011 06:03:34 AM Michael Slusarz Comment #2
Priority ⇒ 1. Low
Reply to this comment
I don't understand - what does prefs_init hook have to do with autocomplete?
10/25/2011 01:39:24 PM michael (dot) groene (at) zel (dot) uni-hannover (dot) de Comment #1
Priority ⇒ 2. Medium
Type ⇒ Bug
Summary ⇒ Autocompleter in IMP with inconsistent results
Queue ⇒ Horde Base
Milestone ⇒
Patch ⇒ No
State ⇒ Unconfirmed
Reply to this comment
I probed the autocomplete feature in IMP a longer time since now.
Before a few weeks something was corrected in the autocompleter code, 
but this is not what my problem solved, too.

The issue is, that the autocompleter will most of the time not show up 
until I wrote 4 letters, though I set ac_threshold to 1, even the 
maximum (200) can't be hit. Another time the autocompleter won't 
filter again, when typing the 3rd letter, typing the 4th will filter 
again.

This behaviour I get, when I use the hook as given in the examples:

     public function prefs_init($pref, $value, $username, $scope_ob)
     {
         switch ($pref) {
         case 'add_source':
             // Dynamically set the add_source preference.

             // Example: Useful hook when using a Turba source with shares
             // enabled (i.e. the example localsql configuration).
             return is_null($username)
                 ? $value
                 : $GLOBALS['registry']->call('contacts/getDefaultShare');


         case 'search_fields':
         case 'search_sources':
             // Dynamically set the search_fields/search_sources preferences.

             // Example #1: Use the list of sources defined in the contacts
             // application (e.g. Turba).

#Horde::debug($pref);
             if (!is_null($username) &&
                 $GLOBALS['registry']->hasMethod('contacts/sources')) {
                 $sources = $GLOBALS['registry']->call('contacts/sources');
                 if ($pref == 'search_fields') {
                     $out = array();
                     foreach (array_keys($sources) as $source) {
                         $out[$source] = 
array_keys($GLOBALS['registry']->call('contacts/fields', 
array($source)));
                     }
                 } else {
                     $out = array_keys($sources);
                 }
#               Horde::debug($out);
                 return json_encode($out);
             }

             return $value;
         }
     }


When I set this on my own in the preferences so that it will be saved 
in the pref-table, the autocompleter works correctly.


Saved Queries