Announcement Announcement Module
Collapse
No announcement yet.
[LDAP TEMPLATE] Imprecise search Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [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
    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".

    Comment

    Working...
    X