Results 1 to 2 of 2

Thread: [LDAP TEMPLATE] Imprecise search

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Question [LDAP TEMPLATE] Imprecise search

    Hi everybody,

    I'm actually using LdapTemplate to search some user account and display them through a web page.

    My code seems as below:

    Code:
    public SearchControls getControls() {
    		controls = new SearchControls();
    		controls.setCountLimit(10);
    		controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    		return controls;
    }
    
    public List searchAccounts(String login){
    		
    		// Filters
    		AndFilter filter = new AndFilter();
    		filter.and(new EqualsFilter("objectclass", "inetOrgPerson"));
    		filter.and(new EqualsFilter("cn", login));
    		
    		return ldapTemplate.search("", filter.encode(), controls, new AccountMapper());
    	}

    The search works fine, but only if the filter is precise.

    Per example,
    if the filter is "toto", ldaptemplate will found one or several results with a login "toto".
    if the filter is "to" or "to*", ldaptemplate will not found results.

    How can i implement an imprecise search? i want to be able to search an account with a not specific term.

    Thanks all !

  2. #2
    Join Date
    Oct 2012
    Posts
    4

    Default

    Finally, i found a solution... I'm using the another type of filter, "LikeFilter"

    Example :

    Code:
    AndFilter filter = new AndFilter();
    		filter.and(new EqualsFilter("objectclass", "inetOrgPerson"));
    		filter.and(new LikeFilter("cn", login));
    This filter allows to add an "*" in your search terms, per example, you could have a keyword like "spr*"and the results could be "spring", "spread" or anything else that begins by "spr".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •