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 |
Ticket #10681: Fix hook1 files changed, 1 insertions(+), 1 deletions(-)
http://git.horde.org/horde-git/-/commit/bc5b08ba9bd5b3a0f85bb81687c44c14deee3e89
State ⇒ Not A Bug
Maybe it could be added to the dist?
Ticket #10681: Only return field names that are searchable1 files changed, 6 insertions(+), 1 deletions(-)
http://git.horde.org/horde-git/-/commit/c762653d6c9fd2206f7817d10105bebc4a10efde
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.
investigate that issue more exact. Will keep on going.
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.
Priority ⇒ 1. Low
Priority ⇒ 2. Medium
Type ⇒ Bug
Summary ⇒ Autocompleter in IMP with inconsistent results
Queue ⇒ Horde Base
Milestone ⇒
Patch ⇒ No
State ⇒ Unconfirmed
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.