[turba] Feature proposition : limiting the number of result shown by search.php

Andrew Morgan morgan at orst.edu
Thu May 29 13:07:49 PDT 2003



On Thu, 29 May 2003, Etienne Goyer wrote:

> Hi there,
>
> After a few months away from it, I am back at hacking Horde, IMP and
> Turba.
>
> My problem here is that the source of contact for my current project
> will be really big (~ 100K entry in LDAP), so search results could be
> _very_ big.  In my experience, performance really become a problem past
> 250 results.  What I would like to do is have a limit set in conf.php.
> When limit is reached, the driver return only limit result and notify the
> caller that result have been truncated.  search.php will then display a
> warning along the line of "Your search returned too much results to
> display.  Please be more specific in your search criteria."
>
> If such a feature have any chance of being accepted by Turba maintainer,
> I will code it and send a patch.
>
> Thanks for your feedback !
>
> --
> Etienne Goyer                    Linux Québec Technologies Inc.
> http://www.LinuxQuebec.com       etienne.goyer at linuxquebec.com

Here is a patch I wrote that adds a sizelimit parameter to Turba.  It
doesn't work quite the way you want though.  If someone enters a search
filter that is too generic, it returns the first SizeLimit results of the
search (200 is my sizelimit here).  No error message is displayed to the
user though.  It wasn't obvious to me how to do that in Turba.

Use it if you want.  If you make any changes or add any features, please
post them back here so I can use them too.  :)

	Andy
-------------- next part --------------
diff -ur turba.orig/config/sources.php.dist turba/config/sources.php.dist
--- turba.orig/config/sources.php.dist	Thu Mar 13 12:55:05 2003
+++ turba/config/sources.php.dist	Thu Mar 13 12:55:18 2003
@@ -209,6 +209,7 @@
         'root' => 'dc=example,dc=com',
         'bind_dn' => 'cn=admin,ou=users,dc=example,dc=com',
         'bind_password' => '********',
+        'sizelimit' => 200,
         'dn' => array('cn'),
         'objectclass' => 'person',
         'charset' => 'iso-8859-1',
diff -ur turba.orig/lib/Driver/ldap.php turba/lib/Driver/ldap.php
--- turba.orig/lib/Driver/ldap.php	Thu Mar 13 12:44:05 2003
+++ turba/lib/Driver/ldap.php	Thu Mar 13 12:54:14 2003
@@ -158,13 +158,22 @@
             $attr[] = 'sn';
         }
 
+        /*
+         * Add a sizelimit, if specified. Default is 0, which means no limit.
+         * Note: You cannot override a server-side limit with this.
+         */
+        $sizelimit = 0;
+        if (!empty($this->params['sizelimit'])) {
+            $sizelimit = $this->params['sizelimit'];
+        }
+
         /* Log the query at a DEBUG log level. */
-        Horde::logMessage(sprintf('LDAP search by %s: root = %s (%s); filter = "%s"; attributes = "%s"',
-                                  Auth::getAuth(), $this->root, $this->server, $filter, implode(', ', $attr)),
+        Horde::logMessage(sprintf('LDAP search by %s: root = %s (%s); filter = "%s"; attributes = "%s"; sizelimit = %d',
+                                  Auth::getAuth(), $this->root, $this->server, $filter, implode(', ', $attr), $sizelimit),
                           __FILE__, __LINE__, LOG_DEBUG);
 
         /* Send the query to the LDAP server and fetch the matching entries. */
-        if (!($res = @ldap_search($this->ds, $this->root, $filter, $attr))) {
+        if (!($res = @ldap_search($this->ds, $this->root, $filter, $attr, 0, $sizelimit))) {
             $this->errno = ldap_errno($this->ds);
             $this->errstr = ldap_error($this->ds);
             return PEAR::raiseError($this->errstr);


More information about the turba mailing list