def search(options = {}, &block)
      logger.debug("#{inspect}.search(#{options.inspect[1..-2]})")
      ary = []
      one_attribute = options[:attributes]
      if one_attribute.respond_to?(:to_ary)
        one_attribute = nil
      end
      options = search_options(options)
      if options[:limit] == true
        options[:limit] = 1
        first = true
      end
      adapter.search(options) do |entry|
        if options[:instantiate]
          klass = const_get("Top")
          entry = klass.instantiate(entry)
        end
        if one_attribute
          entry = entry[Ldaptic.encode(one_attribute)]
          entry = entry.one if entry.respond_to?(:one)
        end
        ary << entry
        block.call(entry) if block_given?
        return entry if first == true
        return ary   if options[:limit] == ary.size
      end
      first ? ary.first : ary
    end
def search(options = {}, &block)
      logger.debug("#{inspect}.search(#{options.inspect[1..-2]})")
      ary = []
      one_attribute = options[:attributes]
      if one_attribute.respond_to?(:to_ary)
        one_attribute = nil
      end
      options = search_options(options)
      if options[:limit] == true
        options[:limit] = 1
        first = true
      end
      adapter.search(options) do |entry|
        if options[:instantiate]
          klass = const_get("Top")
          entry = klass.instantiate(entry)
        end
        if one_attribute
          entry = entry[Ldaptic.encode(one_attribute)]
          entry = entry.one if entry.respond_to?(:one)
        end
        ary << entry
        block.call(entry) if block_given?
        return entry if first == true
        return ary   if options[:limit] == ary.size
      end
      first ? ary.first : ary
    end
This is the core method for LDAP searching.
 * <tt>:base</tt>: The base DN of the search.  The default is derived
   from either the <tt>:base</tt> option of the adapter configuration or
   by querying the server.
 * <tt>:scope</tt>: The scope of the search.  Valid values are
   <tt>:base</tt> (find the base only), <tt>:onelevel</tt> (children of
   the base), and <tt>:subtree</tt> (the base, children, and all
   descendants).  The default is <tt>:subtree</tt>.
 * <tt>:filter</tt>: A standard LDAP filter.  This can be a string, an
   Ldaptic::Filter object, or parameters for Ldaptic::Filter().
 * <tt>:limit</tt>: Maximum number of results to return.  If the value
   is a literal +true+, the first item is returned directly (or +nil+ if
   nothing was found).  For a literal +false+, an array always returned
   (the default).
 * <tt>:attributes</tt>: Specifies an Array of attributes to return.
   When unspecified, all attributes are returned.  If this is not an
   Array but rather a String or a Symbol, an array of attributes is
   returned rather than an array of objects.
 * <tt>:instantiate</tt>: If this is false, a raw hash is returned
   rather than an Ldaptic object.  Combined with a String or Symbol
   argument to <tt>:attributes</tt>, a +false+ value here causes the
   attribute not to be typecast.

 Option examples:
   # Returns all people.
   MyCompany.search(:filter => {:objectClass => "person"})
   # Returns an array of strings because givenName is marked as a singular value on this server.
   MyCompany.search(:attribute => :givenName)
   # Returns an array of arrays of strings.
   MyCompany.search(:attribute => :givenName, :instantiate => false)
   # Returns the first object found.
   MyCompany.search(:limit => true)