/**
 * Axelor Business Solutions
 *
 * Copyright (C) 2005-2014 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.rpc.filter;


class LikeFilter extends SimpleFilter {

	private LikeFilter(Operator operator, String fieldName, String value) {
		super(operator, fieldName, value);
	}

	private static String format(Object value) {
		String text = value.toString().toUpperCase();
		if (text.matches("(^%.*)|(.*%$)")) {
			return text;
		}
		return text = "%" + text + "%";
	}
	
	public static LikeFilter like(String fieldName, Object value) {
		return new LikeFilter(Operator.LIKE, fieldName, format(value));
	}
	
	public static LikeFilter notLike(String fieldName, Object value) {
		return new LikeFilter(Operator.NOT_LIKE, fieldName, format(value));
	}

	@Override
	public String getQuery() {
		return String.format("(UPPER(self.%s) %s ?)", getFieldName(), getOperator());
	}

}

@@ -730,16 +730,42 @@
 ilter;%0A%0A
+import com.axelor.db.JPA;%0A
 %0Aclass L
@@ -798,16 +798,692 @@
 lter %7B%0A%0A
+%09private static Boolean unaccentSupport = null;%0A%0A%09private static final String UNACCENT_CHECK = %22SELECT unaccent('text')%22;%0A%09private static final String UNACCENT_CREATE = %22CREATE EXTENSION IF NOT EXISTS unaccent%22;%0A%0A%09private static boolean testUnaccent() %7B%0A%09%09try %7B%0A%09%09%09JPA.em().createNativeQuery(UNACCENT_CHECK).getResultList();%0A%09%09%09return true;%0A%09%09%7D catch (Exception e) %7B%0A%09%09%7D%0A%09%09try %7B%0A%09%09%09JPA.em().createNativeQuery(UNACCENT_CREATE).executeUpdate();%0A%09%09%09return true;%0A%09%09%7D catch (Exception e) %7B%0A%09%09%7D%0A%09%09return false;%0A%09%7D%0A%0A%09private static boolean hasUnaccentSupport() %7B%0A%09%09if (unaccentSupport == null) %7B%0A%09%09%09unaccentSupport = testUnaccent();%0A%09%09%7D%0A%09%09return unaccentSupport == Boolean.TRUE;%0A%09%7D%0A%0A
 %09private
@@ -2069,16 +2069,16 @@
 verride%0A
-
 %09public 
@@ -2093,24 +2093,159 @@
 etQuery() %7B%0A
+%09%09if (hasUnaccentSupport()) %7B%0A%09%09%09return String.format(%22(unaccent(UPPER(self.%25s)) %25s unaccent(?))%22, getFieldName(), getOperator());%0A%09%09%7D%0A
 %09%09return Str

Add accent insensitive search support